I have a task of installing applications through Intune, 98% of all the installations are fine. but I have an issue with some of them.
The issue is when an application can't be installed or just run by the system account.
I've tried to create a local admin account, and then let the script start the other script as that account, but here the windows security kicks in - the system account is not allowed to run Start-Process
I use PSExec64.exe to start the powershell.exe
here is the code to do the install
$InstallUser = "IntuneInstaller"
$password = -join ((33..126) | Get-Random -Count 32 | ForEach-Object {[char]$_})
$passwordSecure = ConvertTo-SecureString -AsPlainText $password -Force
$null = New-LocalUser "$InstallUser" -Password $passwordSecure -FullName "$InstallUser" -Description "Automated Install Account" -AccountNeverExpires -PasswordNeverExpires
Add-LocalGroupMember -Group "Administrators" -Member "$InstallUser" -ErrorAction SilentlyContinue
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($InstallUser,$passwordSecure)
Start-Process PowerShell.exe -Credential ($Credentials) -WorkingDirectory "c:\sysman" -ArgumentList "c:\SysMan\WriteMyNameInTheSand.ps1 -MyName $env:USERNAME -MyLocation c:\sysman -MyMessage $password" -Wait -WindowStyle Hidden
Remove-LocalUser -Name "$InstallUser"
It woks fine if I run it as adminstrator - but if I run it as Systemaccount I get the error:
Start-Process : This command cannot be run due to the error: Access is denied.
At C:\SysMan\RunInstallAsAdminUser.ps1:20 char:1
+ Start-Process Powershell.exe -Credential ($Credentials) -WorkingDirec ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Anyone with a good sugestion?