schnipdip
schnipdip

Reputation: 151

Invoke-Command return information to be used in conditional statement Powershell

for ($i = 0; $i -lt $arrayHold.length; $i++){
        $OSversion = invoke-command -computername $arrayHold[$i] -scriptblock {Get-WMIObject Win32_OperatingSystem} | 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  -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"

Returns:

PSComputerName SMB1
-------------- ----
XXXXXXXX          0

I want to do an IF statement that just looks to see if SMBv1 is equal to 1. How do I suppress the header information and write the statement?

Upvotes: 0

Views: 428

Answers (1)

ArcSet
ArcSet

Reputation: 6860

Try this

$arrayHold = @("TEST_COMPUTER")
for ($i = 0; $i -lt $arrayHold.length; $i++){
    $OSversion = invoke-command -computername $arrayHold[$i] -scriptblock {Get-WMIObject Win32_OperatingSystem} | select-object caption
    $invcmd = invoke-command -computerName $arrayHold[$i]  -scriptblock {Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\" | select-object PSComputerName, SMB1} 
    $invcmd

    if($invcmd.SMB1 -eq 1){
        "1"
    }elseif(!$invcmd.smb1){
        "2"
    }else{
        "3"
    }
}

Upvotes: 1

Related Questions