Powershell Script - KB Installation Status on Windows Servers / Clients.
<#Read Me !!
1. Script will check if a KB mention in Input.csv against a Server name is installed or not.
2. Input.csv file header heading should not be changed. If planning to change, then changes are required in script also.
3. Once executed, Output.csv can be referred for the results.
To use this, copy the below code, have Input.csv on the same location with MachineName,KBID heading.
KBID - will be containing KBNo.
Machine Name -Server name against check is required.
#>
$checkdata = Import-Csv .\Input.csv
$line = 0
$linecount = $checkdata.count
$percentagecomplete= 0
foreach($srv in $checkdata)
{
$percentagecomplete = ($line / $linecount) * 100
$KB = $srv.KBID
$error.Clear()
Write-Progress -Activity "Checking Status.." -PercentComplete $percentagecomplete -Status "$line out of $linecount"
try{
if(($output = Get-HotFix -ComputerName $srv.'MachineName' -Id $KB).HotfixID -eq $KB)
{
$srv | Select @{n="MachineName";e={$srv.MachineName}},@{n="HotFixID";e={$KB}},@{n="InstalledOn";e={$output.InstalledOn}} | Export-Csv ./Output.csv -Append -NoTypeInformation
}
else
{
$srv | Select @{n="MachineName";e={$srv.MachineName}},@{n="HotFixID";e={$KB}},@{n="InstalledOn";e={"Not Installed"}} | Export-Csv ./Output.csv -Append -NoTypeInformation
}
}
catch
{
$srv | Select @{n="MachineName";e={$srv.MachineName}},@{n="HotFixID";e={$KB}},@{n="InstalledOn";e={$error.exception.Message}} | Export-Csv ./Output.csv -Append -NoTypeInformation
}
$line++
}
Powershell Script - Listing Empty GPOs
#Created By - Abhishek Bansal
<#Read Me !!
1. Script Usage - Finding Empty GPOs in the domain environment.
Script Logic - Logic revolves around GPO Template & GPO Container user & computer version. So if a policy is created but it's not configured with any setting or it's never been edited, then the Sysvol & AD Version for both the container & template are 0.
Below Snap for reference -
2. Refer EmptyGPos.csv for the output & below is the code. #>
import-module grouppolicy
$gpos = Get-GPO -All
foreach ($gpo in $gpos)
{
if (($gpo.Computer.DSVersion -eq 0 -and $gpo.User.DSVersion -eq 0) -and ($gpo.Computer.SysvolVersion -eq 0 -and $gpo.User.SysvolVersion -eq 0))
{
$gpo | Select @{n="GPO Name";e={$_.Displayname}},DomainName,Owner,@{n="GUID";e={$_.ID}},GPoStatus,CreationTime,ModificationTime | Export-Csv ./EmptyGPO.csv -NoTypeInformation -Append
}
}
Powershell Script - Fetching AD Group Details
<#Read Me !!
1. Script Usage - Fetching AD Group details such as Description, Group Type, Name, Category etc for all the Groups mentioned in Input.txt
2. Refer Groupinfo.csv for the details.
3. Refer Errorlogs.csv for any error logs.
For using it, directly copy the entire code, save it in .ps1 extension and have a Input.txt file on the same location containing AD Group names#>
$group = Get-Content .\Input.txt
Write-Host -ForegroundColor Green "Total count of Groups input = $($group.count)"
$line = 0
$linecount = $group.count
$pct = 0
foreach($groupname in $group)
{
$error.Clear()
$line++
$pct = $line/$linecount * 100
Write-Progress -Activity "Checking AD Group information.." -PercentComplete $pct -Status "$line of $linecount"
try{
Get-ADGroup -Identity $groupname -Properties * | Select SamAccountName,Description,Info,GroupScope,GroupCategory,CanonicalName | Export-Csv ./Groupinfo.csv -NoTypeInformation -Append
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
{
$groupname | Select-Object -Property @{n="Samaccountname";e={$groupname}},@{n="Status";e={$error.exception.Message}} | Export-Csv ./Errorlogs.csv -NoTypeInformation -Append
}
}