0
$arrayHold = @($readFile)
$array = @()
$arrayHold[0]
for ($i = 0; $i -lt $arrayHold.Length; $i++) {
    $OSversion = Invoke-Command -ComputerName $arrayHold[$i] -ScriptBlock {
        Get-WMIObject Win32_OperatingSystem -ComputerName $arrayHold[$i]
    } | Select-Object Caption

    # create a nested for loop and throw the OSVERSION into it then nest the $i
    # for loop.
    #if ($OSversion -match "7") {
        $invcmd = Invoke-Command -ComputerName $arrayHold[$i] -ScriptBlock {
            Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1
        } | Select-Object PSComputerName, SMB1 | Format-Table -AutoSize

        #$printInfo = $OSversion + $invcmd
        $array += $invcmd
    #}
}
$array | Out-File $save\"$file"

I am passing host names from a file into an array.

The error I am receiving is:

Null Array

The goal is to retrieve the OS version and push out an update according to whichever OS version the user is operating on.

EDIT: It has something to do with the $OSversion variable. I take it out and there isn't a null array error.

4
  • $readFile is null? Commented May 30, 2017 at 20:18
  • The error isn't specific. However, it has something to do with the $OSversion variable. I take it out and there isn't a null array error. Commented May 30, 2017 at 20:24
  • 1
    Just drop -ComputerName $arrayHold[$i] from the get-wmiobject call, you don't need double-remoting. Then you won't need to fix the error, which is that the scriptblock runs on the remote computer and that cannot see the local $arrayHold variable. Commented May 30, 2017 at 20:33
  • Ohhh okay I see, I can't test the code now since I am not in the testing environment. I will provide an update tomorrow. Thank you for your help TessellatingHeckler :) Commented May 30, 2017 at 20:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.