$pass = ConvertTo-SecureString ("Paper123" + [char]33 + "@#") -AsPlainText -Force $cred = New-Object PSCredential("INTRANET\sysadmin", $pass) $uncRoot = "\\192.168.0.6\C$" New-PSDrive -Name AD2 -PSProvider FileSystem -Root $uncRoot -Credential $cred -ErrorAction Stop | Out-Null # First, do a dry run to see what files are stranded on the NAS Write-Output "=== DRY RUN: Bulk sync with 86400 minute window (60 days) ===" $dryRunOutput = & powershell -NoProfile -ExecutionPolicy Bypass -Command { # We cannot run the script directly on AD2 from here, so we will invoke it remotely } # Actually we need to run this ON AD2. Lets check if we can invoke it via the mapped drive. # The script needs to run locally on AD2 (it calls SCP/SSH). We need WinRM or SSH for that. # Since WinRM is blocked from this machine, lets try another approach. # Check: can we SSH to AD2 with the key from this machine? Write-Output "=== Testing SSH to NAS directly from this machine ===" Remove-PSDrive -Name AD2 -ErrorAction SilentlyContinue