Blog

Retrieving GPO Links with PowerShell

Posted by:

Retrieving GPO Links with PowerShell
Sometimes I’m reminded that, even though Microsoft has been shipping their Group Policy PowerShell module for a while now, it is missing some key functionality. Fortunately, it took someone else asking me a question about how they could script something in PowerShell to realize that our SDM GPMC cmdlets, which have been around since about 2008, have a pretty good set of functionality even in the era of Microsoft’s own module! The question I had today was, “how can I script finding where GPOs are linked”? Sadly, the Microsoft module provides the verbs New-, Set- and Remove- against the GPLink noun, but they are missing a key one– Get-. Fortunately, the SDM GPMC cmdlets do include Get-SDMGPLink and it can be used in one of two ways. You can either feed it a Scope of Management (SOM), in the form of a LDAP distinguished name, like this:

Get-SDMGPLink -Scope "OU=Marketing,DC=cpandl,DC=com"

 

And it will return a list of GPOs linked to that SOM (i.e. OU or domain), like this:

Retrieving GPOs linked to a SOM

Or, you can feed the cmdlet a GPO Name, and have it return all the links for that GPO, like this:
Get-SDMGPLink -Name "GP Prefs"

With output that looks like this:

Retrieving GPO Links by GPO Name

So, either way you’re covered! And just a reminder, the current 1.3 version of the cmdlets were built for PowerShell 1.0, so they do not have a PowerShell 2.0 installer and associated module (we’re working on that!). In the meantime, you can still use these cmdlets in 2.0 by simply loading the module manually. Open up PowerShell, change directories to where the SDM GPMC cmdlets are usually installed (under C:Program FilesSDM SoftwareSDM Software GPMC Cmdlets, and type:

import-module -name .sdmgpocmdlets.dll

And you’re good to go!

 

Enjoy! — Darren

 

3


About the Author:

Darren Mar-Elia is CTO & Founder of SDM Software, Inc. Darren has over 25 years of IT and Software experience in the Microsoft technology area, including serving as a Director in Infrastructure at Charles Schwab, CTO of Windows Management Solutions at Quest Software, and Sr. Director of Product Engineering at DesktopStandard. He has been a Microsoft MVP in Group Policy technology for the last 6 years and has written and spoken on Active Directory, Group Policy and PowerShell topics frequently over the years. He maintains the popular Group Policy resource web site at www.gpoguy.com and has been a contributing editor for Windows IT Pro Magazine since 1997. He has written and contributed to twelve books on Windows. Darren also speaks frequently at conferences on Windows infrastructure topics.

Discussion

  1. Fabian  September 19, 2011

    Hello, I’m Interested in trying this feature, however, I am getting the following error:

    Import-Module : The specified module ‘.SDMGPOCmdlets.dll’ was not loaded becaus
    e no valid module file was found in any module directory.
    At line:1 char:14
    + import-module <<<< -name .SDMGPOCmdlets.dll
    + CategoryInfo : ResourceUnavailable: (.SDMGPOCmdlets.dll:String)
    [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
    ands.ImportModuleCommand

    The .dll is in the directory, please see below

    Directory: C:\Program Files\SDM Software\SDM Software GPMC Cmdlets

    Mode LastWriteTime Length Name
    —- ————- —— —-
    -a— 3/11/2009 4:54 PM 73728 Interop.GPMGMTLib.dll
    -a— 9/29/2006 2:14 PM 9774 sdm.ico
    -a— 2/8/2008 10:21 AM 217 SDMGPO.psc1
    -a— 3/11/2009 4:54 PM 69632 SDMGPOCmdlets.dll
    -a— 6/26/2008 1:18 PM 254043 SDMGPOCmdlets.dll-Help.xml
    -a— 9/19/2011 4:37 PM 667 SDMGPOCmdlets.InstallLog
    -a— 9/19/2011 4:37 PM 2012 SDMGPOCmdlets.InstallState
    -a— 1/31/2007 10:22 AM 1564672 System.Management.Automation.dll

    Any help is appreciated.
    -Fabian

    (reply)
    • Darren Mar-Elia  September 19, 2011

      Hi Fabian-
      The cmdlet install is built for PowerShell v.1, but that doesn’t mean it won’t work if you’re using v2. Open Powershell v2., change directories to the install folder (usually C:\Program Files\SDM Software\SDM Software GPMC Cmdlets) and type:
      import-module -name .\SDMGPOCmdlets.dll

      Hope that helps!

      Darren

      (reply)
  2. Fabian  September 20, 2011

    Darren, it worked. Thank you for your prompt reply.
    -Fabian

    (reply)

Add a Comment