[powershell] Function

Viewer

  1. function Get-ADComputerStatus {
  2.  
  3.     [cmdletbinding()]
  4.     param (
  5.         [Parameter(Mandatory = $true,
  6.             ValueFromPipeline = $true,
  7.             Position = 0)]
  8.         [ValidateNotNull()]
  9.         [ValidateNotNullOrEmpty()]
  10.         [String[]]$ComputerName
  11.     )
  12.  
  13.     foreach ($Computer in $Computername) { 
  14.  
  15.         Try {
  16.             $object = Get-ADComputer $Computer -ErrorAction Stop
  17.             $Result = $true
  18.             $Enabled = $object.Enabled
  19.         }
  20.         Catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
  21.             $Result = $False
  22.             $Enabled = ""
  23.         }
  24.         finally {
  25.             [PSCustomObject]@{
  26.                 Name    = $Computer
  27.                 Found   = $Result
  28.                 Enabled = $Enabled
  29.             
  30.             }
  31.         }
  32.         
  33.     }
  34.  
  35. }

Editor

You can edit this paste and save as new:


File Description
  • Function
  • Paste Code
  • 24 Sep-2021
  • 864 Bytes
You can Share it: