I'm new to scripting and to Powershell but this is what I have managed to put together so far. Of course it fails. We have two custom entries in the registry that I want to query remote workstations for these values, Monitor 1 and Monitor 2. Output to a
CSV along with the workstations name. Because of our AD structure I figured its just easier to input the OU individually as seen in the script. That portion of the script seems to work. I get the following error in bold when I run the script: I've Google'd
and tinkered with this for a week now with no resolution and seem to be going in circles. And yes, I had help to get this far.
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At C:\utils\RegMonitor2.ps1:33 char:5
+ $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$result.pro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At C:\utils\RegMonitor2.ps1:33 char:5
+ $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$result.pro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
# 1) Searches Active Directory for all Computers under said OU # 2) Searches remote registry of those machines for the mentioned Monitor and Monitor2 subkeys. # 3) Exports CSV (Can be opened and saved as excel format later) with ordered columns Computername, Monitor1 value, monitor2 value. # ================================================================ $SearchPath = "OU=XXX,OU=XXX,OU=XXX,DC=XXX,DC=XXX,DC=XXX" $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$SearchPATH") $objSearcher.PageSize = 1000 $objSearcher.Filter = "(objectClass=computer)" $objSearcher.SearchScope = "Subtree" $colProplist = "name" $colResults = $objSearcher.FindAll() $Store = @() $Hive = [Microsoft.Win32.RegistryHive]"LocalMachine"; foreach ($result in $colResults) { #### # Use $result.properties.name to retreive ComputerName ### $obj = New-Object PsObject $obj | Add-member -type noteproperty -name "Computername" -Value $result.properties.name $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$result.properties.name); $ref = $regKey.OpenSubKey("SYSTEM\CurrentcontrolSet\control\Session Manager\Environment"); $obj | Add-member -type Noteproperty -name "Monitor1" -value $ref.OpenSubKey("Monitor") $obj | Add-member -type Noteproperty -name "Monitor2" -value $ref.OpenSubKey("Monitor2") $store += $obj } $store | Select-Object Computername,Monitor1,Monitor2 | Export-CSV -noTypeInformation -Path "Pathtosave.csv"