Solved

Retrieving Unlinked/Unused GPOs Powershell

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…

737 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