Invoke-Command返回要在条件语句Powershell中使用的返回信息

时间:2017-06-07 19:53:17

标签: powershell powershell-v2.0

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"

返回:

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

我想做一个只查看SMBv1是否等于1的IF语句。如何抑制头信息并写出语句?

1 个答案:

答案 0 :(得分:1)

试试这个

$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"
    }
}