nicolonsky / IntuneDriveMapping

Generate PowerShell scripts to map network drives on Intune managed Windows 10 devices
https://intunedrivemapping.azurewebsites.net/
MIT License
148 stars 17 forks source link

Script not detecting that it is running as system #40

Open Paul-Spagnola-Work opened 2 years ago

Paul-Spagnola-Work commented 2 years ago

For some reason the Test-RunningAsSystem is returning false even though the start-transcript header shows the user as DOMAIN\SYSTEM

I am making the following suggestion for changing the fuction:


Original function:

#check if running as system
function Test-RunningAsSystem {
    [CmdletBinding()]
    param()
    process {
        return [bool]($(whoami -user) -match "S-1-5-18")
    }
}

Suggested function (which is working properly in my testing):


#check if running as system
function Test-RunningAsSystem {
    [CmdletBinding()]
    param()
    process {
        return [bool]([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem)
    }
}
nicolonsky commented 2 years ago

The suggested edit is actually not an option as no check is performed at all, you just return a ‘bool’ which translates to false by default.

Paul-Spagnola-Work commented 2 years ago

Github formatted it wrong. I'll fix it.

Paul-Spagnola-Work commented 2 years ago

I noticed it posted wrong, but when I edited the post and added the correct code markup, I forgot to click save. I just hist save now.