I'm creating a script to access a shared network folder. Sample code looks like this:
[CmdletBinding()]
Param (
[string]$SharedFolder,
[ValidateScript({ Test-NetConnection $_ -InformationLevel Quiet })]
[string]$Hostname
)
[string]$UNCPath = "\\" + $Hostname + "\" + $SharedFolder
# Do stuff
Get-ChildItem $UNCPath # OK
My question is about the $UNCPath
variable. Is there a cleaner, better way to accessing the share? Gluing the path together as a string looks ugly.
Is there a better way to access a UNC path using PowerShell?