List empty OU’s


Get-ADOrganizationalUnit -Filter * -SearchBase “DC=test,DC=me,DC=com” | Where-Object {-not ( Get-ADObject -Filter * -SearchBase $_.Distinguishedname -SearchScope OneLevel -ResultSetSize 1 )} | Select Name,DistinguishedName

Advertisements

Find Group Policies linked to Active Directory OU Using PowerShell


Method 1: OU name like “test”

$LinkedGPOs = Get-ADOrganizationalUnit -Filter ‘Name -like “*test*”‘ | select -ExpandProperty LinkedGroupPolicyObjects
$GUIDRegex = “{[a-zA-Z0-9]{8}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{12}}”

foreach($LinkedGPO in $LinkedGPOs) {
$result = [Regex]::Match($LinkedGPO,$GUIDRegex);
if($result.Success) {
$GPOGuid = $result.Value.TrimStart(“{“).TrimEnd(“}”)
Get-GPO -Guid $GPOGuid
}

}


Method 2: Ou name test with path

$LinkedGPOs = Get-ADOrganizationalUnit -Identity “OU=test,DC=AA,DC=COM” | select -ExpandProperty LinkedGroupPolicyObjects
$GUIDRegex = “{[a-zA-Z0-9]{8}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{12}}”

foreach($LinkedGPO in $LinkedGPOs) {
$result = [Regex]::Match($LinkedGPO,$GUIDRegex);
if($result.Success) {
$GPOGuid = $result.Value.TrimStart(“{“).TrimEnd(“}”)
Get-GPO -Guid $GPOGuid
}

}

http://techibee.com/group-policies/find-group-policies-linked-to-active-directory-ou-using-powershell/2419

Find OS versions


Get-Content F:\computers.txt | ForEach-Object{Get-ADComputer $_ -Properties Name,LastLogonDate,OperatingSystem | Select-Object Name,LastLogonDate,OperatingSystem} | Export-Csv report_computers.csv

 

Windows server 2008 above system state backup automation


@echo off
wbadmin start systemstatebackup -backuptarget:D: -quiet >>D:\Backups\WSB_Logs\Backup.log
wbadmin delete systemstatebackup -keepversions:1 -quiet >>D:\Backups\WSB_Logs\Backup-del.log
ipconfig /all >D:\IPDetails_Backups\Common\IPconfig_%computername%.txt”
regedit /e “D:\Re_Backups\Common\Reg_%computername%.reg”
sc queryex type= service state= all >”D:\Services_Backups\Common\Service_%computername%.txt”
exit

Note:

Save as SSB.cmd

Schedule task. Don’t forget to select run with high privileges

Powershell: Automating AD Bulk Users Movement between OUs

Scripts


—————————–IP to name PC name resolve Bulk machines————————–

Get-Content “C:\Disk Report\Serverlist.txt” | ForEach-Object{
$hostname = ([System.Net.Dns]::GetHostByAddress($_)).Hostname
if($? -eq $True) {
$_ +”: “+ $hostname >> “C:\machinenames.txt”
}
else {
$_ +”: Cannot resolve hostname” >> “C:\machinenames.txt”
}}

——————————————————-Done————————————————————————–

Get the Computer Name, IP Address and others with this batch file

@echo off
echo Checking your system infor, Please wating…
systeminfo | findstr /c:”Host Name”
systeminfo | findstr /c:”Domain”
systeminfo | findstr /c:”OS Name”
systeminfo | findstr /c:”OS Version”
systeminfo | findstr /c:”System Manufacturer”
systeminfo | findstr /c:”System Model”
systeminfo | findstr /c:”System type”
systeminfo | findstr /c:”Total Physical Memory”
ipconfig | findstr IPv4

echo.

echo Hard Drive Space:
wmic diskdrive get size

echo.
echo.

echo Service Tag:
wmic bios get serialnumber

echo.
echo.
echo CPU:
wmic cpu get name

echo Completed! Thank you!

pause


Display Current User, Host Name and IP Address


@echo off
echo\
echo I am logged on as %UserName%.
echo My computer's name is %ComputerName%.
echo My IP settings are
ipconfig | find "." | find /i /v "suffix"
echo\
echo Press the Space bar to close this window.
pause > nul

GP


Invoke-Command {
gpupdate /force
}

%d bloggers like this: