How do I fix error: Test-NetConnection : A positional parameter cannot be found that accepts argument 'if'.

VMS 0 Reputation points
2024-05-24T18:05:15.3533333+00:00

I am trying to mount a File share using the Active Directory or Microsoft Entra auth method. I have the method enabled, I have the PC that I am trying to mount the file share to is enrolled to Intune and the user logged in under their Microsoft Entra ID, and am using the PowerShell script generated by the "Connect" window. Here is the script I am using (with the file share info redacted):

$connectTestResult = Test-NetConnection -ComputerName <<file_share_name>>.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
 # Mount the drive
 New-PSDrive -Name M -PSProvider FileSystem -Root "\\<<file_share_name>>.file.core.windows.net\u-brandonp" -Persist
} else {
 Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."
}

However, when I try to run it, I am getting this error message:

Screenshot 2024-05-23 at 2.45.45 PM

Any help on how to resolve this would be great!

Thanks!

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,833 questions
{count} votes