# encoding: ascii
# api: powershell
# title: Get-GPOUNCPaths
# description: This script retrieves the UNC paths from all group policies in the domain. Useful during file server cutovers and renaings.
# version: 0.1
# type: script
# author: Justin Grote
# license: CC0
# x-poshcode-id: 6039
# x-archived: 2016-05-17T07:00:07
# x-published: 2016-10-05T22:23:00
#
#
#Get-GPOUNCPaths.ps1
#This script retrieves the UNC paths from all group policies in the domain

$gpos = get-gpo -all
foreach ($gpo in $gpos) {

    [string]$xmlReport = $gpo | Get-GPOReport -reporttype xml

    $searchResults = $xmlReport -split '["\n\r"|"\r\n"|\n|\r]' | where {$_} | Select-String -pattern '\\\\.*\\.*' -context 3

    foreach ($searchResult in $searchResults) {
        
        $returnParams = [ordered]@{}
        $returnParams.GUID = $gpo.id
        $returnParams.Name = $gpo.DisplayName
        $returnParams.Line = $searchResult.LineNumber
        $returnParams.Match = $searchResult.Line
        $returnParams.Context = $searchResult.ToString()

        # Output a search result 
        new-object PSObject -Property $returnParams

    }
}
