I don't get anywhere when using the Start-Process / Start-Job cmdlets with -Credential $ cred
Problem
I have a service account in a deployment (automatic mode). It was previously added to the local administrator group. I want to reduce the potential damage that I could do by removing this user from the administration group and explicitly assigning folder access rights to this user.
- I rather get a permission error than doing something that happens by accident. Delete item "$ notdefined \ *"
However, in the same powershell script, I want to be able to raise in order to accomplish things like:
- sc.exe
- restarting the application pool that requires an administrator.
One of my failed attempts
$job = Start-Job -ScriptBlock { param( [string]$myWebAppId ) Import-Module WebAdministration Write-Host "Will get the application pool of: IIS:\Sites\$myWebAppId and try to restart" $appPoolName = Get-ItemProperty "IIS:\Sites\$myWebAppId" ApplicationPool Restart-WebAppPool "$($appPoolName.applicationPool)" Write-Host "restart of apppool succeeded." } -Credential $cred -ArgumentList @("appname") Write-Host "started completed" Wait-Job $job Write-Host "wait completed" Receive-Job $job -Verbose Write-Host "receive completed"
source share