$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 $content = Get-Content "AD2:\Shares\test\scripts\Sync-FromNAS.ps1" -Raw $tokens = $null; $parseErrors = $null [void][System.Management.Automation.Language.Parser]::ParseInput($content, [ref]$tokens, [ref]$parseErrors) Write-Output "Parse errors: $($parseErrors.Count)" if ($parseErrors.Count -gt 0) { $parseErrors | ForEach-Object { Write-Output " $_" } } else { Write-Output "[OK] No syntax errors detected" } Remove-PSDrive -Name AD2 -ErrorAction SilentlyContinue