-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-LocalProfile.ps1
More file actions
41 lines (40 loc) · 930 Bytes
/
Copy pathRemove-LocalProfile.ps1
File metadata and controls
41 lines (40 loc) · 930 Bytes
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
#Remove local profile from remote PC
Function Remove-LocalProfile
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true,Position=0)]$Computer,
[parameter(Mandatory=$true,Position=1)]$SamAccountName
)
try
{
$Sid = Get-ADUser $SamAccountName | select -expand sid | select -expand value
}
Catch
{
Write-Warning "$SamAccountName not found in AD"
Break
}
if (Test-Connection $computer -Count 1 -Quiet)
{
$Profile = Get-WmiObject Win32_UserProfile -ComputerName $Computer | where {$_.SID -eq $Sid}
if ($Profile)
{
Try
{
Write-Verbose "Removing $SamAccountName from $Computer"
$Profile.delete()
}
catch
{
Write-Warning "The Profile of $SamAccountName is locked. Please restart $Computer and try again."
}
}
else
{
Write-Warning "$SamAccountName not found on $Computer"
}
}
else {Write-Warning "$Computer is not online"}
}