-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-Profile.ps1
More file actions
58 lines (55 loc) · 1.62 KB
/
Remove-Profile.ps1
File metadata and controls
58 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function Remove-Profile
{
<#
.SYNOPSIS
Removes a user profile from a computer using WMI.
.DESCRIPTION
Removes a user profile from a computer using WMI.
.EXAMPLE
Remove-Profile -Identity accountname -computer computername
.PARAMETER Identity
The AD User account of the profile to be removed.
.PARAMETER ComputerName
The computer or server to remove the profile from.
.PARAMETER Credential
Optionally, supply an account to run the command as.
#>
param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[Alias('User','Username')]
$Identity,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[Alias('Computer','Server')]
$ComputerName,
[Parameter(Mandatory=$False)]
[Alias('Cred','RunAs')]
$Credential
)
if ($Credential)
{
$profile = Get-Profile -Identity $Identity -ComputerName $ComputerName -Credential $Credential
}
else
{
$profile = Get-Profile -Identity $Identity -ComputerName $ComputerName
}
if (($profile.Loaded -eq $False) -and ($profile.count -eq $null))
{
try
{
Write-Output "Attempting to remove profile from $ComputerName"
Write-Output $profile.SID
Write-Output $profile.LocalPath
$profile.delete()
}
catch
{
Write-Warning $profile
Write-Warning "Unable to remove profile from $ComputerName"
}
}
}