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 = {
$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 Prashanth Jayaram

DB Technologist, Author, Blogger, Service Delivery Manager at CTS, Automation Expert, Technet WIKI Ninja, MVB and Powershell Geek My Profile: https://social.technet.microsoft.com/profile/prashanth jayaram/ http://www.sqlshack.com/author/prashanth/ http://codingsight.com/author/prashanthjayaram/ https://www.red-gate.com/simple-talk/author/prashanthjayaram/ http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/ Connect Me: Twitter @prashantjayaram GMAIL powershellsql@gmail.com The articles are published in: http://www.ssas-info.com/analysis-services-articles/ http://db-pub.com/ http://www.sswug.org/sswugresearch/community/
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

2 Responses to PowerShell – Delete Registry Entries – Remote Machines – Example Profile Deletion

  1. Erdnua says:

    what would i need to do to get rid of the “cannot be loaded because running scripts is disabled”?


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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s