Hello, I’m writing a script to test for a path on a remote computer and if that path is found take a certain action. The problem I’m having is test-path returns True regardless. Below is a sample of my script. Any idea why I get True but if I manually remote to the computer and run the same test-path command it returns false?
Function Add-Tns1 { [CmdletBinding()] param( [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string[]]$Computername ) Begin{} Process{ $path = 'c:\oracle11' $test = test-path -path $path $ses foreach ($cpu in $Computername) { Try { $ses = New-PSSession $cpu -ErrorAction Stop invoke-command -Session $ses -ScriptBlock { $test Write-Debug "$test" } } Catch { Write-output "client unavailable" break } } } }