sharepoint - PowerShell 2.0 Network Path not found when creating drive and copying files -
the script works several days, , email message saying failed because "the network path not found".
when run manually works fine, it's hard find problem.
how keep dropping/losing network path? improvements or tips welcome.
i have written script create new folder on shared drive in order backup accounting logs sharepoint. have script deletes of these folders older 30 days.
- the script create folder today's date on shared drive \sfserverspb4\accounting.
- create drive random drive letter between 'd' , 'z' not in use.
- point drive sharepoint path \intranet.mycompany.com\dept
- copy files, folders, sub-folders sharepoint path accounting shared folder created today.
- remove created drive when done.
this first powershell script.
thank you!
#copy po logs sharepoint (intranet.mycompany.com) sfserverspb4\accounting try { write-host 'creating new folder' -fore black -back yellow $today_folder = new-item -itemtype directory -path "\\sfserverspb4\accounting\backups\po_log_backups\$((get-date).tostring('yyyymmdd'))" -ea stop write-host 'copying files...' -fore white -back blue $drive = ls function:[d-z]: -n | ?{ !(test-path $_) } | random write-host "the drive $drive" -fore green net use $drive \\intranet.mycompany.com\dept /user:'corp\spadmin' 'spadminpassword' copy-item -path $drive\finance\shared` documents\po` logs\* -recurse -destination $today_folder -erroraction stop net use $drive /delete # disconnecting intranet.mycompany.com } # if there's error, stop, , send email catch { write-host 'error in function' -fore white -back red $errormessage = $_.exception.message $faileditem = $_.exception.itemname send-mailmessage -from itdept@mycompany.com -to myself@mycompany.com -smtpserver "mail.prxy.com" -subject "the script copy of po logs on server myserver failed!" -body "server myserver scheduled task 'copy po logs' failed. $faileditem. error message was: '$errormessage'" } { write-host 'all done.' }
Comments
Post a Comment