[gptalk] Re: Get-SDMgpo only returning 3/4

  • From: "Darren Mar-Elia" <darren@xxxxxxxxxx>
  • To: <gptalk@xxxxxxxxxxxxx>
  • Date: Wed, 25 Jun 2008 10:55:30 -0700


One thing you can do to make your script simpler is to the following:


$gpos = Get-SDMgpo * | select Name


What that will do is store only the names of the GPOs in the $gpos variable,
which gets rid a lot of your grepping and string parsing. 


Let me know if that doesn't work. Also, one thing I should have in the next
version of the cmdlets is the ability to pipe output of Get-SDMGPO into
other cmdlets. Today that does not work because the current output of that
cmdlet is the native GPMC object, which is not pipe-able. I should have a
version out soon that will let you do something like this:


Get-SDMGPO * | Export-SDMGPO -location c:\backups




From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx] On
Behalf Of Kevin Gay
Sent: Wednesday, June 25, 2008 9:58 AM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Re: Get-SDMgpo only returning 3/4


Domain Admin, and just double checked it, have full control over a GPO I
know isn't listed... grr. I was running powershell under my regular account
while simultaneously running active directory under my admin account, can't
believe I didn't notice that. Thanks. 


From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx] On
Behalf Of Cruz, Jerome L
Sent: Wednesday, June 25, 2008 11:41 AM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Re: Get-SDMgpo only returning 3/4


Hi Kevin,


Several possibilities (off the top of my head.not even looking at the code

1)      The account used to run the script does not have access to all of
the GPOs.

2)      Something wrong with "spaces" in the display names of the GPOs
(causing them to be the same name.data overwriting)

3)      [low probability] Many GPOs have the same name (e.g. New Group
Policy Object).


Jerry Cruz | Group Policies Product Manager | Boeing IT


From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx] On
Behalf Of Kevin Gay
Sent: Wednesday, June 25, 2008 8:46 AM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Get-SDMgpo only returning 3/4


I'm using Powershell to create backups of all our GPO's, basically a daily
script that runs and drops them into a folder with the GPO's name as the
folder name. I've attached links and the script at the bottom if anyone
would like to use it. But the real problem is that Get-SDMgpo only retrieves
about 3/4 of all the GPOs in the domain, we have 61 GPO's, running
Get-SDMgpo * (which grabs them all) only returns 48. So I'm wondering if
anyone else has had this problem and if they resolved it. I'm also using the
free download of the cmdlets.


http://www.gpoguy.com/powershell.htm - explanation of the cmdlets and
download location. You'll need to see the howto so you can add the cmdlets
to powershell.

http://gnuwin32.sourceforge.net/packages/grep.htm - for grep used in the
script, I just placed the files in system32.




#Add-PSSnapin SDMSoftware.PowerShell.GPMC #uncomment in case you get an
error saying Get-SDMgpo is not understood.

$gpmList = Get-SDMgpo * | grep "DisplayName"


$strSavePath = \\server\share" 


#             the log doesn't seem to work as well as I expected it to.

$Date = Get-Date -format MM-dd-yyyy

$Logs = \\server\share\Logs\" + $Date + ".txt"


foreach ($gpmGPOName in $gpmList)



#             Essentially this is performing an InStr() and then a Right()

#   so it can grab only the GPO name.

                $Index = $gpmGPOName.indexof(":") + 2

                $Length = $gpmGPOName.length - $Index


#             See if it outputs correctly

#             echo $gpmGPOName.substring($Index, $Length) 

                $gpmName = $gpmGPOName.substring($Index, $Length)

                echo $gpmName


#             put together the full path            

                $strLocation = $strSavePath + "\" + $gpmName



#             Check for folder to put GPO in

                if (!(Test-Path $strLocation))


                                md $strLocation


#             Log some info.

                echo $gpmName >> $Logs

                echo $gpmName

                Export-SDMgpo -Name $gpmName  -location $strLocation
-Description $gpmName >> $Logs







Kevin Gay

Desktop Administrator

Cherokee Nation Enterprises


Catoosa, OK 74015


Other related posts: