Skip to content

Instantly share code, notes, and snippets.

@davewilson
Last active February 10, 2017 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davewilson/c39705fb983525bdea76 to your computer and use it in GitHub Desktop.
Save davewilson/c39705fb983525bdea76 to your computer and use it in GitHub Desktop.
Mounts and Dismounts commonly used network shares
<#
.Synopsis
Maps commonly used network shares
.DESCRIPTION
Maps drives for commonly used network shares. Username parameter will map the drives as a specific user
.EXAMPLE
Mount-CommonShare
.EXAMPLE
Mount-CommonShare -Username stcxyz
#>
function Mount-CommonShare
{
[CmdletBinding()]
[OutputType([int])]
Param
(
[Parameter(ValueFromPipelineByPropertyName=$true,
Position=0)]
$Username
)
if ($Username -eq $null)
{
New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server1\share" -Persist -Scope global
New-PSDrive -Name "Y" -PSProvider FileSystem -Root "\\server2\share" -Persist -Scope global
New-PSDrive -Name "X" -PSProvider FileSystem -Root "\\server3\share" -Persist -Scope global
}
else
{
New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server1\share" -Persist -Scope global -Credential $Username
New-PSDrive -Name "Y" -PSProvider FileSystem -Root "\\server2\share" -Persist -Scope global -Credential $Username
New-PSDrive -Name "X" -PSProvider FileSystem -Root "\\server3\share" -Persist -Scope global -Credential $Username
}
}
<#
.Synopsis
Removes mapped network shares created with Mount-CommonShare.
.DESCRIPTION
Removes mapped network shares created with Mount-CommonShare.
.EXAMPLE
Dismount-CommonShare
#>
function Dismount-CommonShare
{
Remove-PSDrive -Name "X"
Remove-PSDrive -Name "Y"
Remove-PSDrive -Name "Z"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment