if($filecheck -eq $True) {
Write-Host “All files were found, hooray!”
} else { ## If $fileCheck is a boolean false (at least one file does not exist)
Write-Host “Files are missing.”
}
Before we proceed - could you please go back, edit your question and format your code as code? This way it is hard to distinguish between plain text and code.
You should try to make it easy for people willing to help you.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
How can I add the error handling after that script would tell me if the result successful or not? I try exist $LASTEXISTCODE end of the script but didn’t provide any result. Thank you
What you’re asking for is not error handling - it is confirmation.
Error handling in PowerShell is done with a try catch block. Here you can read more about:
You’d basicall trust the command to do its job until you catch an error.
If you want to have a confirmation you can use Test-Path after you renamed the files and collect its output the way you want. Here you can read more about:
And why should there be an error then? If there are no “.txt” files Rename-Item has nothing to do. So there will be no error.
Try to rename an Office file while you have it opened in Office. Then you will very likely see an error. But I suspect you will not be satisfied with it anyway.
And please do not post images of code or error messages or console output. Instead post the plain text and format it as code.
Thanks.