Closed mikemaccana closed 6 years ago
Oh wow, thanks for a) testing that and b) reporting it. You'd think that the following code should work 🤔
$Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
$Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
I'll browse the Internet a bit for alternative solutions.
Weird: that returns True
when run in Powershell 6.1 preview 4 started as Administrator, just after windows build tools
says I'm not administrator:
~\OneDrive\Documents $ npm install -g windows-build-tools
> windows-build-tools@3.1.0 postinstall C:\Users\mikem\AppData\Roaming\npm\node_modules\windows-build-tools
> node ./dist/index.js
Downloading BuildTools_Full.exe
Downloading python-2.7.14.amd64.msi
[> ] 0.0% (0 B/s)
Downloaded python-2.7.14.amd64.msi. Saved to C:\Users\mikem\.windows-build-tools\python-2.7.14.amd64.msi.
Starting installation...
Please restart this script from an administrative PowerShell!
The build tools cannot be installed without administrative rights.
To fix, right-click on PowerShell and run "as Administrator".
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! windows-build-tools@3.1.0 postinstall: `node ./dist/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the windows-build-tools@3.1.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\mikem\AppData\Roaming\npm-cache\_logs\2018-08-28T09_27_01_485Z-debug.log
~\OneDrive\Documents $ $Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
~\OneDrive\Documents $ $Identity
AuthenticationType : CloudAP
ImpersonationLevel : None
IsAuthenticated : True
IsGuest : False
IsSystem : False
IsAnonymous : False
Name : MIKE-SURFACE-GO\mikem
Owner : S-1-5-32-544
User : S-1-5-21-1153645426-1359381961-3925463904-1001
Groups : {S-1-1-0, S-1-5-114, S-1-5-32-544, S-1-5-32-545...}
AccessToken : Microsoft.Win32.SafeHandles.SafeAccessTokenHandle
Token : 2632
UserClaims : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: MIKE-SURFACE-GO\mikem,
http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid:
S-1-5-21-1153645426-1359381961-3925463904-1001,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-114...}
DeviceClaims : {}
Claims : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: MIKE-SURFACE-GO\mikem,
http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid:
S-1-5-21-1153645426-1359381961-3925463904-1001,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-114...}
Actor :
BootstrapContext :
Label :
NameClaimType : http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
RoleClaimType : http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid
~\OneDrive\Documents $ $Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
~\OneDrive\Documents $ $Principal
Identity : System.Security.Principal.WindowsIdentity
UserClaims : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: MIKE-SURFACE-GO\mikem,
http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid:
S-1-5-21-1153645426-1359381961-3925463904-1001,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-114...}
DeviceClaims : {}
Claims : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: MIKE-SURFACE-GO\mikem,
http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid:
S-1-5-21-1153645426-1359381961-3925463904-1001,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0,
http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-114...}
Identities : {MIKE-SURFACE-GO\mikem}
~\OneDrive\Documents $ $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
True
Hey @mikemaccana, I just downloaded the PowerShell 6.1 RC1 and couldn't reproduce the issue anymore. I hope this is fixed!
Using Powershell 6.1 preview 4, the command fails the admin check - even though it's being run as administrator:
Running the same command in Powershell 5 admin works fine. Not a big deal but worth updating the admin check for newer Powershells.