Solved

Retrieving Unlinked/Unused GPOs Powershell

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A brief introduction to what I consider to be the best editor for PowerShell.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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