IntuneDriveMapping icon indicating copy to clipboard operation
IntuneDriveMapping copied to clipboard

Script not detecting that it is running as system

Open Paul-Spagnola-Work opened this issue 1 year ago • 3 comments

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)
	}
}

Paul-Spagnola-Work avatar Aug 03 '22 16:08 Paul-Spagnola-Work

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.

nicolonsky avatar Aug 04 '22 05:08 nicolonsky

Github formatted it wrong. I'll fix it.

Paul-Spagnola-Work avatar Aug 04 '22 12:08 Paul-Spagnola-Work

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.

Paul-Spagnola-Work avatar Aug 04 '22 12:08 Paul-Spagnola-Work