→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !
‎08-25-2015 05:29 PM
###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
powershell.exe -noprofile -executionpolicy bypass -file {actionpath}Get-RSOP.ps1 -ComputerName {smartname} -UserName {domain}\{username}
Description: Get RSOP
Action: (copy code from above as is)
Leave the rest the default.
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now