I am trying to write a script that will go through all the computers in AD and has them first check to see if a Registry Key Path exists before continuing to make it and a DWord. I feel like I am close but I can’t seem to figure out what exactly I need to change and fix.
Please know I have only ever taken one coding class in college and am not very good at more advanced scripting. This one is starting to go above my head.
$DaysInactive = 30
$time = (Get-Date).Adddays(-($DaysInactive))
$LoopCount = 1000
$Loops = 0
While ($Loops -le $LoopCount)
{
$Loops++
Foreach ($Computer in Get-ADComputer -Filter {LastLogonTimeStamp -gt $time} -ResultPageSize 2000 -resultSetSize $null | Select-Object -ExpandProperty dnshostname) ## Get all computers from AD and loop through them
{
$KeyFound = $true
$KeyNotFound =$false
If (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING' -ErrorAction SilentlyContinue) {
First I would request you to resubmit your code in the preformatted syntax. Second I don’t see where you are doing a remote call to each of the computers in question? Have you enabled PSRemoting for all of the computers? How are you making the call to explore the registry of each of these computers? If you already have this figured out please let us know what you are needing help with. It’s not very clear what you need help with.
You can see the “[-Type < RegistryValueKind > ]” added when I specify “-ArgumentList hklm:”. Well maybe not on this forum. I added spaces around the < and >.