Posts

Showing posts from December, 2022

Get-GPO Name, Link, Link Path and Enabled using Powershell

  $reportfile = "c:\temp\GPOLinksandWMIFilters.csv" Set-Content -path $reportFile -Value ("GPO Name, # Links, Link Path, Enabled, No override, WMI Filter") $gpmc = New-Object -ComObject GPMgmt.GPM $Constants = $gpmc.GetConstants() Get-GPO -All -Domain "abc.com" | %{ [int]$counter=0 [xml]$report = $_.GenerateReport($constants.ReportXML) try {     $wmifilterName = $report.gpo.filtername } catch {    $wmiFilterName = "none" }  $report.GPO.LinksTo | % {     If ($_.SOMPath -ne $null)     {       $counter += 1        add-Content -path $reportFile -Value ($report.GPO.Name + "," + $report.GPO.Linksto.Count +       "," + $_.SOMPath + "," + $_.Enabledd + "," + $_.NoOverridde + "," + $wmiFilterName) } } If ($counter -eq 0) { add-Content -path $reportFile -Value ($report.GPO.Name + "," +  $counter + "," + "No Links" + "," + "No Links") } }