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:
Get-SDMGPLink -Name "GP Prefs"
With output that looks like this:
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
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
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
Darren, it worked. Thank you for your prompt reply.
-Fabian
I don’t understand why it isn’t working more with the GPO IDs. When I use Get-SDMgplink it can retrieve a GPO GUID. But when I want to use that same GUID to add a link at another OU (with cmdlet Add-SDMgplink) I only can fill in the parameter “Name”.
The other day I had an issue where it was linking wrong GPO’s with almost the same name, but with the prefix “Copy of “. The result was that old Group Polcies, which where once copied were applied to the systems in our new OU structure.
Thus, it would be very nice if you can use Add-SDMgplink with parameter GPOID. Now I have to fallback to the default GroupPolicy module which has the cmdlet New-GPLink with parameter Guid.
Johan-
Thanks for this feedback. We’ll check into this and get the cmdlet updated to ensure it’s doing what it’s supposed to.
Thanks again!
Darren
Johan-
Just a quick note to let you know that we’re going to be releasing version 1.5 of the cmdlets in the next few days, and amongst other things, we’re adding support for using either GPO name or GUID to reference a GPO.
How can I feed the -name parameter a wildcard string?
At the moment there is no support for wildcards within the GPO name. If the goal is to find all links that contain GPOs that have a certain character string in them, you might want to try getting that list first using something like the Microsoft GP Module’s Get-GPO and then feed that list to get-sdmgplink
Thanks. Is there any way to use this cmdlet to find all GPOs that contain a specific linke, ie group?
Hi!
Is there a way to return a list of all the GPO links across the domain? When I scope it to the root of the domain, it is only showing links at that level, not all levels below.
Thanks!
Paul-
With our cmdlets, you either feed get-sdmgplink GPO names or scopes (i.e. sites, domains, OUs). So the only way to get links across the entire domain is to use get-sdmGPO to retrieve all GPOs and then pass each one to get-sdmgplink, or use AD cmdlets to retrieve the DNs of all site, domain and OUs and then feed that to get-sdmgplink. If I get some time I will blog about that and provide some script samples.
Darren
I’m finding a problem with add-sdmsplink. I can go through an existing OU and pick up the GPOs that are linked with get-sdmgplink. The problem is when I try to link a GPO name “workstation”. Because of the search mechanism used, it will actually link “workstation_new”. Who can I link a specific name? I don’t see where the GPOid can be used.
Mike-
Are you using the 1.5 version of the cmdlets? We made some changes in 1.5 that corrected/changed two things. First, in previous versions we were doing a search on GPO by using a “Contains” operator. This meant that when referencing a GPO that has a similar name to another, we would not necessarily return the desired result. That changed so that now if you reference a GPO name, we look for the exact name. The second change was to add support for a -GPOID param to all of the relevant cmdlets. Have a look at 1.5 and see if it works for you.
Darren
Yes, that’s it. 1.5 is even more awesome!
This is hands down the handiest set of PowerShell cmdlets I have downloaded!
get-sdmgplink has saved me about 10 days work!
Glad to hear it Kriss!
Darren