Solved

Retrieving Unlinked/Unused GPOs Powershell

Posted on 2016-08-24
3
101 Views
Last Modified: 2016-08-29
Dear powershell experts,

I have this working but for some reason the output is not exporting to csv. Could someone please help? Thanks a lot.

Get-GPO -all domain mydomain.com | Sort-Object displayname,ID | Where-Object { If ($_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "<LinksTo>" )
{
$_.DisplayName, $_.Id | Export-CSV c:\temp\unlinkedgpos.txt -notypeinformation
}}
0
Comment
Question by:IT_Admin XXXX
3 Comments
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41769481
$report = @()
Get-GPO -All | 
    foreach-object { If ( $_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "<LinksTo>" ) { $report += $_ }
    }
    $report | select-object displayname, id | Export-CSV c:\temp\unlinkedgpos.txt -notypeinformation

Open in new window

1
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41770036
I prefer to treat XML as such; if in some version, the APi decides to generate <LinksTo></LinksTo>, the script would not find them.
Plus it's shorter.
Get-GPO -All | ? {!([xml]$_.GenerateReport('Xml')).GPO.LinksTo.ChildNodes} | Select DisplayName, Id | Export-CSV c:\temp\unlinkedgpos.txt -notypeinformation

Open in new window

1
 

Author Closing Comment

by:IT_Admin XXXX
ID: 41775277
Thank you!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
A brief introduction to what I consider to be the best editor for PowerShell.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question