Trying to verify that a remote server can access CIF share

26 views Asked by At

I am trying to verify that a remote server has access to a CIF share

$RemoteMoteMachineName = 'ServerName'
$ShareToAccess='\\Share\Level1Folder'
$RemoteSession = New-PSSession -ComputerName $RemoteMachineName
$RemoteTest = Invoke-Command -Session $RemoteSession -ScriptBlock {Test-Path -PATH -ArgumentList $using:ShareToAccess}

If I run the above commands manually with hard coded values, it works.

If I try to use the variables I receive Test-Path: A positional parameter cannot be found that accepts argument '\Share\Level1\Folder'

Ideas?

1

There are 1 answers

0
TallKewlOnez On

Resolved, used instead (create a fake drive and remove if successful:

$RemoteTest = Invoke-Command -Session $RemoteSession -ScriptBlock {New-PSDrive -Name TestName -PSProvider FileSystem -Root  $using:ShareToAccess}

If ($RemoteTest){
  Write-Host "Remote test pass $RemoteMachine to $ShareToAccess"
  Invoke-Command -Session $RemoteSession -ScriptBlock {Remove-PSDrive -Name TestName } 
Else {Write-Host "Share access Fail"}