→ Having trouble accessing our new support portal or creating a ticket? Please notify our team here

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
keys_it
Engaged Sweeper III
This script will allow you to pull the RSOP HTML Report for the Computer Asset and you will have a choice to either choose the last logged in user as scanned by Lansweeper or specify a user account. This script will also allow you to browse where to store the report but will generate a report name based on Computer name, date and time of report (see line 22).

The script makes the following assumptions:
Running Windows 7,8,8.1 (not tested on 10)
PowerShell version 3 or higher with GroupPolicy module installed (if RSAT is installed you most likely have the module)
You have admin rights (needed to run Get-GPResultantSetOfPolicy cmdlet) and rights to read Group Policy

PowerShell Code

###Variables passed from Lansweeper
param (
[parameter(Mandatory=$true)]
[string]$ComputerName,
[parameter(Mandatory=$true)]
[string]$UserName
)

$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
if (-not $IsAdmin){
$cmd = $MyInvocation.MyCommand.Path + " -ComputerName $ComputerName -UserName $UserName"
$arguments = "-NoProfile -NoExit -File ""& {$cmd}"""
#Start-Process powershell.exe -Verb RunAs -ArgumentList ($arguments -f ($myinvocation.MyCommand.Definition))
#Exit
}

### Import Module
Import-Module GroupPolicy

### Declare Variables
$date = (get-date -UFormat "%m_%d_%Y_Time-%T").Replace("/","_").Replace(":","_")
$reportName = "RSOP_" + $ComputerName + "_" + "$date.html"

### Function Get-FolderLocation to pick save location
function Get-FolderLocation{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
SelectedPath = 'C:\Temp’
}
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
}

### Function Get-RSOP Computer and last logged in user HTML Report
function Get-RSOPLastUser([string]$ComputerName,[string]$UserName){
Write-Host "Please select location to save HTML Report:"
$savedLocation = Get-FolderLocation
$fullPath = $savedLocation + "\" + $reportName
Write-Host "Collecting results...please be patient"
Get-GPResultantSetOfPolicy -Path $fullPath -Computer $ComputerName -User $UserName -ReportType Html | Out-Null

### Press any key to close the powershell dialog
Write-Host "Press any key to close ..."

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Exit
}

### Function Get-RSOP Computer and specified user HTML Report
function Get-RSOPSpecifyUser([string]$ComputerName){
$specifyUserName = Read-Host "Please specify user for RSOP Results (ex: Domain\Username)"
Write-Host "Please select location to save HTML Report:"
$savedLocation = Get-FolderLocation
$fullPath = $savedLocation + "\" + $reportName
Write-Host "Collecting results...please be patient"
Get-GPResultantSetOfPolicy -Path $fullPath -Computer $ComputerName -User $specifyUserName -ReportType Html | Out-Null

### Press any key to close the powershell dialog
Write-Host "Press any key to close ..."

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Exit
}

### Function Get-RSOPChoice to pick Computer and last logon user or Computer and specified user
function Get-RSOPChoice([string]$ComputerName,[string]$UserName){
$caption = "Choose RSOP Report Type";
$message = "Which RSOP report do you want to run?";
$computerOnly = New-Object System.Management.Automation.Host.ChoiceDescription "&Computer and Last User","Computer and Last User";
$userComputer = New-Object System.Management.Automation.Host.ChoiceDescription "Computer and &Specify User","Computer and Specify User";
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($computerOnly,$userComputer);
$answer = $Host.ui.PromptForChoice($caption,$message,$choices,0)

switch ($answer){
### Call Get-RSOPComp if Computer Only is selected
0 {Get-RSOPLastUser -ComputerName $ComputerName -UserName $UserName; break}
### Call Get-RSOPComp if Computer and User is selected
1 {Get-RSOPSpecifyUser -ComputerName $ComputerName; break}
}
}

### Call Get-RSOPChoice functions
Get-RSOPChoice -ComputerName $ComputerName -UserName $UserName


Copy the code and save it to your \\servername\Lansweeper$ folder as Get-RSOP.ps1

Asset Action
powershell.exe -noprofile -executionpolicy bypass -file {actionpath}Get-RSOP.ps1 -ComputerName {smartname} -UserName {domain}\{username}

Now you need to create the action under Configuration > Asset Pages > Asset Actions.

Description: Get RSOP


Action: (copy code from above as is)


Leave the rest the default.



Enjoy quick easy RSOP HTML reports!
0 REPLIES 0