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"

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?

4
  • 2
    Do not use Format-* cmdlets as intermediate step in data processing. Commented Jun 7, 2017 at 20:23
  • I use it to make it readable. Otherwise it is stretched. Does it muck with things? Commented Jun 7, 2017 at 20:31
  • Possible duplicate of Store just the value of an object in a variable Commented Jun 7, 2017 at 20:32
  • 1
    Yes it mucks with things; it changes an object with properties you can work with easily, into a string representation of a table with less information in it, some possibly cut short, which you can't easily work with. You want to read up on Select-Object -ExpandProperty Commented Jun 7, 2017 at 20:34

1 Answer 1

1

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"
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

tat gross "SMBv1 -eq 1" :D
I will give this a shot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.