Quantcast
Viewing all articles
Browse latest Browse all 21975

Registry Checking For Remote Machine

Hello,

I have checked on other forums and they seem to have bit's i need, but i'm getting confused piecing it together.

Currently at the end of a function in my script i have this

$sid=([wmi]"win32_userAccount.Domain='SOTON',Name='$tname'").sid

if (Test-Path "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid") {
Remove-Item 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid'
}

Write-Host "All Done..." -foregroundcolor red -backgroundcoloryellow

sleep 10

The theory, to lookup the SID of a user from an already set username variable "$tname" and then use that to check the registry for that key... I made a boo boo in the sense that it is looking at my local machine's registry and not the remote machine"$compname"

Basically, if it exists it need's deleting... else move on to the next stage of my script.. if it doesn't exist, move onto the next stage of the script. If my script finds the key and deletes it, i want it to return to check that it no longer exists before it moves on...

Below is something i have guessed together with a little help from Google, i hope it works! If someone could help me with the if actions mentioned above... i would be great-full.

$host = “$compname”

$Hive = [Microsoft.Win32.RegistryHive]“LocalMachine”;

$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$host);

$ref = $regKey.OpenSubKey(“SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid”);

if (!$ref) {$false}

else {$true}

Want an easier life!


Viewing all articles
Browse latest Browse all 21975

Trending Articles