Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Problems reading in from array

$
0
0

Hi,

I’m having some issue with following script:


$Computers = get-adcomputer -filter * -searchbase "ou=computers,dc=domain,dc=com" | foreach-object {$_.name}

foreach ($computer in $Computers)

{get-windowskey -targets $computer}

Get-windowskey is a function I have loaded into my environment which takes the name of a pc, stated with the param -targets, and returns the Windows version and product key. When I run the above script with hard coded $Computers, it runs great. However, running the above gives me the below error, any advice?

Thanks in advance


Cannot convert value "\\CAND8TQ14J\root\default:stdRegProv" to type "System.Management.ManagementClass". Error: "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"
At C:\Powershell\GetProductKeyFunction.ps1:11 char:9
+ $wmi = [WMIClass]"\\$target\root\default:stdRegProv"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastToWMIClass

You cannot call a method on a null-valued expression.
At C:\Powershell\GetProductKeyFunction.ps1:12 char:9
+ $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At C:\Powershell\GetProductKeyFunction.ps1:13 char:9
+ $binArray = ($data.uValue)[52..66]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray


Viewing all articles
Browse latest Browse all 13067

Trending Articles