-
Notifications
You must be signed in to change notification settings - Fork 4
/
status.ps1
32 lines (27 loc) · 785 Bytes
/
status.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Import the Active Directory module
Import-Module ActiveDirectory
# Get all computers in Active Directory
$computers = Get-ADComputer -Filter *
# Initialize an array to store the computer status
$computerStatus = @()
# Loop through each computer
foreach ($computer in $computers)
{
# Check if the computer is online
$status = Test-Connection -ComputerName $computer.Name -Count 1 -Quiet
if ($status)
{
$statusText = "Online"
}
else
{
$statusText = "Offline"
}
# Add the computer name and status to the array
$computerStatus += [PSCustomObject]@{
ComputerName = $computer.Name
Status = $statusText
}
}
# Output the computer status in a table
$computerStatus | Format-Table -Property ComputerName, Status