I have a small script that copies files to a list of remote machines. In this script I use:
Copy-Item "$AppLocation$AppName" -destination "\$MachineNamec$" -force
This can throw various types of errors. If this throws an error, I want to log the error to a file and then continue. My question is that I d like to know what would be the right way to find out if the Copy-Item command was successful.
Next question is related:
psexec \$MachineName -u $RemoteLogin -p $Remotepassword -s -i -d C:$AppName
What would be a good way to find out how this command executed? I get a message in the console that it exited with 0 but I have no idea how I could get the return code into a local variable.
I can also use this:
(Get-WMIObject -ComputerName $MachineName -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install("C:$AppName","","false")
which works fine, but still, no idea how to find out if it succeeded unless I read the output.
Thanks!