none
Scan Subnet Range and check Bitlocker status RRS feed

  • Question

  • I know I can do this:

    $computers = 'PC001','Laptop002'
     ForEach ($computer in $computers) {
    #$client = $Computer.Name
    if (Test-Connection -Computername $computer -BufferSize 16 -Count 1 -Quiet) {
        
        manage-bde.exe -status -cn $computer 
        }
    }

    But what I really would like is to ping a range like :

    1..5 | Where { (Test-Connection 192.168.27.$_ -quiet -count 1) } | % { ([System.Net.DNS]::GetHostbyAddress((192.168.27.$))).HostName  }

    and then if the machine is online to run the manage-bde command.

    I cant see a way to incorporate the 2 together....

    Thanks, M


    Maelito

    • Moved by Bill_Stewart Thursday, December 20, 2018 8:38 PM This is not "debug/fix/rewrite my script for me" forum
    Friday, October 5, 2018 2:52 PM

All replies

  • Use ForEach-Object instead of "Where".


    \_(ツ)_/

    Friday, October 5, 2018 3:21 PM
  • If you wanted to script-verify BL status, why not use an immediate task for it? It will catch any workstation, while your script will only catch the computers that are turned on at runtime, and additionally, that way needs ports to be open, making it a less secure way.
    Saturday, October 6, 2018 4:19 PM
  • You mean like this?

    $computers = 1..5 | Where { 
        Test-Connection "192.168.27.$_" -quiet -count 1 } | % { 
            ([System.Net.DNS]::GetHostbyAddress("192.168.27.$_")).HostName}
     ForEach ($computer in $computers) {
        manage-bde.exe -status -cn $computer 
    }

    Or did you want to do it inline as jrv suggests?

    That would look like;

    1..5 | Where { 
    Test-Connection "192.168.27.$_" -quiet -count 1 } | % { 
    ([System.Net.DNS]::GetHostbyAddress("192.168.27.$_")).HostName} | % {
    manage-bde.exe -status -cn $_}

    Monday, October 15, 2018 5:10 AM