PS Dynamic Script for Test-Connection on OU and SubOU.


i have non working powershell script searching ou in 2008 level active directory, incomplete. able retrieve part of script forum (cant remember one, or kindly give them credit deserve), hoping include variable in "searchbase" option below , make dynamic, can change ou ping top level , have work under child ou if need to.

outcome: ping ou , child ou , have option ping either selection. of course manually enter in search base parameters when prompted shell. want have easy way of ping computers ou level without having paste lower part of script powershell script pane , changing ou there. if can correct parameters working, easy load function ps profile. thank you, , appreciated. hoping can let me know missing functional.

function get-dcping


{

   

[cmdletbinding()]


   

[alias()]


   

[outputtype([int])]


   

param


    (

       

# param1 description


       

[parameter(mandatory=$true,


                   valuefrompipelinebypropertyname

=$true,


                   position

=0)]


       

[string]$search)

  

$rtn = $null


  

get-adcomputer -filter * -searchbase 'ou=$search,dc=domain,dc=domain'  |


%

{$rtn = test-connection -cn $_.name -count 1 -buffersize 16 -quiet


if

($rtn -match 'true') {write-host -foregroundcolor green $_.name}


else

{ write-host -foregroundcolor red $_.name }}

}


hi,

here's starter:

function get-dcping {      [cmdletbinding()]      param(              [string]         $organizationalunit      )      get-adcomputer -filter * -searchbase $organizationalunit | foreach {          $computername = $_.name          $props = @{             computername = $computername             alive = $false         }          if (test-connection -computername $computername -count 1 -quiet) {              $props.alive = $true          }          new-object psobject -property $props      }  }


don't retire technet! - (don't give yet - 13,225+ strong , growing)



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL