Skip to content

Instantly share code, notes, and snippets.

@moddingg33k
Last active August 16, 2020 19:08
Show Gist options
  • Save moddingg33k/ee9d5fa6f76832ee9bf695ce0e27d80e to your computer and use it in GitHub Desktop.
Save moddingg33k/ee9d5fa6f76832ee9bf695ce0e27d80e to your computer and use it in GitHub Desktop.
Methods to mount a SMB share by PowerShell
$PsDriveParams = @{
Name = 'Z';
Root = '\\<fqdn>\<path>';
Credential = (Get-Credential)
}
New-PSDrive @PsDriveParams -PSProvider FileSystem -Scope Global -Persist
$SmbMappingParams = @{
LocalPath = 'Z:';
RemotePath = '\\<fqdn>\<path>';
UserName = '<NetbiosDomainName>\<samAccountName>';
Password = 'P@ssw0rd'
}
New-SmbMapping @SmbMappingParams -Persistent $True -SaveCredentials
$NetShare = New-Object -ComObject WScript.Network
$NetShare.MapNetworkDrive(strLocalDrive, strRemoteShare, [persistent], [strUser], [strPassword])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment