I am trying to back up a network share to an USB drive, while archiving the data. To do this, I'm calling 7-zip archiver (actually it doesn't matter which archiver I use) like this:
new-psdrive -name O -psprovider filesystem -root '\\kapital-dc01\disk_o' -credential $cred
$arclog=(. 'c:\program files\7-zip\7z.exe' a -bb1 -bd -bse1 -mmt6 -r -v1200m "f:\disk_o\disk_o-$timestamp.7z" 'o:\')
7-zip, however, reports a "file not found" error while trying to get data from O:. In Powershell I am able to dir o:\
without any problem. This script is run as a job via Task Manager as SYSTEM
account. What should I use to start 7-zip with access to attached network drive?
You need to use the -Persist
switch for New-PSDrive
to make the drive available for the windows session and not just the PowerShell session.
You can use the Persist parameter of New-PSDrive to create Windows mapped network drives. Unlike temporary Windows PowerShell drives, Windows mapped network drives are not session-specific. They are saved in Windows and they can be managed by using standard Windows tools, such as File Explorer and Net Use.
Source: MSDN