x

Serwis finansowy

czwartek, 22 stycznia 2015

Sprawdzamy czy wszystkie serwery w sieci są dostępne

cls

Write-Host

Write-Host "Checking if PowerShell module for Active Directory is available on this machine..."

$ADModuleAvailable = $null

$ADModuleAvailable = Get-Module -ListAvailable | where {$_.Name -eq "ActiveDirectory"}

if ($ADModuleAvailable -eq $null){

Write-Host -ForegroundColor Red "PowerShell module for Active Directory is not available on this machine."

Write-Host -ForegroundColor Red "Please run this script on a domain controller or on a machine that has Active Directory management tools installed."

Write-Host

Exit}

else{

Write-Host -ForegroundColor Green "PowerShell module for Active Directory is availble."}

Write-Host





Write-Host "Checking if PowerShell module for Active Directory is already loaded..."

$ADModuleLoaded = $null

$ADModuleLoaded = Get-Module | where {$_.Name -eq "ActiveDirectory"}

if ($ADModuleLoaded -eq $null){

Write-Host "Loading PowerShell module for Active Directory ..."

Import-Module -Name "ActiveDirectory"}

Write-Host -ForegroundColor Green "Powershell module for Active Directory is loaded."

Write-Host








$ServerList = $null

$ServerList = Get-ADComputer -Filter '(OperatingSystem -like "*Server*") -AND (Enabled -ne "False")' -Properties DNSHostName | Select-Object DNSHostName | Sort-Object DNSHostName





$IsOnline = $null

ForEach ($Server in $ServerList) {

$IsOnline = Test-Connection -ComputerName $Server.DNSHostName -BufferSize 10 -Count 1 -Quiet

if ($IsOnline -eq $true){

Write-Host -ForegroundColor Green $Server.DNSHostName "is ONLINE"



}

else {

Write-Host -ForegroundColor Red $Server.DNSHostName "is OFFLINE"



}

}

żródło       


Brak komentarzy:

Prześlij komentarz