Few of the articles are posted as Images, Please use Laptop / Computers to go through the articles for best experience. For phone users, switch to Web Version

Please Share with your colleagues if you found these blogs informative. Happy Learning :-)

Powershell Script - Comparing Policies sub folders with GP

  <#Created By - Abhishek Bansal

Read Me !!

Script Usage - This script will compare sub folder of Policies folder inside Sysvol for every DC with the Group Policy configured in GPMC

Once it compares, it will list all the Policy folders which are mapped to GPMC and show as "Valid GPO Folder" and Policy folder for any non existing Group Policy would be shows as "Not valid GPO folder .#>


$gpoid = Get-GPO -All

$dcs = (Get-ADDomainController -Filter *).Name

foreach($dc in $dcs)

{

    if($(Test-Path -Path "\\$dc\sysvol\Mari.com\Policies")-eq $true)

    {

    $Sysvolgpos = $(Get-ChildItem -Path "\\$dc\sysvol\Mari.com\Policies" -Exclude "*PolicyDefin*").Name

            $arr = @()   

                                foreach($Sysvolgpo in $Sysvolgpos)

                        {

                              foreach($gpo in $gpoid)

                                {

                                    $gpoingpmc = "{$($gpo.id)}"

                                    if($($gpoingpmc -eq $Sysvolgpo))

                                        {

                                        $arr += $gpoingpmc

                                        break

                                            }

                                   }

                }

        }

$Sysvolgpos | Where {$arr -Contains $_} | Select-Object -Property @{n="Domain Controller";e={$dc}},@{n="GPO Folder";e={$_}},@{n="Status";e={"Valid GPO folder"}}

$Sysvolgpos | Where {$arr -NotContains $_} | Select-Object -Property @{n="Domain Controller";e={$dc}},@{n="GPO Folder";e={$_}},@{n="Status";e={"Not valid GPO folder"}}

}


Sample Output












Fetching Event Logging Mode on Windows Servers

<#Created By Abhishek Bansal

Read Note 

Script Usage :: Want to check what logging mode is configured for events like System , Setup, Application , Security logs for all your servers ?? What' the current size of all the events contained in these logs ?? What's the maximum log size of these events ?? For all this, use below script.

Pre requisites :: Copy all the code into a text file, save it with an extension ".PS1". On same location create a text file named "InputServers.txt" which will be containing names of machines. Once saved, run script as Administrator.

Execution & Outputs :: Once executed Output will be saved in a file named "LoggingmodeOutput.csv" and any Errors into "Errorslogs.csv" onto same location. #>


$servers = Get-Content .\InputServers.txt

foreach($server in $servers)

{

$server = $server.trim()

$Error.Clear()

    try{

    Invoke-Command -ComputerName $server -ErrorAction Stop -ScriptBlock{Get-WinEvent -ListLog Application,Setup,System,Security | Select-Object @{n="Hostname";e={$using:server}},LogName,LastAccessTime,LastWriteTime,@{n="MaximumLogSize(MB)";e={[Math]::Round($($_.MaximumSizeInBytes)/1024/1024,1)}},@{n="CurrentEventSize(MB)";e={[Math]::Round($($_.FileSize)/1024/1024,1)}},@{n="Events Count";e={$_.RecordCount}},@{n="LoggingMode";e={$(if($_.Logmode -eq "Circular"){echo "Overwrite events as needed (Oldest events first)"}elseif($_.Logmode  -eq "Retain"){echo "Do not overwrite events (Clear logs manually)"}elseif($_.Logmode  -eq "AutoBackup"){echo "Archive the log when full, do not overwrite events)"})}},LogFilePath} | Export-Csv ./LoggingmodeOutput.csv -NoTypeInformation -Append

        }

    catch

    {

    $server | Select-Object @{n="Hostname";e={$server}},@{n="ErrorMessage";e={$($Error.Exception.Message)}} | Export-Csv ./Errorlogs.csv -NoTypeInformation -Append

    }

}


Sample Output