So I’m trying to create a script to run sfc,chkdsk, and dism as a job on the computer. It’s intended to be run on a computer that would be signed in as a standard user so that I can run this at the end of the day when I need to and check the reports after
I think I’ve got the majority of the script in place already but running into issues when it gets to runing the actual utilities. It tells me that admin privelleges are needed please run in an elevated prompt.
At the time of testing I was signed in as a local admin on the computer and simply testing out the commands in an admin session of PS so there should be no permission issues. If I remote the -credential parameter from the start-job cmd then the script runs (as I would expect, given that Im signed in as admin).
Left the commands attached, open to any help/suggestions/opinions. End goal is to be able to run this by double clicking and forgetting about it until the next day, I don’t want to input passwords at all and would like for it to be run by a non-admin computer account.
######## *omitted $user and $pass lines
$Cred= New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Pass $Path= 'C:\JobLogs' $Date= get-date -format "dd MM yyyy mm ss" $LogFile= "C:\JobLogs\ResultsFrom$date.txt" start-job -name DiskCheck -ScriptBlock { CHKDSK C: } -Credential $cred start-job -name SFC -ScriptBlock { sfc /scannow } -Credential $cred start-job -name DISM -ScriptBlock { DISM /Online /Cleanup-Image /RestoreHealth } -Credential $cred if (test-path $path) { write-host "`$Path was found, exporting logs to $Path" } else { new-item C:\JobLogs -itemtype directory; Write-Host "$Path not found, creating $Path and exporting logs" } wait-job -name DiskCheck,SFC,DISM | receive-job | out-file -FilePath $LogFile