Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,12 @@ protected override void ProcessRecord()
ThrowTerminatingError(er);
}

// Trimming forward and backward slash for FileSystem provider when -Persist is used.
if (Persist && provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
Root = Root.TrimEnd('/', '\\');
}

// Create the new drive
PSDriveInfo newDrive =
new PSDriveInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" {
Context "Validate New-PSDrive Cmdlet with -Persist switch." {
BeforeEach {
$UsedDrives = Get-PSDrive | Select-Object -ExpandProperty Name
$PSDriveName = 'D'..'Z' | Where-Object -FilterScript {$_ -notin $UsedDrives} | Get-Random
$RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))"
}

AfterEach {
Remove-PSDrive -Name $PSDriveName -Force -ErrorAction SilentlyContinue
}

It "Should not throw exception for persistent PSDrive creation." -Skip:(-not $IsWindows) {
{ New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Not -Throw
}

it "Should throw exception if root is not a remote share." -Skip:(-not $IsWindows) {
{ New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root "TestDrive:\" -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveRootNotNetworkPath'
}

it "Should throw exception if PSDrive is not a drive letter supported by operating system." -Skip:(-not $IsWindows) {
$PSDriveName = 'AB'
{ New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence'
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Basic Alias Provider Tests" -Tags "CI" {
Context "Validate basic PSDrive Cmdlets" {
BeforeAll {
Expand Down