Question

How can I change the path in result using mapped drive instead of true path? Now I got something like \\server\data\work\.... I would like to see it in lets say K:\work\.... I can't use mapped drive path for variable because it does not work with task scheduler....

Get-ChildItem -Recurse $source -Filter *.prt | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-6)} | sort LastWriteTime -descending | select name,LastWriteTime,Directory | convertto-html -head $a -body "<H2>FILES LIST FOR PAST 7 DAYS</H2>" | out-file $output\result.htm
Was it helpful?

Solution

The mapped drive letter should work as long as you're running the Powershell script as a user who has the drive mapped. Otherwise, you need to use New-PSDrive to map the drive for the session.

New-PSDrive –Name K –PSProvider FileSystem –Root "\\server\data"

OTHER TIPS

Try creating a PSDrive at the start of your script. Make sure that the account running the script(through task scheduler) has the required rights on the share.

New-PSDrive –Name "K" –PSProvider FileSystem –Root "\\server\data"
#.... something something, creating $output variable etc. 
Get-ChildItem -Recurse $source -Filter *.prt | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-6)} | sort LastWriteTime -descending | select name,LastWriteTime,Directory | convertto-html -head $a -body "<H2>FILES LIST FOR PAST 7 DAYS</H2>" | out-file $output\result.htm
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top