Repository navigation
Expand file tree
/
Copy pathStorage&PerformanceAssistantScript.ps1
More file actions
40 lines (35 loc) · 1.7 KB
/
Copy pathStorage&PerformanceAssistantScript.ps1
File metadata and controls
40 lines (35 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
############
## Setup ##
############
$Warningcolour = (Get-Host).PrivateData
$Warningcolour.WarningBackgroundColour = "Red"
$Warningcolour.WarningForegroundColour = "White"
$DebugColour = (Get-Host).PrivateData
$DebugColour.DebugBackgroundColour = "White"
$DebugColour.DebugForegroundColour = "Blue"
$console.backgroundcolour = "Black"
Write-Host "Setting up ..." -ForegroundColor Green
############################################
## Self elevate to Administrator Privlages #
#############################################
Write-Host "Checking for administrative rights..." -ForegroundColor Green
## Get the ID and security principal of the current user account.
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrinciples = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
## get the security principal for the administrator role.
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
##check if script is running as admin
if ($myWindowsPrinciples.IsInRole($adminRole))
{
Write-Host "Script is Currently running as administrator" -ForegroundColor Green
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
}
else
{
Write-Host "We are not running as Administrator. Attempting to Relaunch as Administrator..." -ForegroundColor Red
##Not running as admin, relaunch script as admin
$NewProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
## Specifying Current Script path and name as Parameter, support for spaces included :)
$NewProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
## Process should be elevated.
}