delprof2
Greg Funk
I am wondering if I can set up a deployment task with delprof2. More specifically can I call delprof2 from a network share and somehow pass the machine name to the command or do I have to copy the file to the machine first and then run the command.
0
Comments
Hi Greg,
you can create a new deployment package, include a command step and the executable.
the command should contain the executable name and a parameter for it. When deployed it will be executed on the target machine.
I advise to be very carefull with this tool. Remember that it deletes all profiles except the profile it is executed under and few system default profiles.
You can use a GPO to remove unused profiles after x amount of days.
You could also use a script like this:
Function Remove-UserProfile{
<#
.SYNOPSIS
Removes specified user profile from a local or remote machine using Invoke-Command
.PARAMETER
Profile
The profile you wish to remove from the workstation
.PARAMETER
Computername
The remote computer(s) you wish to remove profiles from
.EXAMPLE
Remove-UserProfile -Profile demouser1
.EXAMPLE
Remove-UserProfile -Profile demouser1,demouser2
.EXAMPLE
Remove-UserProfile -Computername wrkstn01 -Profile demouser1
.EXAMPLE
Remove-UserProfile -Computername wrkstn01,wrkstn02 -Profile demouser1
#>
Param(
[cmdletBinding()]
[parameter(
Mandatory,
Position=1)]
[string]
$Profile,
[parameter(
Mandatory=$false,
Position=0)]
[array]
$Computername
)
#Work with a remote machine.
If($Computername-ne'')
{
Foreach($computerin$Computername)
{
Try
{
Foreach($pin$Profile)
{
Get-CimInstance-Computername $Computer win32_userprofile |
Select-Object SID,LocalPath |
Where-Object { $_.localpath-match"$p" } |
Remove-CimInstance
}#end foreach
}#end try
Catch
{
$_.Exception.Message
}#end catch
}#end foreach
}#end if
#Working with the local machine.
Else
{
foreach($pin$Profile)
{
Get-CimInstance win32_userprofile |
Select-Object SID,LocalPath |
Where-Object { $_.localpath-match"$p" } |
Remove-CimInstance
}#end foreach
}#end else
}#end function
Can this script be used to remove all profiles except built in accounts?
Sure it can. I would modify it slightly with an array containing the built-in account names, and then use a -notin filter to delete the ones that aren't.
Hi,
I have looked around and I ended up with using this PowerShell script that works just great!
It is easy to edit as you can see in attached screenshot you add the datestring -DateBeforeDeletion (xxdays) for what matches your business needs.
You should also edit in the file itself what accounts you don't want to be touched. If you have say admin accounts that should always be on the clients.
File can be downloaded here: Remove-OldUser