I have the following code which I thought would allow me to catch an error and instead of generating the error write out "An Error Occurred".
Unfortunately, it still shows the error "Failed to restart the computer: Access is denied" instead.
I know why this is happening but I want to be able to catch the error and reformat it. What am I doing wrong?
try {
Restart-Computer -ComputerName MFG-KY-PC74 -Force
} catch {
Write-Host "An Error Occurred"
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…