[powershell] Function
Viewer
- function Get-ADComputerStatus {
- [cmdletbinding()]
- param (
- [Parameter(Mandatory = $true,
- ValueFromPipeline = $true,
- Position = 0)]
- [ValidateNotNull()]
- [ValidateNotNullOrEmpty()]
- [String[]]$ComputerName
- )
- foreach ($Computer in $Computername) {
- Try {
- $object = Get-ADComputer $Computer -ErrorAction Stop
- $Result = $true
- $Enabled = $object.Enabled
- }
- Catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
- $Result = $False
- $Enabled = ""
- }
- finally {
- [PSCustomObject]@{
- Name = $Computer
- Found = $Result
- Enabled = $Enabled
- }
- }
- }
- }
Editor
You can edit this paste and save as new: