Skip to content

Instantly share code, notes, and snippets.

@davewilson
Last active February 10, 2017 23:48

Revisions

  1. davewilson renamed this gist Jun 25, 2014. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions Mount-CommonShare.ps1 → CommonShare.ps1
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,19 @@ function Mount-CommonShare
    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"
    }
  2. davewilson renamed this gist Jun 25, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. davewilson created this gist Jun 25, 2014.
    34 changes: 34 additions & 0 deletions MapDrives.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    <#
    .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
    }
    }