Skip to content

Instantly share code, notes, and snippets.

@blazejwiecha
Created June 28, 2017 17:16
Show Gist options
  • Save blazejwiecha/ddff1be7781eaf0b42363f4d347aac61 to your computer and use it in GitHub Desktop.
Save blazejwiecha/ddff1be7781eaf0b42363f4d347aac61 to your computer and use it in GitHub Desktop.
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
'running with full privileges'
md -Path 'C:\Windows\perfc'
Disable-WindowsOptionalFeature -Online -FeatureName smb1protocol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment