Comments on: Why Your Hyper-V PowerShell Commands Don’t Work (and how to fix them) https://www.altaro.com/hyper-v/powershell-commands-dont-work-2/ Hyper-V guides, how-tos, tips, and expert advice for system admins and IT professionals Wed, 31 Mar 2021 06:25:20 +0000 hourly 1 By: Phil Bolduc https://www.altaro.com/hyper-v/powershell-commands-dont-work-2/#comment-2620 Fri, 15 Sep 2017 16:42:00 +0000 http://www.altaro.com/hyper-v/?p=12729#comment-2620 I have always used the following code to test if the user is an admin

function Test-Administrator {
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] “Administrator”))
{
return $false
}

return $true
}

if (-NOT (Test-Administrator)) {
Write-Warning “You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!”
break
}

]]>