help with powershell script.

Could you please help with the powershell script. It doesn't give me any error and doesnt run.

Here is the script.

When I run it, this is what I get

PS C:\Script-GPOStatus> .\Get-GPStatus.ps1

PS C:\Script-GPOStatus> $Env:USERPROFILE\Desktop\Get-GPStatus.ps1
At line:1 char:17
+ $Env:USERPROFILE\Desktop\Get-GPStatus.ps1
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '\Desktop\Get-GPStatus.ps1' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
Who is Participating?
SubsunConnect With a Mentor Commented:
Either way it will work.. Make sure you import the module first and then run these commands..
creative555Author Commented:
I dont understand the instructions provided....not sure what I need to specify and where in order to run it.

Thank you
creative555Author Commented:
This is not working: Do I need to put the name of my profile??

Load function stored on user desktop, get group policy status over the forest and record in a variable, export variable to csv file.
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Benjamin MOREAUProject ManagerCommented:
try to run :

Benjamin MOREAUProject ManagerCommented:
otherwise, just open powershell console, browse directory et run :

Script is written as a module. Save code to desktop folder and then you can import the module using following command..
Import-Module '$Env:USERPROFILE\Desktop\Get-GPStatus.ps1'

Open in new window

Once you complete the import you can use the commands shown in the example of the article..

Get-GPStatus 'MyDomainFQDN'

Open in new window

creative555Author Commented:
ok. that worked. but the excel  file that I received by running this command did not give me a good output.
$GPStatus = Get-GPStatus '' | Export-Csv -Path "$Env:USERPROFILE\Desktop\GPStatus5.csv" -Delimiter ';' –NoTypeInformation

But I received the output on the screen: Is there any other command I should run in order toget the list of GPOs such as empty ones, orphans, etc?


Preparing status record of Group Policy(ies) linked on Site(s) and Domain(s) listed below:
=> 391 Group Policy(ies) linked
Checking Link options : enabled, enforced, disabled
Preparing status record of Group Policy(ies) not linked on Site(s) or Domain(s) listed below but stored in the latter:

=> 25 Group Policy(ies) not linked
Adding status record(s) considering orphaned Group Policy Directory(ies)
=> 26 orphaned Directory(ies)
Checking Sysvol status:
- selecting Domain Controller to query
- Network Drive "Sysvol_0" on "\\server.domain\SYSVOL\\Policies" already mounted
- checking Directory, Folder(s) and Setting(s) existence
- updating Sysvol status considering NTFRS conflict(s)
=> 16 NTFRS conflict(s)
creative555Author Commented:
oh. so I have to use each command from this script? The script is not going to run all the commands?

I also need to group them.....The excel file looks bad. It is not grouped and has bad results. Could you please help me with the command to select and group them so that I have for example list of empty GPOs, list of unlinked GPos, etc.

THank you so much!!
creative555Author Commented:
This script only shows on the screen the following below but doesn't identify which 26 Group Policies are not linked and what 53 orphaned directories are....Please help with running this script

=> 26 Group Policy(ies) not linked
Adding status record(s) considering orphaned Group Policy Directory(ies)
=> 53 orphaned Directory(ies)
You need to filter the results of Get-GPStatus cmdlet to get required result..
$GPStatus = Get-GPStatus ''
$GPStatus | ? { !($_.existsInPolicies) -and ($_.enabledOn -or $_.enforcedOn -or $_.disabledOn) } | Export-csv  "C:\orphaned_grouppolicy_links.csv" -nti
$GPStatus | ? { !($_.existsInPolicies) -and $_.sysvol -ne 'no_Directory' }  | Export-csv  "C:\ orphaned_GroupPolicy_Directory.csv" -nti

Open in new window

creative555Author Commented:
Do I need to copy and paste one line by one into the powershell? Or I can copy three rows and paste it?
creative555Author Commented:
THank you so much!! Script worked like you said
Senior IT System EngineerIT ProfessionalCommented:
OK creative555, so does the script only list the GPO not doing anything to the existing production GPO ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.