1

I'm attempting to run sfc.exe /scannow on a remote computer using PowerShell's Start-Process, but I'm unable to confirm whether the process starts on the remote machine. When I check for any sfc processes using Get-Process sfc, I don't see any processes running. How can I effectively start sfc.exe /scannow on a remote machine using Start-Process?

Here's the PowerShell code I'm using:

$remoteComputer = "RemoteComputerName"

$scriptBlock = {
    Start-Process -FilePath "C:\windows\system32\sfc.exe" -ArgumentList "/scannow" -NoNewWindow -Wait
}

Invoke-Command -ComputerName $remoteComputer -ScriptBlock $scriptBlock

Update: If I start it like this it works, but do I do it with Start-Process?

Invoke-Command -ComputerName $remoteComputer -ScriptBlock {& $(${env:Windir} + "\System32\SFC.EXE") "/scannow"}
8
  • Why are you using Start-Process? It sounds like simply running sfc.exe /scannow directly might solve your problem (or at least reveal why the process dies too quickly) Commented Jul 17, 2024 at 12:04
  • @MathiasR.Jessen I want to "start-process -nonewwindow" so I can start "invoke-command -asjob" on multiple computers and then check if the tasks are complited with "get-job -IncludeChildJob" Commented Jul 17, 2024 at 12:07
  • I don't think Start-Process will make a difference here. Try changing it to just sfc.exe /scannow, run it and see what happens :) Commented Jul 17, 2024 at 12:09
  • Okay, so it works when you just run it directly. Why do you still want to use Start-Process then? What change in behavior are you hoping to get from using Start-Process instead? Commented Jul 17, 2024 at 12:14
  • @MathiasR.Jessen Invoke-Command -ComputerName $remoteComputer -ScriptBlock {SFC.EXE /scannow} I ckecked it doesn't create a process and yes, Start-Process with -nonewwindow param suppose to make a difference Commented Jul 17, 2024 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.