I am trying to move certain files from c:\ on a list of servers to a central location. I have 2 problems.
Apparently I don’t have access to all of them (and I’m not sure which ones). I tried to use write-output but couldn’t get the server name.
Some of the files are still being written to and are locked. (ideally I would just skip those. I tried to use try / catch but couldn’t get the syntax to work. Here is my code:
$file = import-csv -LiteralPath "F:\auditFilesFromLocalServers\auditserverList.csv"
foreach($i in $file)
{
If (-not (Move-Item -Path "\\$($i.name)\c`$\auditLogs\*.sqlaudit" -Destination "\\myCentralServer\F`$\auditFilesFromLocalServers" ))
{
Throw "Folder Access Denied" # and this causes NONE of the servers to transfer files.
}
}