Solved

Retrieving Unlinked/Unused GPOs Powershell

Posted on 2016-08-24
3
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 81

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 85

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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