$ErrorActionPreference = "Stop" $pass = ConvertTo-SecureString ("Paper123" + [char]33 + "@#") -AsPlainText -Force $cred = New-Object PSCredential("INTRANET\sysadmin", $pass) $uncRoot = "\\192.168.0.6\C$" try { New-PSDrive -Name AD2 -PSProvider FileSystem -Root $uncRoot -Credential $cred -ErrorAction Stop | Out-Null $scriptPath = "AD2:\Shares\test\scripts\Sync-FromNAS.ps1" $content = Get-Content $scriptPath -Raw # Show the Copy-FromNAS function $lines = $content -split "`n" $inFunc = $false $funcName = "" foreach ($line in $lines) { if ($line -match "^function (Copy-FromNAS|Copy-ToNAS|Invoke-NASCommand)") { $inFunc = $true $funcName = $Matches[1] Write-Output "=== $funcName ===" } if ($inFunc) { Write-Output $line.TrimEnd() if ($line.Trim() -eq "}" -and $funcName) { $inFunc = $false Write-Output "" } } } Remove-PSDrive -Name AD2 -ErrorAction SilentlyContinue } catch { Write-Output "ERROR: $_" }