lunes, 31 de julio de 2017

WINDOWS. PS. Check OU computers

Subject: Check compurters OU to check there ara some host. Scheduler one daily task and inform us by email only if there are some host.

When you add new computer to AD by default is assigned to "Computers" OU, this script remember you to move at other OU.

[ ] Get-ADComputer


COMMAND: Get-ADComputer -Filter * -SearchBase "CN=COMPUTERS, DC=Mydomain, DC=local" | select-object -expand name


COMMAND: Get-ADComputer -properties * -Filter * -SearchBase "CN=COMPUTERS, 
DC=MyDomain, DC=local" | select name, DNSHOSTNAME,WHENCHANGED,WhenCreated | Format-Table


[ ] PS Script


#Creado 31/7/2017
#
#
Import-Module ActiveDirectory
#
#
#******************************************************************************************************* 
#[COMMON VARIABLES]

$emailbody = $nul
$emailbody = @()

$body= Get-ADComputer -properties * -Filter * -SearchBase "CN=COMPUTERS, DC=MyDomain, DC=local" | select name, DNSHOSTNAME,WHENCHANGED,WhenCreated | Format-Table | Out-String 

# [SEND EMAIL]


If (!$body) {


else 
{
$PSEmailServer = "11.116.116.2"
Send-MailMessage -From "OUComputers@micompany.es" -To "ServiceDesk@micompany.es; it@micompany.es" -Subject "PCs sin asignar en OU\COMPUTERS" -Body $body 
}

[ ] Schedule daily report










Check at Windows 2012 R2
by GoN | Published: July 31, 2017 | Last Updated: September 28, 2017

No hay comentarios: