Solved

Retrieving Unlinked/Unused GPOs Powershell

Posted on 2016-08-24
3
49 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 78

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 83

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now