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 @@ -1266,6 +1266,7 @@ public string Description
[Parameter(ValueFromPipelineByPropertyName = true)]
public string Scope { get; set; }

#if !UNIX
/// <summary>
/// Gets or sets the Persist Switch parameter.
/// If this switch parameter is set then the created PSDrive
Expand All @@ -1278,7 +1279,7 @@ public SwitchParameter Persist
set { _persist = value; }
}
private bool _persist = false;

#endif
/// <summary>
/// Gets the dynamic parameters for the new-psdrive cmdlet.
/// </summary>
Expand Down Expand Up @@ -1368,6 +1369,7 @@ protected override void ProcessRecord()

if (ShouldProcess(resource, action))
{
#if !UNIX
// -Persist switch parameter is supported only for FileSystem provider.
if (Persist && !provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -1384,7 +1386,17 @@ protected override void ProcessRecord()
Description,
Credential,
Persist);

#else
// Create the new drive
PSDriveInfo newDrive =
new PSDriveInfo(
Name,
provider,
Root,
Description,
Credential,
persist: false);
#endif
try
{
SessionState.Drive.New(newDrive, Scope, CmdletProviderContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Describe "Extended Alias Provider Tests" -Tags "Feature" {
$localDrive = Get-PSDrive -Name $psDriveName -Scope Local
$localDrive.Name | Should -BeExactly $psDriveName
}

It "Verify '-Persist' parameter is not available on UNIX" -Skip:($IsWindows) {
{ New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Persist -Description "Test PSDrive to remove" } | Should -Throw -ErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewPSDriveCommand"
}
}

Context "Valdiate Get-PSDrive Cmdlet Parameters" {
Expand Down