I'm trying to write a script that checks which print server users on our network are connecting to. To do that, I'm attempting to check the registry values listed under Printer\Connections. On my local machine the following two methods both work:
1)
Get-ChildItem HKCU:\Printers\Connections
Output:
Hive: HKEY_CURRENT_USER\Printers\Connections
Name Property
----- --------
,,printServer,printerName GuidPrinter : {guid}
Server : \\printserver.domain
Provider : win32spl.dll
LocalConnection : 1
2)
>> Get-ChildItem HKCU:\Printers\Connections | ForEach-Object {Get-ItemProperty $_.pspath}
And the output of that command is:
GuidPrinter : {guid}
Server : \\printServer.domain
Provider : win32spl.dll
LocalConnection : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Printers\Connections\,,printServerName,printerName
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Printers\Connections
PSChildName : ,,printServerName, printerName
PSProvider : Microsoft.PowerShell.Core\Registry
By themselves, neither of these implementations are easily applied to remote machines. My most recent attempt to get the same information shown above off of a remote machine is:
$machine = 'computerName';
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('CurrentUser',$machine);
$regKey = $reg.OpenSubKey("Printers\Connections");
$regKey.GetValueName()
# I also tried the following which I didn't think
# would work, but I was grasping at straws:
# Get-ChildItem $regKey;
The above code returns nothing. It doesn't throw an error but regKey returns an empty string.
Does anyone know of an alternative solution to getting the information I'm looking for or see something wrong in the implementation above?
Thanks.