-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-PowerShellAsAdministrator.ps1
More file actions
56 lines (40 loc) · 1.35 KB
/
Start-PowerShellAsAdministrator.ps1
File metadata and controls
56 lines (40 loc) · 1.35 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
.SYNOPSIS
The "Start-PowerShellAsAdministrator" function spawns an Administrator PowerShell shell.
.EXAMPLE
PS C:\> Start-PowerShellAsAdministrator
################################
# A SEPARATE TERMINAL WINDOW IS CREATED
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32>
Here we run the function and another PowerShell terminal window appears in the default directory of an Administrator shell, "C:\WINDOWS\system32>".
.NOTES
Name: Start-PowerShellAsAdministrator.ps1
Author: Travis Logue
Version History: 1.1 | 2021-12-31 | Initial Version
Dependencies:
Notes:
- This is where I retrieved the syntax: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.2#example-5--start-powershell-as-an-administrator
.
#>
function Start-PowerShellAsAdministrator {
[CmdletBinding()]
[Alias('PowerShellAsAdministrator')]
param (
[Parameter()]
[switch]
$NoProfile
)
begin {}
process {
if ($NoProfile) {
Start-Process -FilePath "powershell" -Verb RunAs -ArgumentList "-NoProfile"
}
else {
Start-Process -FilePath "powershell" -Verb RunAs
}
}
end {}
}