When we execute Immy as User-Current user and the user is a local administrator, this works. The failure occurs if we attempt to use that as a system or metascript. When we manually run the code on the computer, it performs just as well as when we are logged into Powershell ISE as the Administrator.
The code worked on my machine when run as a meta script from Immy, as I am a local administrator logged in on my laptop.
But when I ran it on another tenant’s device, it failed with an error saying Access Denied.
Your user might be a local admin, but they might be a standard user. Might be worth throwing some logic in there to determine if the current user is part of the administrators localgroup
I confirmed that they are not part of the local administrator’s group. They are the standard users. Do we need to put on a logic for Get-Credential to pass via parameters and try or not worth?
Maybe, not too sure. I did find a debloat script with a self-elevating snippet that might work. Worth a try.
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue."
Start-Sleep 1
Write-Host " 3"
Start-Sleep 1
Write-Host " 2"
Start-Sleep 1
Write-Host " 1"
Start-Sleep 1
Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs
Exit
}
It’s because GitHub desktop is a per-user install, and per-user installers won’t work in system context. That said, I was working on a set of scripts some time ago that would handle these kinds of installers–the most recent successful example of this is Spotify (if you want to have a look at that approach).
Thank you @DimitriRodis .
I tested with the Soptify logic, but it is still not working. The GitHub Desktop is installed in the roaming profile for the logged-in user. I am trying more options using the Spotify code logic.
The solution to this would be to create a set of scripts to turn a squirrel “per user install” into a machine-wide one. Not sure you’re going to find a nicer way, outside of pleading with the software authors to create a machine-wide installer instead (and some vendors have, like PasswordBoss).