Skip to content

Instantly share code, notes, and snippets.

@mnaoumov
Last active April 28, 2018 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnaoumov/fe950c42fca4ad2482df2878b3bf9aaa to your computer and use it in GitHub Desktop.
Save mnaoumov/fe950c42fca4ad2482df2878b3bf9aaa to your computer and use it in GitHub Desktop.
Setup environment
powershell -NoExit -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri https://gist.githubusercontent.com/mnaoumov/fe950c42fca4ad2482df2878b3bf9aaa/raw/Setup.ps1 -UseBasicParsing | Invoke-Expression"
#Requires -Version 4
[CmdletBinding()]
param
(
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
trap { throw $Error[0] }
function Main {
if (-not $PSCommandPath) {
Invoke-WebRequest -Uri https://gist.githubusercontent.com/mnaoumov/fe950c42fca4ad2482df2878b3bf9aaa/raw/Setup.ps1 -OutFile '~\Setup.ps1'
}
if (-not $PSCommandPath -or -not (Test-Administrator)) {
$scriptPath = Resolve-Path '~\Setup.ps1'
Start-Process -FilePath powershell.exe -ArgumentList "-NoExit -NoProfile -ExecutionPolicy Bypass -File $scriptPath" -Verb RunAs
Read-Host -Prompt "Executing as admin. Press Enter to close"
exit
}
Read-Host -Prompt "Execution finished. Press Enter to close"
}
function Test-Administrator {
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment