diff --git a/help/Save-PSResource.md b/help/Save-PSResource.md index e98cf87b3..162f0011c 100644 --- a/help/Save-PSResource.md +++ b/help/Save-PSResource.md @@ -192,15 +192,14 @@ Accept wildcard characters: False ### -Path -Specifies the path to save the resource to. If no path is provided, the resource is saved to the -current location. +Specifies the path to save the resource to. ```yaml Type: System.String Parameter Sets: (All) Aliases: -Required: False +Required: True Position: Named Default value: None Accept pipeline input: False diff --git a/src/code/SavePSResource.cs b/src/code/SavePSResource.cs index 9c92a261f..0c33b3a94 100644 --- a/src/code/SavePSResource.cs +++ b/src/code/SavePSResource.cs @@ -81,7 +81,7 @@ public sealed class SavePSResource : PSCmdlet /// /// The destination where the resource is to be installed. Works for all resource types. /// - [Parameter] + [Parameter(Mandatory = true)] [ValidateNotNullOrEmpty] public string Path { @@ -90,21 +90,13 @@ public string Path set { - string resolvedPath = string.Empty; - if (string.IsNullOrEmpty(value)) - { - // If the user does not specify a path to save to, use the user's current working directory - resolvedPath = SessionState.Path.GetResolvedPSPathFromPSPath(SessionState.Path.CurrentFileSystemLocation.Path).First().Path; - } - else { - resolvedPath = SessionState.Path.GetResolvedPSPathFromPSPath(value).First().Path; - } + if (WildcardPattern.ContainsWildcardCharacters(value)) + { + throw new PSArgumentException("Wildcard characters are not allowed in the path."); + } - // Path where resource is saved must be a directory - if (Directory.Exists(resolvedPath)) - { - _path = resolvedPath; - } + // This will throw if path cannot be resolved + _path = SessionState.Path.GetResolvedPSPathFromPSPath(value).First().Path; } } private string _path; diff --git a/test/SavePSResource.Tests.ps1 b/test/SavePSResource.Tests.ps1 index 3366cdec5..d4300b66e 100644 --- a/test/SavePSResource.Tests.ps1 +++ b/test/SavePSResource.Tests.ps1 @@ -280,7 +280,7 @@ Describe 'Test Save-PSResource for PSResources' { # Save script that is not signed # Should throw It "Save script that is not signed" -Skip:(!(Get-IsWindows)) { - { Save-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" + { Save-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -Path $SaveDir} | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } <#