28 lines
900 B
PowerShell
28 lines
900 B
PowerShell
# Ashley's script to pull all OUs and their linked GPOs, dump to csv
|
|
$Timestamp = (Get-Date).ToString("yyyyMMdd_HHmmss")
|
|
Get-GPLinkReport | export-csv "D:\GPOs\^LinkReport\GPOLinks-$Timestamp.csv" -Force
|
|
|
|
# import-csv Ashley's report, filter only ITD
|
|
$LinkReports = Get-ChildItem "D:\GPOs\^LinkReport\" | Sort-Object LastWriteTime -Descending
|
|
$FirstNewest = $LinkReports | select -first 1
|
|
$SecondNewest = $LinkReports | select -first 2 | select -last 1
|
|
|
|
# check dates and backup any new changes
|
|
$compare = Compare-Object $FirstNewest $SecondNewest
|
|
|
|
|
|
|
|
|
|
|
|
$GPOs=Get-GPO -All
|
|
ForEach($GPO in $GPOs)
|
|
{
|
|
$GPOName = $GPO.DisplayName
|
|
$Timestamp = $GPO.ModificationTime.ToString("yyyyMMdd_HHmmss")
|
|
$FolderPath = "D:\GPOs\$GPOName\$Timestamp\"
|
|
If(!(Test-Path $FolderPath))
|
|
{
|
|
New-Item -Path $FolderPath -Force -ItemType Directory
|
|
}
|
|
$GPO | Backup-GPO -Path $FolderPath
|