I'm trying to use the Get-GPOLinkInfo.ps1 powershell script from p597 of the 5th edition green book.
I'm a complete novice to powershell so not clear where I'm going wrong.
Typed in the script as listed in the book. It's missing from the downloads page on the Website, not sure if this is relevent

## Get-GPOLinkinfo.ps1
## disclaimer info

## Get GP environment info
. "$pwd\Set-GPEnvironment.ps1"

$gpmSitesContainer = $gpm.GetSitesContainer
($dnsForestRoot, "","",$gpmConstants.UsePDC)
$gpmSearchCriteria = $gpm.CreateSearchCriteria()
$somSearchCriteria = $gpm.CreateSearchCriteria()
$GPO_List = $gpmDomain.SearchGPOs($gpmSearchCriteria)

Write-Host
Write-Host "The following list contains GPOs in the $($gpmDomain.Domain) domain, the containers linked to them, and their inheritance settings:"
Write-Host

$myCollection = @()

foreach($GPO in $GPO_List)
{
$somSearchCriteria = $gpm.CreateSearchCriteria()
$somSearchCriteria.Add(
$gpmConstants.SearchPropertySOMLinks,
$gpmConstants.SearchOpContains,$GPO)
$SOM_List = $gpmDomain.SearchSOMs($somSearchCriteria)
if($SOM_List.Count -ne 0)
{
foreach($SOM in $SOM_List)
{
$myobj = "" | Select-Object GPOName,
Location, Type
$myobj.GPOName = $GPO.Displayname
$myobj.Location =$SOM.Name
$myobj.Type = Convert-GPSOMType($SOM.Type)
$myCollection += $myobj
}
$siteSOM_List = $gpmSitesContainer.SearchSites(
$somSearchCriteria)
foreach($SOM in $siteSOM_List)
{
$myobj = "" | Select-Object GPOName,
Location, Type
$myobj.GPOName = $GPO.Displayname
$myobj.Location =$SOM.Name
$myobj.Type = Convert-GPSOMType($SOM.Type)
$myCollection += $myobj
}
}
}
$myCollection


When it's run I get the error "Method invocation failed becase [System.management.automation.PSMethod] doesn't contain a method named 'Searchsites'. At C:\Scripts\Get-GPOLinkinfo.ps1:37 char:50.

This points to the line $siteSOM_List = $gpmSitesContainer.SearchSites($somSearchCriteria) being the problem - but I'm not sure why, or how to fix this.

Is it a problem with the script in the book, or - more likely - something I'm missing?

Any help would be greatly appreciated.

Richard.