am trying to add log to deletion of folder.
Basically, I want to delete a folder "C:\ABC" from around 15 servers.
Note that only a single path "C:\ABC" needs to be deleted from the servers.
I need output generated into a log file for this deletion of folders.
for eg,
Server1--- Folder deleted
Server2--- Folder doesnot exist
,etc
So far, I have come up with the below script using try catch method but it doesnot do the job:
Try { gc C:\servers.txt | % { Remove-Item -force "C:\ABC" -Recurse -EA stop } }
Catch { Write "Error: delete-item: $_" >> C:\Desktop\logfile.log}
Can onlyone please help with this ? Any other approach would also do, like putting paths in form of \\server1\c$\ABC"
Many thanks