PowerShell offers numerous ways to connect to SMB file shares. Here are three different approaches:
# adjust path to point to your file share
$UNCPath = '\\server\share'
net use * $UNCPath
New-PSDrive -Name y -PSProvider FileSystem -Root $UNCPath -Persist
New-SmbMapping -LocalPath 'x:' -RemotePath $UNCPath
Net.exe is the most versatile approach and available in all PowerShell versions. By providing a “*”, it automatically picks the next available drive letter.
New-PSDrive supports SMB shares beginning in PowerShell 3. New-SmbMapping requires the SmbShare module and seems to be a bit buggy at this time: the drive shows in Windows Explorer only after a reboot.
ReTweet this Tip!