$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 # Syntax check via parsing the content string $parseErrors = $null [System.Management.Automation.Language.Parser]::ParseInput($content, [ref]$null, [ref]$parseErrors) if ($parseErrors.Count -eq 0) { Write-Output "[OK] Script parses OK - no syntax errors" } else { foreach ($err in $parseErrors) { Write-Output "[ERROR] PARSE ERROR: $($err.Message) at line $($err.Extent.StartLineNumber)" } } # Count total lines $lineCount = ($content -split "`n").Count Write-Output "Total lines: $lineCount" Remove-PSDrive -Name AD2 -ErrorAction SilentlyContinue } catch { Write-Output "ERROR: $_" }