-
-
Save jplindgren/77ec678cb2c814dc37e48a20ba701696 to your computer and use it in GitHub Desktop.
PowerShell: Profile to always launch PS as Administrator, set Aliases (ex. Notepad++), Import SharePoint Online, Azure AD, and Azure Services.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if Running as Admin | |
$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") | |
if (-not $IsAdmin) | |
{ | |
if ($MyInvocation.ScriptName -ne "") | |
{ | |
try | |
{ | |
Write-Host "Relanuching Script as Admin" | |
$arg = "-file `"$($MyInvocation.ScriptName)`"" | |
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList $arg -ErrorAction 'stop' | |
} | |
catch | |
{ | |
Write-Warning "Error - Failed to restart script with runas" | |
break | |
} | |
} | |
else | |
{ | |
try | |
{ | |
Write-Host "Relanuching Shell as Admin" | |
Start-Process "$psHome\powershell.exe" -Verb Runas -ErrorAction 'stop' | |
} | |
catch | |
{ | |
Write-Warning "Error - Failed to restart script with runas" | |
break | |
} | |
} | |
Write-Host "Exiting" | |
Stop-Process -Id $PID | |
} | |
# Shell Modifications | |
$Shell = $Host.UI.RawUI | |
# Set Window Size | |
$size = $Shell.WindowSize | |
$size.width=100 | |
$size.height=25 | |
$Shell.WindowSize = $size | |
# Set BufferSize | |
$size = $Shell.BufferSize | |
$size.width=100 | |
$size.height=5000 | |
$Shell.BufferSize = $size | |
# Add Aliases | |
new-item alias:np -value "C:\Program Files (x86)\Notepad++\notepad++.exe" | |
# Clear the Screen | |
Clear-Host | |
# Import SPO | |
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking | |
# Import Azure AD | |
Import-Module MSOnline | |
#Import | |
Set-ExecutionPolicy Bypass | |
cd "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services" | |
.\ShortcutStartup.ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment