Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPResult problem #3

Open
Nioubi24 opened this issue Dec 24, 2021 · 0 comments
Open

GPResult problem #3

Nioubi24 opened this issue Dec 24, 2021 · 0 comments

Comments

@Nioubi24
Copy link

Hi,

Very nice script, thanks a lot... ;-)

I think there is a problem when generating the 'gpresult', txt and HTML files.

The script must be run in Administator mode... fine.
So, suppose my current Windows session is Domain\JDOE.
I run the script with Powershell launched in Administator mode with the Domain\JDOELocalAdmininstrator account...
But in this case, GPResult won't get any result with an error message like "The user 'Domain\JDOELocalAdmininstrator' doesn't have RSOP data".
Because the GPOs had been retreived from the DC and applied to the PC for the current Windows session with JDOE account but not for the JDOELocalAdmininstrator account.
So the Powershell script can't read the GPOs for the JDOELocalAdmininstrator account.

I think it should be specified in the script the Logged session user in the GPResult command like suggested below.

Written code in the script :

#Get usefull files
Write-Host "#########>Take File to analyse<#########" -ForegroundColor DarkGreen
$seceditfile = "./secpol" + "-" + "$OSName" + ".cfg"
secedit /export /cfg $seceditfile 
#Second command in case of emergency
$gpofile = "./gpo" + "-" + "$OSName" + ".txt"
gpresult /r /V > $gpofile
$gpofile = "./gpo" + "-" + "$OSName" + ".html"
gpresult /h $gpofile /f | out-null

$auditconfigfile = "./auditpolicy" + "-" + "$OSName" + ".txt"

auditpol.exe /get /Category:* > $auditconfigfile

Suggested code :

#Get usefull files
Write-Host "#########>Take File to analyse<#########" -ForegroundColor DarkGreen
$seceditfile = "./secpol" + "-" + "$OSName" + ".cfg"
secedit /export /cfg $seceditfile 
#Second command in case of emergency
$gpofile = "./gpo" + "-" + "$OSName" + ".txt"

#-----------------------------------
# If the current Powershell user - adminXXX - is not the current Windows Session Username ==> GpResult Error "The user 'xxxxxxx\adminXXX' doesn't have RSOP data"  
#-----------------------------------
$PCUser = (Get-WMIObject -Classname Win32_ComputerSystem).Username # Get current LogonSession username 
$PSUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name # Get current Powershell User

if ($PCUser -Like $PSUser) { # If the current Powershell user - adminXXX - is the current Windows Session Username
	gpresult /r /V > $gpofile
} else {
	# ==> the text file generated by gpresult will only contain "INFO : The user 'xxxxxxx\yyyyy' doesn't have RSOP data"... need to specifiy the User parameter
	gpresult /r /V /user $PCUSER > $gpofile # Execute the gpresult for the Windows Session Username
}

$gpofile = "./gpo" + "-" + "$OSName" + ".html"

if ($PCUser -Like $PSUser) { # If the current Powershell user - adminXXX - is the current Windows Session Username 
	gpresult /h $gpofile /f | out-null
} else {
	# ==> gpresult won't generate the HTML file... need to specify the User Parameter
	gpresult /h $gpofile /f /user $PCUSER | out-null # Execute the gpresult for the Windows Session Username
}
#-----------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant