PowerShell – Delete Registry Entries – Remote Machines – Example Profile Deletion

 

#The following SID registry entry to be deleted across all mutiple Machines, SID is a user #who owns this user profile. Run the below script in Powershell console or ISE

$sid = ‘S-1-5-21-3656904587-1668747452′

$scriptblock = {
param($sid)
$regpath = ‘HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList’
Remove-Item -path (Join-Path $regPath $sid) -force -recurse
}

#The list of servers are entered in Server.txt file. The below foreach statement will loop #through all servers for the above said SID.

Foreach ($srv in get-content “C:\Server.txt”)
{
# Need to pass the variables that will be used in the remote session with the argumentlist
Invoke-Command -computername $srv -scriptblock $scriptblock -argumentlist $sid
}

About these ads

About Prashanth Jayaram

I’m a Database technologist having 7+ years of rich, hands-on experience on Database technologies. I am Microsoft Certified Professional and backed with a Degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication and PowerShell. hobbies are playing sports and drawing.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s