PS: Get GPO OU Report

         # Setting file variables, local folders or UNC shares are permitted.
         $path = 'C:'
         $domain = Get-ADDomain
         $GPOs = Get-GPO -all -server myserver.mydomain.comยท         
         # Backup the GPOs

         Backup-Gpo -All -Path $path
         # Generating HTML reports
         $GPOs | ForEach-Object {
         $dname = $_.DisplayName

##############################################################################

 

# For an individual Report
Get-GPOReport -name ($dname) -ReportType Html -Path "C:\$dname.html"}

PS: Get OU's for a Policy (Export to CSV)

$Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher

$Searcher.SearchRoot = "LDAP://DC=snet,dc=crouse,dc=org"

$Searcher.SearchScope = "subtree"

$Searcher.Filter = "(objectClass=organizationalUnit)"

$Searcher.PropertiesToLoad.Add('Distinguishedname') | Out-Null

$LDAP_OUs = $Searcher.FindAll()

$OUs = $LDAP_OUs.properties.distinguishedname

$OUs | foreach { (Get-GPInheritance -Target $_).GPOlinks } | Select @{name = "GPO Name" ; Expression = {$_.Displayname}} , @{name = "Link Location" ; Expression = {$_.Target}} | sort -Property "GPO Name"| Group-Object -Property 'GPO Name' | ForEach-Object {

New-Object -TypeName PSCustomObject -Property @{

'GPO Name' = $_.Name

'Links' = ($_.Group | ForEach-Object {$_.'Link Location'}) -join ';'

} | Select-Object -Property 'GPO Name',{$_.Links}|export-csv -path out.csv -Append

}

#http://community.idera.com/powershell/ask_the_experts/f/active_directory__powershell_remoting-9/21616/list-of-all-gpo-s-with-their-links

PS: Get Security Filtering Groups for a Policy

$perms = Foreach ($GPO in (Get-GPO -All | Where {$_.DisplayName -like "*"})){

   Foreach ($Perm in (Get-GPPermissions $GPO.DisplayName -All | Where {$_.Permission -eq "GpoApply"})) {

      New-Object PSObject -property @{GPO=$GPO.DisplayName;Trustee=$Perm.Trustee.Name;Permission=$Perm.Permission}

   }

}

$perms | Select GPO,Trustee,Permission|export-csv -path out_filtering.csv -Append

#https://social.technet.microsoft.com/Forums/office/en-US/6d717266-e641-47df-807e-4d579f6f914f/gpo-report-with-security-filtering?forum=winserverpowershell

PS: Get members of a group

import-module ActiveDirectory

Get-ADGroupMember "DL CH Lawson Supervisors" | Select samAccountName | out-file c:\dropbox\lawson.txt

Recursively Compress Folders with the Folders name as the zip

@echo off FOR /D %%f IN (*) DO ( REM @ECHO %%f %cd% @ECHO %cd%\%%f CD .\%%f forfiles /m *.* /d -30 /c "cmd /c @D:\McKesson\7z\7z.exe a -x!*.zip -x!*.exe %%f.zip @file & del @file" ECHO %ERRORLEVEL% call D:\McKesson\Logs\compress.cmd cd .. REM pause )