Aug 01 2023 08:16 AM
I am getting the desired output from the below script manually through PowerShell ISE. But the same script is not running through Task Scheduler. It's showing as completed (in Task Scheduler History) but it did not copy file from "\\MICROSOFT.COM\AD$" to "F:\Reports" folder.
$SourcePath = "\\SERVER1.MICROSOFT.COM\AD$"
$password = Get-Content F:\Reports\ImpCred\encrypted_passwd.txt | ConvertTo-SecureString
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "MICROSOFT\SVC_REPORT", $password
New-PSDrive -Persist -Name "U" -Root $SourcePath -PSProvider "FileSystem" -Credential $creds
Copy-Item "U:\ADReport__$((Get-Date).ToString('dddd')).htm" -Destination "F:\Reports" -ErrorAction SilentlyContinue
Remove-PSDrive U
Aug 01 2023 02:20 PM
Aug 01 2023 10:34 PM
Aug 03 2023 03:50 AM