powershell - Scrape Remote Registry and report on credential providers -
i'm not hot @ powershell i'm looking solution can report on credential providers being used pc , servers in windows domain.
i had found https://gallery.technet.microsoft.com/scriptcenter/detect-authentication-09b0a749 (note: not being used below) works fine on current session, want script run remotely against window os computers , produce report.
i want output username, provider used (based on regkey value corresponds provider) , computer used. if computer can't connected gracefully inform of failure. feel 'simply' scanning registry specific keys , outputting them seemed work script has encountered few issues:
it appears $keycheck1/2 isn't working. if sessiondata\1 exists script runs fine, doesn't fails find key , errors...
i have few of different providers in use, hence 'if $provider ='. problem doesn't seem picking value returns same result (duo secure)!
for reason output dropping value of $remotepc
for using write-host see happening, want email results (i 'should' ok tips may ease things along)
any advise appreciated.
get-adcomputer -filter {operatingsystem -like "windows 7 ent*"} -properties dnshostname | foreach-object {"$($_.dnshostname)"} | out-file -filepath "u:\computers.txt" $filepath = "u:\computers.txt" $computerlist = get-content $filepath foreach($remotepc in $computerlist){ if((test-connection -computername $remotepc -count 1 -erroraction silentlycontinue)) { $session = new-pssession -computername $remotepc invoke-command -session $session -scriptblock{ $keycheck1 = 'hklm:\software\microsoft\windows\currentversion\authentication\logonui\sessiondata\1' $keyexists1 = test-path $keycheck1 -isvalid if ($keyexists1 -eq $true) { $key1 = 'hklm:\software\microsoft\windows\currentversion\authentication\logonui\sessiondata\1' $provider = (get-itemproperty -path $key1 -name lastloggedonprovider) $user = (get-itemproperty -path $key1 -name loggedonsamuser).loggedonsamuser $provider = (get-itemproperty -path $key1 | select lastloggedonprovider) $user = (get-itemproperty -path $key1 | select loggedonsamuser).loggedonsamuser if ($provider = '{449b5f65-c836-4eb0-a00a-71c47ef75210}') { $usedprovider = "duo secure" } elseif ($provider = '{8bf9a910-a8ff-457f-999f-a5ca10b4a885}') { $usedprovider = "smart card" } elseif ($provider = '{8fd7e19c-3bf7-489b-a72c-846ab3678c96}') { $usedprovider = "smartcard" } elseif ($provider = '{25cbb996-92ed-457e-b28c-4774084bd562}') { $usedprovider = "password only!" } write-host $user used $usedprovider on $remotepc } else { $keycheck2 = 'hklm:\software\microsoft\windows\currentversion\authentication\logonui\sessiondata\2' $keyexists2 = test-path $keycheck2 -isvalid if ($keyexists2 -eq $true) { $key2 = 'hklm:\software\microsoft\windows\currentversion\authentication\logonui\sessiondata\2' $provider = (get-itemproperty -path $key2 -name lastloggedonprovider) $user = (get-itemproperty -path $key2 -name loggedonsamuser).loggedonsamuser $provider = (get-itemproperty -path $key2 | select lastloggedonprovider) $user = (get-itemproperty -path $key2 | select loggedonsamuser).loggedonsamuser if ($provider = '{449b5f65-c836-4eb0-a00a-71c47ef75210}') { $usedprovider = "duo secure" } elseif ($provider = '{8bf9a910-a8ff-457f-999f-a5ca10b4a885}') { $usedprovider = "smart card" } elseif ($provider = '{8fd7e19c-3bf7-489b-a72c-846ab3678c96}') { $usedprovider = "smartcard" } elseif ($provider = '{25cbb996-92ed-457e-b28c-4774084bd562}') { $usedprovider = "password only!" } write-host $user used $usedprovider on $remotepc } } } remove-pssession $session } else { } }
Comments
Post a Comment