diff --git a/v3prototype/Find-PSResource.ps1 b/v3prototype/Find-PSResource.ps1 new file mode 100644 index 00000000..e3c24503 --- /dev/null +++ b/v3prototype/Find-PSResource.ps1 @@ -0,0 +1,182 @@ +# Replaces: Find-Command, Find-DscResource, Find-Module, Find-RoleCapability, Find-Script +# Parameter Sets: ResourceParameterSet, PackageParameterSet, ScriptParameterSet + +# Find-Command returns an object with properties: Name, Version, ModuleName, Repository +# Find-DSCResource returns an object with properties: Name, Version, ModuleName, Repository +# Find-RoleCapability returns an object with properties: Name, Version, ModuleName, Repository + +# Find-Module returns an object with properties: Version, Name, Repository, Description +# Find-Script returns an object with properties: Version, Name, Repository, Description + +function Find-PSResource { + [OutputType([PSCustomObject[]])] + [Cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies the name of the resource to be searched for. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0)] + [ValidateNotNullOrEmpty()] + [string[]] + $Name, + + # Specifies the type of the resource being searched. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateSet('Module', 'Script', 'DscResource', 'RoleCapability', 'Command')] + [string[]] + $Type, + + # Specifies the module name that contains the resource. + # Resources that use this param: Command, DSCResource, RoleCapability. + [Parameter(ParameterSetName = "ResourceParameterSet")] + [ValidateNotNullOrEmpty()] + [string] + $ModuleName, + + # Specifies the minimum version of the resource to include in results (cannot use this parameter with the RequiredVersion or AllVersions parameters). + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $MinimumVersion, + + # Specifies the maximum version of the resource to include in results (cannot use this parameter with the RequiredVersion or AllVersions parameters). + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $MaximumVersion, + + # Specifies the required version of the resource to include in results (cannot use this parameter with the MinimumVersion, MaximumVersion, or AllVersions parameters). + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $RequiredVersion, + + # Displays each of a resource's available versions (cannot use this parameter with the MinimumVersion, MaximumVersion, or RequiredVersion parameters). + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter()] + [switch] + $AllVersions, + + # Includes resources marked as a prerelease. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter()] + [switch] + $Prerelease, + + # Specifies tags that categorize modules in a repository. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter()] + [ValidateNotNull()] + [string[]] + $Tag, + + # Finds resources based on ModuleName, Description, and Tag properties. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter()] + [ValidateNotNull()] + [string] + $Filter, + + # Specifies a proxy server for the request, rather than a direct connection to the internet resource. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [Uri] + $Proxy, + + # Specifies a user account that has permission to use the proxy server that is specified by the Proxy parameter. + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $ProxyCredential, + + # Specifies the repository to search within (default is all repositories). + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. + [Parameter()] + [ValidateNotNullOrEmpty()] + [string[]] + $Repository, + + # Specifies a user account that has rights to find a resource from a specific repository. + # Resources that use this param: Package, Script. + [Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = "PackageParameterSet")] + [Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = "ScriptParameterSet")] + [PSCredential] + $Credential, + + # Specifies to include all modules that are dependent upon the module specified in the Name parameter. + # Resources that use this param: Package, Script. + [Parameter(ParameterSetName = "PackageParameterSet")] + [Parameter(ParameterSetName = "ScriptParameterSet")] + [switch] + $IncludeDependencies, + + # Returns only those modules that include specific kinds of PowerShell functionality. For example, you might only want to find modules that include DSCResource. + # The acceptable values for this parameter are as follows: + # Module: DscResource, Cmdlet, Function, RoleCapability; + # Scripts: Function, Workflow; + # Resources that use this param: Package, Script. + [Parameter(ParameterSetName = "PackageParameterSet")] + [Parameter(ParameterSetName = "ScriptParameterSet")] + [ValidateNotNull()] + [ValidateSet('DscResource', 'Cmdlet', 'Function', 'RoleCapability', 'Workflow')] + [string[]] + $Includes, + + # Specifies the name of the DSC resources contained within a module (per PowerShell conventions, performs an OR search when you provide multiple arguments). + # Resources that use this param: Package. + [Parameter(ParameterSetName = "PackageParameterSet")] + [ValidateNotNull()] + [string[]] + $DscResource, + + # Specifies the name of the role capabilities contained within a module (per PowerShell conventions, performs an OR search when you provide multiple arguments). + # Resources that use this param: Package. + [Parameter(ParameterSetName = "PackageParameterSet")] + [ValidateNotNull()] + [string[]] + $RoleCapability, + + # Specifies commands to find in modules (command can be a function or workflow). + # Resources that use this param: Package, Script. + [Parameter(ParameterSetName = "PackageParameterSet")] + [Parameter(ParameterSetName = "ScriptParameterSet")] + [ValidateNotNull()] + [string[]] + $Command + + ) + + begin { + # For each repository, if local cache does not exist then Update-PSResourceCache + } + process { + + # Returning the array of resources + $foundResources + + foreach ($n in $name) { + + if ($pscmdlet.ShouldProcess($n)) { + + $PSResource = [PSCustomObject] @{ + Name = $Name + Version = "placeholder-for-module-version" + Type = $Type + Description = "placeholder-for-description" + } + + $foundResources += $PSResource + } + } + + return $foundResources + } + end { } +} diff --git a/v3prototype/Find-PSResourceValidations.ps1 b/v3prototype/Find-PSResourceValidations.ps1 new file mode 100644 index 00000000..6f6e198e --- /dev/null +++ b/v3prototype/Find-PSResourceValidations.ps1 @@ -0,0 +1,490 @@ +####################### +### Find-PSResource ### +####################### + +### Find command ### +# Should find the command 'TestCommand' +Find-PSResource -name 'TestCommand' + +# Should find the command 'TestCommand' +Find-PSResource 'TestCommand' + +# Should find the command 'TestCommand' +Find-PSResource 'TestCommand' -Type 'Command' + +# Should find the command 'TestCommand' +Find-PSResource 'TestCommand' -Type 'Command', 'DscResource', 'RoleCapability', 'Module', 'Script' + +# Should find the command 'TestCommand' from the module 'TestCommandModuleName' +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' + +# Should find the command 'TestCommand' from the latest, non-prerelease module 'TestCommandModuleName' that has a minimum version 1.5.0 +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' -MinimumVersion '1.5.0' + +# Should find the command 'TestCommand' from the latest, non-prerelease module 'TestCommandModuleName' that has a maximum version of 1.5.0 +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' -MaximumVersion '1.5.0' + +# Should find the command 'TestCommand' from the latest, non-prerelease module 'TestCommandModuleName' that has a minimum version of 1.0.0 and a maximum version of 2.0.0 +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should find the command 'TestCommand' from the module 'TestCommandModuleName' that is exactly version 1.5.0 (non-prerelease) +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' -RequiredVersion '1.5.0' + +# Should find the command 'TestCommand' from all non-prerelease versions of the module 'TestCommandModuleName' +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' -AllVersions + +# Should find the command 'TestCommand' from the latest verions of the module 'TestCommandModuleName', including prerelease versions +Find-PSResource 'TestCommand' -ModuleName 'TestCommandModuleName' -Prerelease + +# Should find the command 'TestCommand' from a resource with the tags 'Tag1', 'Tag2', 'Tag3' +Find-PSResource 'TestCommand' -Tag 'Tag1', 'Tag2', 'Tag3' + +# Should find the command 'TestCommand' from a resource that has 'Test' in either the module name or description +Find-PSResource 'TestCommand' -Filter 'Test' + +# Should find the command 'TestCommand' from one of the specified repositories +Find-PSResource 'TestCommand' -Repository 'Repository1', 'Repository2' + +# Should NOT find the command 'TestCommand' +Find-PSResource 'TestCommand' -Type 'TestDscResource' + + + +### Find DSC resource ### +# Should find the DSC resource 'TestDscResource' +Find-PSResource -name 'TestDscResource' + +# Should find the DSC resource 'TestDscResource' +Find-PSResource 'TestDscResource' + +# Should find the DSC resource 'TestDscResource' +Find-PSResource 'TestDscResource' -Type 'DscResource' + +# Should find the DSC resource 'TestDscResource' +Find-PSResource 'TestDscResource' -Type 'Command', 'DscResource', 'RoleCapability', 'Module', 'Script' + +# Should find the DSC resource 'TestDscResource' that is contained within the module 'TestDscResourceModuleName' +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' + +# Should find the DSC resource 'TestDscResource' from the latest, non-prerelease module 'TestDscResourceModuleName' that has a minimum version 1.5.0 +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' -MinimumVersion '1.5.0' + +# Should find the DSC resource 'TestDscResource' from the latest, non-prerelease module 'TestDscResourceModuleName' that has a maximum version of 1.5.0 +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' -MaximumVersion '1.5.0' + +# Should find the DSC resource 'TestDscResource' from the latest, non-prelease module 'TestDscResourceModuleName' that has a minimum version of 1.0.0 and a maximum version of 2.0.0 +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should find the DSC resource 'TestDscResource' from the module 'TestDscResourceModuleName' that has a required version of 1.5.0 (non-prerelease) +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' -RequiredVersion '1.5.0' + +# Should find the DSC resource 'TestDscResource' from all non-prerelease versions of the module 'TestDscResourceModuleName' +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' -AllVersions + +# Should find the DSC resource 'TestDscResource' from the latest module 'TestDscResourceModuleName', including prerelease versions +Find-PSResource 'TestDscResource' -ModuleName 'TestDscResourceModuleName' -Prerelease + +# Should find the DSC resource 'TestDscResource' from a resource with the tags 'Tag1', 'Tag2', 'Tag3' +Find-PSResource 'TestDscResource' -Tag 'Tag1', 'Tag2', 'Tag3' + +# Should find the DSC resource 'TestDscResource' from a resource that has 'Test' in either the module name or description +Find-PSResource 'TestDscResource' -Filter 'Test' + +# Should find the DSC resource 'TestDscResource' from one of the specified repositories +Find-PSResource 'TestDscResource' -Repository 'Repository1', 'Repository2' + +# Should NOT find the DSC resource 'TestDscResource' +Find-PSResource 'TestDscResource' -Type 'DscResource' + + + +### Find role capability ### +# Should find the role capability 'TestRoleCapability' +Find-PSResource -name 'TestRoleCapability' + +# Should find the role capability 'TestRoleCapability' +Find-PSResource 'TestRoleCapability' + +# Should find the role capability 'TestRoleCapability' +Find-PSResource 'TestRoleCapability' -Type 'DscResource' + +# Should find the role capability 'TestRoleCapability' +Find-PSResource 'TestRoleCapability' -Type 'Command', 'DscResource', 'RoleCapability', 'Module', 'Script' + +# Should find the role capability 'TestRoleCapability' from the module +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' + +# Should find the role capability 'TestRoleCapability' from the latest, non-prerelease module 'TestDscResourceModuleName' that has a minimum version 1.5.0 +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' -MinimumVersion '1.5.0' + +# Should find the role capability 'TestRoleCapability' from the latest, non-prerelease modules with name 'TestDscResourceModuleName' that has a maximum version of 1.5.0 +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' -MaximumVersion '1.5.0' + +# Should find the command 'TestRoleCapability' from the latest, non-prerelease module with name 'TestDscResourceModuleName' that has a minimum version of 1.0.0 and a maximum version of 2.0.0 +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should find the role capability 'TestRoleCapability' from the module 'TestDscResourceModuleName' that has a required version of 1.5.0 (non-prerelease) +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' -RequiredVersion '1.5.0' + +# Should find the role capability 'TestRoleCapability' from all non-prerelease versions of the module 'TestDscResourceModuleName' +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' -AllVersions + +# Should find the role capability 'TestRoleCapability' from the module 'TestDscresourceModuleName', including prerelease versions +Find-PSResource 'TestRoleCapability' -ModuleName 'TestDscResourceModuleName' -Prerelease + +# Should find the role capability 'TestRoleCapability' from a resource with the tags 'Tag1', 'Tag2', 'Tag3' +Find-PSResource 'TestRoleCapability' -Tag 'Tag1', 'Tag2', 'Tag3' + +# Should find the role capability 'TestRoleCapability' from a resource that has 'Test' in either the module name or description +Find-PSResource 'TestRoleCapability' -Filter 'Test' + +# Should find the role capability 'TestRoleCapability' from one of the specified repositories +Find-PSResource 'TestRoleCapability' -Repository 'Repository1', 'Repository2' + +# Should NOT find the role capability 'TestRoleCapability' +Find-PSResource 'TestRoleCapability' -Type 'TestDscResource' + + + +### Find module ### +# Should find the module 'TestModule' +Find-PSResource -name 'TestModule' + +# Should find the module 'TestModule' +Find-PSResource 'TestModule' + +# Should find the module 'TestModule' +Find-PSResource 'TestModule' -Type 'Module' + +# Should find the module 'TestModule' +Find-PSResource 'TestModule' -Type 'Command', 'DscResource', 'RoleCapability', 'Module', 'Script' + +# Should find the non-prerelase module 'TestModule' that has a minimum version of 1.5.0 +Find-PSResource 'TestModule' -MinimumVersion '1.5.0' + +# Should find the non-prerelease module 'TestModule' that has a maximum version of 1.5.0 +Find-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should find the non-prerelease module 'TestModule' that has a minimum version of 1.0.0 and a maximum version of 1.5.0 +Find-PSResource 'TestModule' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should find the latest, non-prerelease scripts 'TestModule' that is exactly version 1.5.0 +Find-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should find all versions of all non-prerelease versions of the module 'TestModule' +Find-PSResource 'TestModule' -AllVersions + +# Should find the lastest, non-prerelease version of the module 'TestModule', including prerelease versions +Find-PSResource 'TestModule' -Prerelease + +# Should find the module 'TestModule' with the tags 'Tag1', 'Tag2', 'Tag3' +Find-PSResource 'TestModule' -Tag 'Tag1', 'Tag2', 'Tag3' + +# Should find the module 'TestModule' that has 'Test' in either the module name or description +Find-PSResource 'TestModule' -Filter 'Test' + +# Should find the module 'TestModule' from all of the specified repositories +Find-PSResource 'TestModule' -Repository 'Repository1', 'Repository2' + +# Should find the module 'TestModule' and all modules that are dependent upon 'TestModule' +Find-PSResource 'TestModule' -IncludeDependencies + +# Should find the module 'TestModule' that has DSC resources +Find-PSResource 'TestModule' -Includes 'DscResource' + +# Should find the module 'TestModule' that has DSC resources named 'TestDscResource' +Find-PSResource 'TestModule' -DSCResource 'TestDscResource' + +# Should find the module 'TestModule' that has a role capacity named 'TestDscResource' +Find-PSResource 'TestModule' -RoleCapability 'TestRoleCapability' + +# Should find the module 'TestModule' that has a command named 'Test-Command' +Find-PSResource 'TestModule' -Command 'Test-Command' + + + +### Find Script ### +# Should find the script named 'TestScript' +Find-PSResource -name 'TestScript' + +# Should find the script named 'TestScript' +Find-PSResource 'TestScript' + +# Should find the script named 'TestScript' +Find-PSResource 'TestScript' -Type 'Script' + +# Should find the script named 'TestScript' +Find-PSResource 'TestScript' -Type 'Command', 'DscResource', 'RoleCapability', 'Module', 'Script' + +# Should find the latest, non-prerelease script 'TestScript' that has a minimum version of 1.5.0 +Find-PSResource 'TestScript' -MinimumVersion '1.5.0' + +# Should find the latest, non-prerelease script 'TestScript' that have a maximum version of 1.5.0 +Find-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should find the latest, non-prerelease script 'TestScript' that has a minimum version of 1.0.0 and a maximum version of 1.5.0 +Find-PSResource 'TestScript' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should find the latest, non-prerelease scripts 'TestScript' that is exactly version 1.5.0 +Find-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should find all versions of all scripts named 'TestScript', not including prerelease versions +Find-PSResource 'TestScript' -AllVersions + +# Should find the script 'TestScript', including prerelease versions +Find-PSResource 'TestScript' -AllowPrerelease + +# Should find the script 'TestScript' with the tags 'Tag1', 'Tag2', 'Tag3' +Find-PSResource 'TestScript' -Tag 'Tag1', 'Tag2', 'Tag3' + +# Should find the script 'TestScript' that has 'Test' in either the script name or description +Find-PSResource 'TestScript' -Filter 'Test' + +# Should find the script 'TestScript' from all of the specified repositories +Find-PSResource 'TestScript' -Repository 'Repository1', 'Repository2' + +# Should find the script 'TestScript' and all modules that are dependent upon 'TestScript' +Find-PSResource 'TestScript' -IncludeDependencies + +# Should find the script 'TestScript' that has a function named 'TestFunction' +Find-PSResource 'TestScript' -Includes 'TestFunction' + +# Should find the script 'TestScript' that has a command named 'Test-Command' +Find-PSResource 'TestScript' -Command 'Test-Command' + + + +### Find multiple resources ### +# Should find the resources 'TestResource1', 'TestResource2', 'TestResource3' +Find-PSResource -name 'TestResource1', 'TestResource2', 'TestResource3' + +# Should find the resource 'TestResource1', 'TestResource2', 'TestResource3' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' + +# Should find the resources 'TestResource1', 'TestResource2', 'TestResource3' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Type 'Module' + +# Should find the 'TestResource1', 'TestResource2', 'TestResource3' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Type 'Command', 'DscResource', 'RoleCapability', 'Module', 'Script' + +# Should find the latest, non-prerelease modules 'TestResource1', 'TestResource2', 'TestResource3' that have a minimum version of 1.5.0 +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -MinimumVersion '1.5.0' + +# Should find the latest, non-prerelease modules 'TestResource1', 'TestResource2', 'TestResource3' that have a maximum version of 1.5.0 +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -MaximumVersion '1.5.0' + +# Should find the latest, non-prerelease modules 'TestResource1', 'TestResource2', 'TestResource3' that have a minimum version of 1.0.0 and a maximum version of 1.5.0 +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' that are exactly version 1.5.0 +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -RequiredVersion '1.5.0' + +# Should find all non-prerelease versions of the modules 'TestResource1', 'TestResource2', 'TestResource3', not including prerelease versions +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -AllVersions + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3', including prerelease versions +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Prerelease + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' with the tags 'Tag1', 'Tag2', 'Tag3' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Tag 'Tag1', 'Tag2', 'Tag3' + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' that have 'Test' in either the module name or description +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Filter 'Test' + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' from all of the specified repositories +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Repository 'Repository1', 'Repository2' + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' and all modules that are dependent upon 'TestResource1', 'TestResource2', 'TestResource3' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -IncludeDependencies + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' that have DSC resources +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Includes 'DscResource' + +# Should find the modules 'TestResource1', 'TestResource2', 'TestResource3' that have DSC resources named 'TestDscResource' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -DSCResource 'TestDscResource' + +# Should find all the modules named 'TestResource1', 'TestResource2', 'TestResource3' that have a role capacity named 'TestRoleCapacity' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -RoleCapability 'TestRoleCapability' + +# Should find all the modules named 'TestResource1', 'TestResource2', 'TestResource3' that have a command named 'Test-Command' +Find-PSResource 'TestResource1', 'TestResource2', 'TestResource3' -Command 'Test-Command' + + + + + +########################## +### Install-PSResource ### +########################## + +### Installing Modules ### + +# Should install the module 'TestModule' +Install-PSResource 'TestModule' + +# Should install the module 'TestModule' +Install-PSResource -name 'TestModule' + +# Should install the modules 'TestModule1', 'TestModule2', 'TestModule3' +Install-PSResource 'TestModule1', 'TestModule2', 'TestModule3' + +# Should install the latest, non-prerelease version of the module 'TestModule' that is at least 1.5.0 +Install-PSResource 'TestModule' -MinimumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the module 'TestModule' that is at most 1.5.0 +Install-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the module 'TestModule' that is at least version 1.0.0 and at most 2.0.0 +Install-PSResource 'TestModule' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should install version 1.5.0 (non-prerelease) of the module 'TestModule' +Install-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should install the latest verison of 'TestModule', including prerelease versions +Install-PSResource 'TestModule' -Prerelease + +# Should install 'TestModule' from one of the specified repositories (based on repo priority) +Install-PSResource 'TestModule' -Repository 'Repository1', 'Repository2' + +# Should install the module Pester +Install-PSResource -RequiredResources @{ + 'Configuration' = '[1.3.1,2.0)' + 'Pester' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } +} + +# Should install the module Pester +Install-PSResource -RequiredResources ConvertTo-Json ( + @{ + 'Configuration' = '[1.3.1,2.0)' + 'Pester' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } + } +) + +# Should install the required resources in RequiredResource.psd1 +Install-PSResource -RequiredResourcesFile 'RequiredResource.psd1' + +# Should install the required resources in RequiredResource.json +Install-PSResource -RequiredResourcesFile 'RequiredResource.json' + +# Should install the module 'TestModule' to the CurrentUser scope +Install-PSResource 'TestModule' -Scope 'CurrentUser' + +# Should install the module 'TestModule' to the AllUsers scope +Install-PSResource 'TestModule' -Scope 'AllUsers' + +# Should install the module 'TestModule' without prompting warning message regarding installation conflicts +Install-PSResource 'TestModule' -NoClobber + +# Should install the module 'TestModule' without prompting message regarding publisher mismatch +Install-PSResource 'TestModule' -IgnoreDifferentPublisher + +# Should install the module 'TestModule' without prompting message regarding untrusted sources +Install-PSResource 'TestModule' -TrustRepository + +# Should install the module 'TestModule' without prompting message regarding untrusted sources +Install-PSResource 'TestModule' -Force + +# Should reinstall the module 'TestModule' +Install-PSResource 'TestModule' -Reinstall + +#Should install the module 'TestModule' without displaying progress information +Install-PSResource 'TestModule' -Quiet + +#Should install the module 'TestModule' and automatically accept license agreement +Install-PSResource 'TestModule' -AcceptLicense + +#Should install the module 'TestModule' and return the module as an object to the console +Install-PSResource 'TestModule' -PassThru + + + +### Installing Scripts ### ############ + +# Should install the script 'TestScript' +Install-PSResource 'TestScript' + +# Should install the script 'TestScript' +Install-PSResource -name 'TestScript' + +# Should install the scripts 'TestScript1', 'TestScript2', 'TestScript3' +Install-PSResource 'TestScript1', 'TestScript2', 'TestScript3' + +# Should install the latest, non-prerelease version of the script 'TestScript' that is at least 1.5.0 +Install-PSResource 'TestScript' -MinimumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the script 'TestScript' that is at most 1.5.0 +Install-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the script 'TestScript' that is at least version 1.0.0 and at most 2.0.0 +Install-PSResource 'TestScript' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should install version 1.5.0 (non-prerelease) of the script 'TestScript' +Install-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should install the latest verison of 'TestScript', including prerelease versions +Install-PSResource 'TestScript' -Prerelease + +# Should install 'TestScript' from one of the specified repositories (based on repo priority) +Install-PSResource 'TestScript' -Repository 'Repository1', 'Repository2' + +# Should install the script TestScript +Install-PSResource -RequiredResources @{ + 'Configuration' = '[1.3.1,2.0)' + 'TestScript' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } +} + +# Should install the script TestScript +Install-PSResource -RequiredResources ConvertTo-Json ( + @{ + 'Configuration' = '[1.3.1,2.0)' + 'TestScript' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } + } +) + +# Should install the required resources in RequiredResource.psd1 +Install-PSResource -RequiredResourcesFile 'RequiredResource.psd1' + +# Should install the required resources in RequiredResource.json +Install-PSResource -RequiredResourcesFile 'RequiredResource.json' + +# Should install the script 'TestScript' to the CurrentUser scope +Install-PSResource 'TestScript' -Scope 'CurrentUser' + +# Should install the script 'TestScript' to the AllUsers scope +Install-PSResource 'TestScript' -Scope 'AllUsers' + +# Should install the module 'TestModule' without prompting warning message regarding installation conflicts +Install-PSResource 'TestModule' -NoClobber + +# Should install the script 'TestScript' without prompting message regarding publisher mismatch +Install-PSResource 'TestScript' -IgnoreDifferentPublisher + +# Should install the script 'TestScript' without prompting message regarding untrusted sources +Install-PSResource 'TestScript' -TrustRepository + +# Should install the script 'TestScript' without prompting message regarding untrusted sources +Install-PSResource 'TestScript' -Force + +# Should reinstall the script 'TestScript' +Install-PSResource 'TestScript' -Reinstall + +#Should install the script 'TestScript' without displaying progress information +Install-PSResource 'TestScript' -Quiet + +#Should install the script 'TestScript' and automatically accept license agreement +Install-PSResource 'TestScript' -AcceptLicense + +#Should install the script 'TestScript' and return the script as an object to the console +Install-PSResource 'TestScript' -PassThru diff --git a/v3prototype/Get-PSResource.ps1 b/v3prototype/Get-PSResource.ps1 new file mode 100644 index 00000000..b13a5d0a --- /dev/null +++ b/v3prototype/Get-PSResource.ps1 @@ -0,0 +1,83 @@ +function Get-PSResource { + [OutputType([PsCustomObject])] + [cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies the resources to get. + [Parameter(ValueFromPipelineByPropertyName = $true, + Position = 0)] + [ValidateNotNullOrEmpty()] + [String[]] + $Name, + + # Specifies the type of resource to get. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateSet('Module', 'Script', 'Nupkg')] + [string[]] + $Type, + + # Specifies the minimum version of the resource to return (cannot use this parameter with the RequiredVersion or AllVersions parameters). + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $MinimumVersion, + + # Specifies the required version of the resource to return (cannot use this parameter with the MinimumVersion, MaximumVersion, or AllVersions parameters). + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $RequiredVersion, + + # Specifies the maximum version of the resource to return (cannot use this parameter with the RequiredVersion or AllVersions parameters). + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $MaximumVersion, + + # Displays all versions of the resource that have been installed (cannot use this parameter with the MinimumVersion, MaximumVersion, or RequiredVersion parameters). + [Parameter()] + [switch] + $AllVersions, + + # Allows returning prerelease versions. + [Parameter()] + [switch] + $Prerelease + ) + + + begin { } + process { + foreach ($n in $Name) { + if ($pscmdlet.ShouldProcess($n)) { + $PSResource = New-Object PSObject -Property @{ + Name = $Name + Version = "placeholder-for-module-version" + Type = "placeholder-for-type" + Description = "placeholder-for-description" + Author = "placeholder-for-author" + CompanyName = "placeholder-for-company-name" + Copyright = "placeholder-for-copyright" + PublishedDate = "placeholder-for-published-date" + InstalledDate = "placeholder-for-installed-date" + UpdatedDate = "placeholder-for-updated-date" + LicenseUri = "placeholder-for-license-uri" + ProjectUri = "placeholder-for-project-uri" + IconUri = "placeholder-for-icon-uri" + Tags = "placeholder-for-tags" + Includes = "placeholder-for-includes" + PowerShellGetFormatVersion = "placeholder-for-powershellget-format-version" + ReleaseNotes = "placeholder-for-release-notes" + Dependencies = "placeholder-for-dependencies" + URL = "placeholder-for-url" + Repository = "placeholder-for-repository" #??? + AdditonalMetadata = "placehodler-for-additional-metadata" + } + + return $PSResource + } + } + } + end { } + +} diff --git a/v3prototype/Get-PSResourceValidations.ps1 b/v3prototype/Get-PSResourceValidations.ps1 new file mode 100644 index 00000000..40191016 --- /dev/null +++ b/v3prototype/Get-PSResourceValidations.ps1 @@ -0,0 +1,104 @@ +####################### +### Get-PSResource ### +####################### +### Getting Installed Modules ### +# Should get the module 'TestModule' +Get-PSResource 'TestModule' + +# Should get the module 'TestModule' +Get-PSResource -name 'TestModule' + +# Should get the module 'TestModule' +Get-PSResource 'TestModule' -Type 'Module' + +# Should get the module 'TestModule' +Get-PSResource 'TestModule' -Type 'Module', 'Script', 'Library' + +# Should get the modules 'TestModule1', 'TestModule2', 'TestModule3' +Get-PSResource 'TestModule1', 'TestModule2', 'TestModule3' + +# Should get the latest, non-prerelease version of the module 'TestModule' that is at least 1.5.0 +Get-PSResource 'TestModule' -MinimumVersion '1.5.0' + +# Should get the latest, non-prerelease version of the module 'TestModule' that is at most 1.5.0 +Get-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should get the latest, non-prerelease version of the module 'TestModule' that is at least version 1.0.0 and at most 2.0.0 +Get-PSResource 'TestModule' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should get version 1.5.0 (non-prerelease) of the module 'TestModule' +Get-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should find all non-prerelease versions of the module 'TestModule' +Get-PSResource 'TestModule' -AllVersions + +# Should get the latest verison of 'TestModule', including prerelease versions +Get-PSResource 'TestModule' -Prerelease + + + +### Getting Installed Scripts ### +# Should get the script 'TestScript' +Get-PSResource 'TestScript' + +# Should get the script 'TestScript' +Get-PSResource -name 'TestScript' + +# Should get the module 'TestScript' +Get-PSResource 'TestScript' -Type 'Script' + +# Should get the module 'TestScript' +Get-PSResource 'TestScript' -Type 'Module', 'Script', 'Library' + +# Should get the scripts 'TestScript1', 'TestScript2', 'TestScript3' +Get-PSResource 'TestScript1', 'TestScript2', 'TestScript3' + +# Should get the latest, non-prerelease version of the script 'TestScript' that is at least 1.5.0 +Get-PSResource 'TestScript' -MinimumVersion '1.5.0' + +# Should get the latest, non-prerelease version of the script 'TestScript' that is at most 1.5.0 +Get-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should get the latest, non-prerelease version of the script 'TestScript' that is at least version 1.0.0 and at most 2.0.0 +Get-PSResource 'TestScript' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should get version 1.5.0 (non-prerelease) of the script 'TestScript' +Get-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should find all non-prerelease versions of the module 'TestModule' +Get-PSResource 'TestModule' -AllVersions + +# Should get the latest verison of 'TestScript', including prerelease versions +Get-PSResource 'TestScript' -Prerelease + + +### Getting Installed Nupkgs ### +# Should get the nupkg 'TestNupkg' +Get-PSResource 'TestNupkg' + +# Should get the nupkg 'TestNupkg' +Get-PSResource 'TestNupkg' -Type 'Library' + +# Should get the nupkg 'TestNupkg' +Get-PSResource 'TestNupkg' -Type 'Module', 'Script', 'Library' + +# Should get the nupkgs 'TestNupkg1', 'TestNupkg2', 'TestNupkg3' +Get-PSResource 'TestNupkg1', 'TestNupkg2', 'TestNupkg3' + +# Should get the latest, non-prerelease version of the nupkg 'TestNupkg' that is at least 1.5.0 +Get-PSResource 'TestNupkg' -MinimumVersion '1.5.0' + +# Should get the latest, non-prerelease version of the nupkg 'TestNupkg' that is at most 1.5.0 +Get-PSResource 'TestNupkg' -MaximumVersion '1.5.0' + +# Should get the latest, non-prerelease version of the nupkg 'TestNupkg' that is at least version 1.0.0 and at most 2.0.0 +Get-PSResource 'TestNupkg' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should get version 1.5.0 (non-prerelease) of the nupkg 'TestNupkg' +Get-PSResource 'TestNupkg' -RequiredVersion '1.5.0' + +# Should find all non-prerelease versions of the module 'TestModule' +Get-PSResource 'TestModule' -AllVersions + +# Should get the latest verison of 'TestNupkg', including prerelease versions +Get-PSResource 'TestNupkg' -Prerelease diff --git a/v3prototype/Install-PSResource.ps1 b/v3prototype/Install-PSResource.ps1 new file mode 100644 index 00000000..06e5f31b --- /dev/null +++ b/v3prototype/Install-PSResource.ps1 @@ -0,0 +1,180 @@ +# Replaces: Install-Module, Install-Script +# Parameter Sets: NameParameterSet, InputObject +# Install-PSResource will only work for modules unless -DestinationPath is specified which works for all resource types. +function Install-PSResource { + [OutputType([void])] + [cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies the exact names of resources to install from a repository. + # A comma-separated list of module names is accepted. The resource name must match the resource name in the repository. + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNullOrEmpty()] + [string[]] + $Name, + + # Used for pipeline input. + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'InputObject')] + [ValidateNotNull()] + [PSCustomObject[]] + $InputObject, + + # The destination where the resource is to be installed. Works for all resource types. + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $DestinationPath, + + # Specifies the minimum version of the resource to be installed (cannot use this parameter with the RequiredVersion parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $MinimumVersion, + + # Specifies the maximum version of the resource to include to be installed (cannot use this parameter with the RequiredVersion parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $MaximumVersion, + + # Specifies the required version of the resource to include to be installed (cannot use this parameter with the MinimumVersion or MaximumVersion parameters). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $RequiredVersion, + + # Allows installing prerelease versions + [Parameter(ParameterSetName = 'NameParameterSet')] + [switch] + $Prerelease, + + # Specifies the repository to search within (default is all repositories). + [Parameter(ParameterSetName = 'NameParameterSet')] + [ValidateNotNullOrEmpty()] + [string[]] + $Repository, + + # If the resource requires dependencies that are not already installed, then a prompt will appear before anything is installed, + # listing all the resources including module name, version, size, and repository to be installed + # unless -IncludeDependencies is specified which will install without prompting. + # Rejecting the prompt will result in nothing being installed. + [Parameter()] + [switch] + $IncludeDependencies, + + # Accepts a path to a hashtable or json file. + # Where the key is the module name and the value is either the required version specified using Nuget version range syntax or + # a hash table where repository is set to the URL of the repository and version contains the Nuget version range syntax. + # The json format will be the same as if this hashtable is passed to ConvertTo-Json. + [Parameter(ParameterSetName = 'NameParameterSet')] + [ValidateNotNullOrEmpty()] + [string[]] + $RequiredResources, + + # Accepts a path to a psd1 or json file. + # See above for json description. + [Parameter(ParameterSetName = 'NameParameterSet')] + [ValidateNotNullOrEmpty()] + [string[]] + $RequiredResourcesFile, + + # Specifies the installation scope of the module. The acceptable values for this parameter are AllUsers and CurrentUser. Default is CurrentUser. + # The AllUsers scope installs modules in a location that is accessible to all users of the computer: + # $env:ProgramFiles\PowerShell\Modules + # The CurrentUser installs modules in a location that is accessible only to the current user of the computer: + # $home\Documents\PowerShell\Modules + # When no Scope is defined, the default is set based on the PowerShellGet version. + # In PowerShellGet versions 2.0.0 and above, the default is CurrentUser, which does not require elevation for install. + # In PowerShellGet 1.x versions, the default is AllUsers, which requires elevation for install. + [Parameter()] + [ValidateSet("CurrentUser", "AllUsers")] + [string] + $Scope, + + # Specifies a proxy server for the request, rather than connecting directly to the Internet resource. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [Uri] + $Proxy, + + # Specifies a user account that has permission to use the proxy server that is specified by the Proxy parameter. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $ProxyCredential, + + # Specifies a user account that has rights to install a resource from a specific repository. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $Credential, + + # Overrides warning messages about installation conflicts about existing commands on a computer. + # Overwrites existing commands that have the same name as commands being installed by a module. AllowClobber and Force can be used together in an Install-Module command. + # Prevents installing modules that have the same cmdlets as a differently named module already + [Parameter()] + [switch] + $NoClobber, + + # Suppresses being prompted if the publisher of the resource is different from the currently installed version. + [Parameter()] + [switch] + $IgnoreDifferentPublisher, + + # Suppresses being prompted for untrusted sources. + [Parameter()] + [switch] + $TrustRepository, + + # Overrides warning messages about resource installation conflicts. + # If a resource with the same name already exists on the computer, Force allows for multiple versions to be installed. + # If there is an existing resource with the same name and version, Force does NOT overwrite that version. + [Parameter()] + [switch] + $Force, + + # Overwrites a previously installed resource with the same name and version. + [Parameter()] + [switch] + $Reinstall, + + # Suppresses progress information. + [Parameter()] + [switch] + $Quiet, + + # For modules that require a license, AcceptLicense automatically accepts the license agreement during installation. + [Parameter()] + [switch] + $AcceptLicense, + + # Returns the resource as an object to the console. + [Parameter()] + [switch] + $PassThru + ) + + begin { } + process { + foreach ($n in $Name) { + if ($pscmdlet.ShouldProcess($n)) { + + if (Find-PSResource $n) { + # Install the resource + write-verbose -message "Successfully installed $n" + } + } + } + } + end { } +} diff --git a/v3prototype/Install-PSResourceValidations.ps1 b/v3prototype/Install-PSResourceValidations.ps1 new file mode 100644 index 00000000..0aad258c --- /dev/null +++ b/v3prototype/Install-PSResourceValidations.ps1 @@ -0,0 +1,175 @@ +########################## +### Install-PSResource ### +########################## + +### Installing Modules ### + +# Should install the module 'TestModule' +Install-PSResource 'TestModule' + +# Should install the module 'TestModule' +Install-PSResource -name 'TestModule' + +# Should install the modules 'TestModule1', 'TestModule2', 'TestModule3' +Install-PSResource 'TestModule1', 'TestModule2', 'TestModule3' + +# Should install the latest, non-prerelease version of the module 'TestModule' that is at least 1.5.0 +Install-PSResource 'TestModule' -MinimumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the module 'TestModule' that is at most 1.5.0 +Install-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the module 'TestModule' that is at least version 1.0.0 and at most 2.0.0 +Install-PSResource 'TestModule' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should install version 1.5.0 (non-prerelease) of the module 'TestModule' +Install-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should install the latest verison of 'TestModule', including prerelease versions +Install-PSResource 'TestModule' -Prerelease + +# Should install 'TestModule' from one of the specified repositories (based on repo priority) +Install-PSResource 'TestModule' -Repository 'Repository1', 'Repository2' + +# Should install the module Pester +Install-PSResource -RequiredResources @{ + 'Configuration' = '[1.3.1,2.0)' + 'Pester' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } +} + +# Should install the module Pester +Install-PSResource -RequiredResources ConvertTo-Json ( + @{ + 'Configuration' = '[1.3.1,2.0)' + 'Pester' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } + } +) + +# Should install the required resources in RequiredResource.psd1 +Install-PSResource -RequiredResourcesFile 'RequiredResource.psd1' + +# Should install the required resources in RequiredResource.json +Install-PSResource -RequiredResourcesFile 'RequiredResource.json' + +# Should install the module 'TestModule' to the CurrentUser scope +Install-PSResource 'TestModule' -Scope 'CurrentUser' + +# Should install the module 'TestModule' to the AllUsers scope +Install-PSResource 'TestModule' -Scope 'AllUsers' + +# Should install the module 'TestModule' without prompting warning message regarding installation conflicts +Install-PSResource 'TestModule' -NoClobber + +# Should install the module 'TestModule' without prompting message regarding publisher mismatch +Install-PSResource 'TestModule' -IgnoreDifferentPublisher + +# Should install the module 'TestModule' without prompting message regarding untrusted sources +Install-PSResource 'TestModule' -TrustRepository + +# Should install the module 'TestModule' without prompting message regarding untrusted sources +Install-PSResource 'TestModule' -Force + +# Should reinstall the module 'TestModule' +Install-PSResource 'TestModule' -Reinstall + +#Should install the module 'TestModule' without displaying progress information +Install-PSResource 'TestModule' -Quiet + +#Should install the module 'TestModule' and automatically accept license agreement +Install-PSResource 'TestModule' -AcceptLicense + +#Should install the module 'TestModule' and return the module as an object to the console +Install-PSResource 'TestModule' -PassThru + + + +### Installing Scripts ### + +# Should install the script 'TestScript' +Install-PSResource 'TestScript' + +# Should install the script 'TestScript' +Install-PSResource -name 'TestScript' + +# Should install the scripts 'TestScript1', 'TestScript2', 'TestScript3' +Install-PSResource 'TestScript1', 'TestScript2', 'TestScript3' + +# Should install the latest, non-prerelease version of the script 'TestScript' that is at least 1.5.0 +Install-PSResource 'TestScript' -MinimumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the script 'TestScript' that is at most 1.5.0 +Install-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should install the latest, non-prerelease version of the script 'TestScript' that is at least version 1.0.0 and at most 2.0.0 +Install-PSResource 'TestScript' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should install version 1.5.0 (non-prerelease) of the script 'TestScript' +Install-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should install the latest verison of 'TestScript', including prerelease versions +Install-PSResource 'TestScript' -Prerelease + +# Should install 'TestScript' from one of the specified repositories (based on repo priority) +Install-PSResource 'TestScript' -Repository 'Repository1', 'Repository2' + +# Should install the script TestScript +Install-PSResource -RequiredResources @{ + 'Configuration' = '[1.3.1,2.0)' + 'TestScript' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } +} + +# Should install the script TestScript +Install-PSResource -RequiredResources ConvertTo-Json ( + @{ + 'Configuration' = '[1.3.1,2.0)' + 'TestScript' = @{ + version = '[4.4.2,4.7.0]' + repository = 'https://www.powershellgallery.com' + } + } +) + +# Should install the required resources in RequiredResource.psd1 +Install-PSResource -RequiredResourcesFile 'RequiredResource.psd1' + +# Should install the required resources in RequiredResource.json +Install-PSResource -RequiredResourcesFile 'RequiredResource.json' + +# Should install the script 'TestScript' to the CurrentUser scope +Install-PSResource 'TestScript' -Scope 'CurrentUser' + +# Should install the script 'TestScript' to the AllUsers scope +Install-PSResource 'TestScript' -Scope 'AllUsers' + +# Should install the module 'TestModule' without prompting warning message regarding installation conflicts +Install-PSResource 'TestModule' -NoClobber + +# Should install the script 'TestScript' without prompting message regarding publisher mismatch +Install-PSResource 'TestScript' -IgnoreDifferentPublisher + +# Should install the script 'TestScript' without prompting message regarding untrusted sources +Install-PSResource 'TestScript' -TrustRepository + +# Should install the script 'TestScript' without prompting message regarding untrusted sources +Install-PSResource 'TestScript' -Force + +# Should reinstall the script 'TestScript' +Install-PSResource 'TestScript' -Reinstall + +#Should install the script 'TestScript' without displaying progress information +Install-PSResource 'TestScript' -Quiet + +#Should install the script 'TestScript' and automatically accept license agreement +Install-PSResource 'TestScript' -AcceptLicense + +#Should install the script 'TestScript' and return the script as an object to the console +Install-PSResource 'TestScript' -PassThru diff --git a/v3prototype/Publish-PSResource.ps1 b/v3prototype/Publish-PSResource.ps1 new file mode 100644 index 00000000..b7f0e898 --- /dev/null +++ b/v3prototype/Publish-PSResource.ps1 @@ -0,0 +1,149 @@ +function Publish-PSResource { + + [OutputType([void])] + [Cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies the name of the resource to be published. + [Parameter(Mandatory = $true, + ParameterSetName = "ModuleNameParameterSet", + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [string] + $Name, + + # Specifies the path to the resource that you want to publish. This parameter accepts the path to the folder that contains the resource. + # Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.). + [Parameter(Mandatory = $true, + ParameterSetName = "ModulePathParameterSet", + ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, + ParameterSetName = 'ScriptPathParameterSet', + ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [string] + $Path, + + # Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is used exactly as entered. + # No characters are interpreted as wildcards. If the path includes escape characters, enclose them in single quotation marks. + # Single quotation marks tell PowerShell not to interpret any characters as escape sequences. + [Parameter(Mandatory = $true, + ParameterSetName = 'ModuleLiteralPathParameterSet', + ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, + ParameterSetName = 'ScriptLiteralPathParameterSet', + ValueFromPipelineByPropertyName = $true)] + [Alias('PSPath')] + [ValidateNotNullOrEmpty()] + [string] + $LiteralPath, + + # Can be used to publish the a nupkg locally. + [Parameter(Mandatory = $true, + ParameterSetName = 'DestinationPathParameterSet', + ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [string] + $DestinationPath, + + # Specifies the exact version of a single resource to publish. + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $RequiredVersion, + + # Specifies the API key that you want to use to publish a module to the online gallery. + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $NuGetApiKey, + + # Specifies the repository to publish to. + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $Repository, + + # Specifies a user account that has rights to a specific repository. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $Credential, + + # Specifies a string containing release notes or comments that you want to be available to users of this version of the resource. + [Parameter()] + [string[]] + $ReleaseNotes, + + # Adds one or more tags to the resource that you are publishing. + [Parameter()] + [ValidateNotNullOrEmpty()] + [string[]] + $Tags, + + # Specifies the URL of licensing terms for the resource you want to publish. + [Parameter()] + [ValidateNotNullOrEmpty()] + [Uri] + $LicenseUri, + + # Specifies the URL of an icon for the resource. + [Parameter()] + [ValidateNotNullOrEmpty()] + [Uri] + $IconUri, + + # Specifies the URL of a webpage about this project. + [Parameter()] + [ValidateNotNullOrEmpty()] + [Uri] + $ProjectUri, + + # Excludes files from a nuspec + [Parameter(ParameterSetName = "ModuleNameParameterSet")] + [ValidateNotNullOrEmpty()] + [string[]] + $Exclude, + + # Forces the command to run without asking for user confirmation. + [Parameter()] + [switch] + $Force, + + # Allows resources marked as prerelease to be published. + [Parameter()] + [switch] + $Prerelease, + + # Bypasses the default check that all dependencies are present. + [Parameter()] + [switch] + $SkipDependenciesCheck, + + # Specifies a nuspec file rather than relying on this module to produce one. + [Parameter()] + [switch] + $Nuspec + ) + + + begin { } + process { + if ($pscmdlet.ShouldProcess($Name)) { + if ($Name) { + # Publish module + Write-Verbose -message "Successfully published $Name" + } + elseif ($Path) { + # Publish resource + Write-Verbose -message "Successfully published $Path" + } + elseif ($LiteralPath) { + # Publish resource + Write-Verbose -message "Successfully published $LiteralPath" + } + } + } + + end { } +} diff --git a/v3prototype/Publish-PSResourceValidations.ps1 b/v3prototype/Publish-PSResourceValidations.ps1 new file mode 100644 index 00000000..3ee56089 --- /dev/null +++ b/v3prototype/Publish-PSResourceValidations.ps1 @@ -0,0 +1,104 @@ +########################## +### Publish-PSResource ### +########################## + +### Publish module ### +# Should publish the module 'TestModule' +Publish-PSResource -name 'TestModule' + +# Should publish the module 'TestModule' +Publish-PSResource 'TestModule' + +# Should publish the module 'TestModule' from the specified path +Publish-PSResource 'TestModule' -Path '.\*\somepath' + +# Should publish the module 'TestModule' from the specified literal path +Publish-PSResource 'TestModule' -LiteralPath '.' + +# Should publish the version 1.5.0 of the module 'TestModule' +Publish-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should publish the lastest version of the module 'TestModule' even if it's a prerelease version +Publish-PSResource 'TestModule' -Prerelease + +# Should publish the version 1.5.0 of the module 'TestModule' +Publish-PSResource 'TestModule' -NuGetApiKey '1234567890' + +# Should publish the module 'TestModule' to the specified repository +Publish-PSResource 'TestModule' -Repository 'Repository' + +# Should publish the module 'TestModule' with release notes +Publish-PSResource 'TestModule' -ReleaseNotes 'Mock release notes.' + +# Should publish the module 'TestModule' with the tags 'Tag1', 'Tag2', 'Tag3' +Publish-PSResource 'TestModule' -Tags 'Tag1', 'Tag2', 'Tag3' + +# Should publish the module 'TestModule' with a specified license uri +Publish-PSResource 'TestModule' -LicenseUri 'www.licenseuri.com' + +# Should publish the module 'TestModule' with a specified icon uri +Publish-PSResource 'TestModule' -IconUri 'www.iconuri.com' + +# Should publish the module 'TestModule' with a specified projected uri +Publish-PSResource 'TestModule' -ProjectUri 'www.projecturi.com' + +# Should publish the module 'TestModule' and exclude the specified file from the nuspec. +Publish-PSResource 'TestModule' -Exclude 'some\path\file.ps1' + +# Should publish the module 'TestModule' without asking for user confirmation +Publish-PSResource 'TestModule' -Force + +# Should publish the module 'TestModule' without checking that all dependencies are present +Publish-PSResource 'TestModule' -SkipDependenciesCheck + +# Should publish the module 'TestModule' with a specified nuspec file +Publish-PSResource 'TestModule' -Nuspec '\path\to\file.nuspec' + + +# Should publish the nupkg 'TestNupkg' from the specified literal path +Publish-PSResource 'TestModule' -DestinationPath '.\TestNupkg.nupkg' + + + +### Publish Script ### +# Should publish the script 'TestScript' from the specified path +Publish-PSResource 'TestScript' -Path '.\*\TestScript.ps1' + +# Should publish the script 'TestScript' from the specified literal path +Publish-PSResource 'TestScript' -LiteralPath '.\TestScript.ps1' + +# Should publish the version 1.5.0 of the script 'TestScript' +Publish-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should publish the lastest version of the script 'TestScript' even if it's a prerelease version +Publish-PSResource 'TestScript' -Prerelease + +# Should publish the version 1.5.0 of the script 'TestScript' +Publish-PSResource 'TestScript' -NuGetApiKey '1234567890' + +# Should publish the script 'TestScript' to the specified repository +Publish-PSResource 'TestScript' -Repository 'Repository' + +# Should publish the script 'TestScript' with release notes +Publish-PSResource 'TestScript' -ReleaseNotes 'Mock release notes.' + +# Should publish the script 'TestScript' with the tags 'Tag1', 'Tag2', 'Tag3' +Publish-PSResource 'TestScript' -Tags 'Tag1', 'Tag2', 'Tag3' + +# Should publish the script 'TestScript' with a specified license uri +Publish-PSResource 'TestScript' -LicenseUri 'www.licenseuri.com' + +# Should publish the script 'TestScript' with a specified icon uri +Publish-PSResource 'TestScript' -IconUri 'www.iconuri.com' + +# Should publish the script 'TestScript' with a specified projected uri +Publish-PSResource 'TestScript' -ProjectUri 'www.projecturi.com' + +# Should publish the script 'TestScript' without asking for user confirmation +Publish-PSResource 'TestScript' -Force + +# Should publish the script 'TestScript' without checking that all dependencies are present +Publish-PSResource 'TestScript' -SkipDependenciesCheck + +# Should publish the script 'TestScript' with a specified nuspec file +Publish-PSResource 'TestScript' -Nuspec '\path\to\file.nuspec' diff --git a/v3prototype/RepositoryValidations.ps1 b/v3prototype/RepositoryValidations.ps1 index fc846baf..ecce2411 100644 --- a/v3prototype/RepositoryValidations.ps1 +++ b/v3prototype/RepositoryValidations.ps1 @@ -4,6 +4,32 @@ # Should register the PowerShell Gallery Register-PSRepository -PSGallery +<<<<<<< HEAD +# Should register the repository 'TestRepo' +Register-PSResourceRepository 'TestRepo' 'www.testrepo.com' + +# Should register the repository 'TestRepo' +Register-PSResourceRepository -name 'TestRepo' -url 'www.testrepo.com' + +# Should register the repository 'TestRepo' as trusted, priority should be set to 0 +Register-PSResourceRepository -name 'TestRepo' -url 'www.testrepo.com' -Trusted + +# Should register the repository 'TestRepo' with a priority of 2 +Register-PSResourceRepository -name 'TestRepo' -url 'www.testrepo.com' -Priority 2 + +### Repositories +# Should register the repositories 'TestRepo1', 'TestRepo2', 'PSGallery' +Register-PSResourceRepository -Repositories @( + @{ Name = 'TestRepo1'; URL = 'https://testrepo1.com'; Trusted = $true; Credential = $cred } + @{ Name = 'TestRepo2'; URL = '\\server\share\myrepository'; Trusted = $true } + @{ Default = $true; Trusted = $true } +) + +# Should return the repositories 'TestRepo1', 'TestRepo2', 'PSGallery' +$repos = @( + @{ Name = 'TestRepo1'; URL = 'https://testrepo1.com'; Trusted = $true; } + @{ Name = 'TestRepo2'; URL = '\\server\share\myrepository'; Trusted = $true } +======= # Should register the repository "TestRepo" Register-PSResourceRepository "TestRepo" "www.testrepo.com" @@ -28,6 +54,7 @@ Register-PSResourceRepository -Repositories @( $repos = @( @{ Name = "TestRepo1"; URL = "https://testrepo1.com"; Trusted = $true; } @{ Name = "TestRepo2"; URL = "\\server\share\myrepository"; Trusted = $true } +>>>>>>> 419fe737e7f5e0c8d31477cb656faa0ded253c37 @{ Default = $true; Trusted = $true } ) $repos | Register-PSResourceRepository @@ -40,6 +67,25 @@ $repos | Register-PSResourceRepository # Should return all repositories Get-PSResourceRepository +<<<<<<< HEAD +# Should return the repository 'TestRepo' +Get-PSResourceRepository 'TestRepo' + +# Should return the repository 'TestRepo' +Get-PSResourceRepository -name 'TestRepo' + +# Should return the repositories 'TestRepo1', 'TestRepo2', 'TestRepo3' +Get-PSResourceRepository 'TestRepo1', 'TestRepo2', 'TestRepo3' + +# Should return the repositories 'TestRepo1', 'TestRepo2', 'TestRepo3' +Get-PSResourceRepository -name 'TestRepo1', 'TestRepo2', 'TestRepo3' + +# Should return the repository 'TestRepo' +'TestRepo1' | Get-PSResourceRepository + +# Should return the repositories 'TestRepo1', 'TestRepo2', 'TestRepo3' +'TestRepo1', 'TestRepo2', 'TestRepo3' | Get-PSResourceRepository +======= # Should return the repository "TestRepo" Get-PSResourceRepository "TestRepo" @@ -57,12 +103,42 @@ Get-PSResourceRepository -name "TestRepo1", "TestRepo2", "TestRepo3" # Should return the repositories "TestRepo1", "TestRepo2", "TestRepo3" "TestRepo1", "TestRepo2", "TestRepo3" | Get-PSResourceRepository +>>>>>>> 419fe737e7f5e0c8d31477cb656faa0ded253c37 ################################ ### Set-PSResourceRepository ### ################################ +<<<<<<< HEAD +# Should set the repository 'TestRepo' to the url 'www.testrepo.com' +Set-PSResourceRepository 'TestRepo' 'www.testrepo.com' + +# Should set the repository 'TestRepo' to the url 'www.testrepo.com' +Set-PSResourceRepository -name 'TestRepo' -url 'www.testrepo.com' + +# Should set the repository 'TestRepo' to trusted, with a priority of 0 +Set-PSResourceRepository 'TestRepo' -Trusted + +# Should set the repository 'TestRepo' with a priority of 2 +Set-PSResourceRepository 'TestRepo' 'www.testrepo.com' -Priority 2 + +# Should set the repository 'TestRepo' +'TestRepo1' | Set-PSResourceRepository -url 'www.testrepo.com' + +### Repositories +# Should set the repositories 'TestRepo1', 'TestRepo2', 'PSGallery' to trusted, with a priority of 0 +Set-PSResourceRepository -Repositories @( + @{ Name = 'TestRepo1'; URL = 'https://testrepo1.com'; Trusted = $true; } + @{ Name = 'TestRepo2'; URL = '\\server\share\myrepository'; Trusted = $true } + @{ Default = $true; Trusted = $true } +) + +# Should return the repositories 'TestRepo1', 'TestRepo2', 'PSGallery' +$repos = @( + @{ Name = 'TestRepo1'; URL = 'https://testrepo1.com'; Trusted = $true; } + @{ Name = 'TestRepo2'; URL = '\\server\share\myrepository'; Trusted = $true } +======= # Should set the repository "TestRepo" to the url "www.testrepo.com" Set-PSResourceRepository "TestRepo" "www.testrepo.com" @@ -90,6 +166,7 @@ Set-PSResourceRepository -Repositories @( $repos = @( @{ Name = "TestRepo1"; URL = "https://testrepo1.com"; Trusted = $true; } @{ Name = "TestRepo2"; URL = "\\server\share\myrepository"; Trusted = $true } +>>>>>>> 419fe737e7f5e0c8d31477cb656faa0ded253c37 @{ Default = $true; Trusted = $true } ) $repos | Set-PSResourceRepository @@ -99,6 +176,19 @@ $repos | Set-PSResourceRepository ####################################### ### Unregister-PSResourceRepository ### ####################################### +<<<<<<< HEAD +# Should unregister the repository 'TestRepo' +Unregister-PSResourceRepository -name 'TestRepo' + +# Should unregister the repositories 'TestRepo1', 'TestRepo2', 'TestRepo3' +Unregister-PSResourceRepository -name 'TestRepo1', 'TestRepo2', 'TestRepo3' + +# Should unregister the repository 'TestRepo' +'TestRepo1' | Unregister-PSResourceRepository + +# Should unregister the repositories 'TestRepo1', 'TestRepo2', 'TestRepo3' +'TestRepo1', 'TestRepo2', 'TestRepo3' | Unregister-PSResourceRepository +======= # Should unregister the repository "TestRepo" Unregister-PSResourceRepository -name "TestRepo" @@ -110,3 +200,4 @@ Unregister-PSResourceRepository -name "TestRepo1", "TestRepo2", "TestRepo3" # Should unregister the repositories "TestRepo1", "TestRepo2", "TestRepo3" "TestRepo1", "TestRepo2", "TestRepo3" | Unregister-PSResourceRepository +>>>>>>> 419fe737e7f5e0c8d31477cb656faa0ded253c37 diff --git a/v3prototype/Save-PSResource.ps1 b/v3prototype/Save-PSResource.ps1 new file mode 100644 index 00000000..fba98b15 --- /dev/null +++ b/v3prototype/Save-PSResource.ps1 @@ -0,0 +1,164 @@ +# Saving resources +function Save-PSResource { + [OutputType([void])] + [cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies the exact names of resources to save from a repository. + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'NameAndLiteralPathParameterSet')] + [ValidateNotNullOrEmpty()] + [string[]] + $Name, + + # Specifies the type of the resource being saved. + [Parameter(ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(ParameterSetName = 'NameAndLiteralPathParameterSet')] + [ValidateSet('Module', 'Script', 'Library')] + [string[]] + $Type, + + # Used for pipeline input. + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'InputObjectAndPathParameterSet')] + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'InputObjectAndLiteralPathParameterSet')] + [ValidateNotNull()] + [PSCustomObject[]] + $InputObject, + + # Specifies the minimum version of the resource to be saved (cannot use this parameter with the RequiredVersion parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndLiteralPathParameterSet')] + [ValidateNotNull()] + [string] + $MinimumVersion, + + # Specifies the maximum version of the resource to include to be saved (cannot use this parameter with the RequiredVersion parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndLiteralPathParameterSet')] + [ValidateNotNull()] + [string] + $MaximumVersion, + + # Specifies the required version of the resource to include to be saved (cannot use this parameter with the MinimumVersion or MaximumVersion parameters). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndLiteralPathParameterSet')] + [ValidateNotNull()] + [string] + $RequiredVersion, + + # Specifies the repository to search within (default is all repositories). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndLiteralPathParameterSet')] + [ValidateNotNullOrEmpty()] + [string[]] + $Repository, + + # Specifies the location on the local computer to store a saved resource. Accepts wildcard characters. + [Parameter(Mandatory = $true, + Position = 1, + ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(Mandatory = $true, + Position = 1, + ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'InputObjectAndPathParameterSet')] + [string] + $Path, + + # Specifies a path to one or more locations. + # The value of the LiteralPath parameter is used exactly as entered. No characters are interpreted as wildcards. + # If the path includes escape characters, enclose them in single quotation marks. + # PowerShell does not interpret any characters enclosed in single quotation marks as escape sequences. + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameAndLiteralPathParameterSet')] + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'InputObjectAndLiteralPathParameterSet')] + [Alias('PSPath')] + [string] + $LiteralPath, + + # Specifies a proxy server for the request, rather than connecting directly to an internet resource. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [Uri] + $Proxy, + + # Specifies a user account that has permission to use the proxy server specified by the Proxy parameter. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $ProxyCredential, + + # Specifies a user account that has permission to save a resource from a specific repository. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $Credential, + + # Saves a resource without asking for user confirmation. + [Parameter()] + [switch] + $Force, + + # Allows you to save a resource marked as a prerelease. + [Parameter(ParameterSetName = 'NameAndPathParameterSet')] + [Parameter(ParameterSetName = 'NameAndLiteralPathParameterSet')] + [switch] + $Prerelease, + + # Automatically accept the license agreement if the resoruce requires it. + [Parameter()] + [switch] + $AcceptLicense, + + # Will save the resource as a nupkg (if it was originally a nupkg) instead of expanding it into a folder. + [Parameter()] + [switch] + $AsNupkg, + + # Will explicitly retain the runtimes directory hierarchy within the nupkg to the root of the destination. + [Parameter()] + [switch] + $IncludeAllRuntimes + ) + + + begin { } + process { + foreach ($n in $Name) { + if ($pscmdlet.ShouldProcess($n)) { + + if (Find-PSResource $n) { + + # Save the resource-- use install logic + write-verbose -message "Successfully saved $n" + } + } + } + } + end { } +} diff --git a/v3prototype/Save-PSResourceValidations.ps1 b/v3prototype/Save-PSResourceValidations.ps1 new file mode 100644 index 00000000..6aa687dd --- /dev/null +++ b/v3prototype/Save-PSResourceValidations.ps1 @@ -0,0 +1,152 @@ +####################### +### Save-PSResource ### +####################### +### Saving Modules ### +# Should save the module 'TestModule' +Save-PSResource 'TestModule' + +# Should save the module 'TestModule' +Save-PSResource -name 'TestModule' + +# Should save the module 'TestModule' +Save-PSResource 'TestModule' -Type 'Module' + +# Should save the module 'TestModule' +Save-PSResource 'TestModule' -Type 'Module', 'Script', 'Library' + +# Should save the modules 'TestModule1', 'TestModule2', 'TestModule3' +Save-PSResource 'TestModule1', 'TestModule2', 'TestModule3' + +# Should save the latest, non-prerelease version of the module 'TestModule' that is at least 1.5.0 +Save-PSResource 'TestModule' -MinimumVersion '1.5.0' + +# Should save the latest, non-prerelease version of the module 'TestModule' that is at most 1.5.0 +Save-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should save the latest, non-prerelease version of the module 'TestModule' that is at least version 1.0.0 and at most 2.0.0 +Save-PSResource 'TestModule' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should save version 1.5.0 (non-prerelease) of the module 'TestModule' +Save-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should save the latest verison of 'TestModule', including prerelease versions +Save-PSResource 'TestModule' -Prerelease + +# Should save 'TestModule' from one of the specified repositories (based on repo priority) +Save-PSResource 'TestModule' -Repository 'Repository1', 'Repository2' + +# Should save the module 'TestModule' to the specified directory +Save-PSResource 'TestModule' -Path '.\*\somepath' + +# Should save the module 'TestModule' to the specified directory +Save-PSResource 'TestModule' -LiteralPath '.' + +# Should save the module 'TestModule' without prompting user for confirmation +Save-PSResource 'TestModule' -Force + +#Should save the module 'TestModule' and automatically accept license agreement +Save-PSResource 'TestModule' -AcceptLicense + +#Should save the module 'TestModule' from the input object +Find-PSResource 'TestModule' | Save-PSresource + + + +### Saving Scripts ### +# Should save the script 'TestScript' +Save-PSResource 'TestScript' + +# Should save the script 'TestScript' +Save-PSResource -name 'TestScript' + +# Should save the module 'TestScript' +Save-PSResource 'TestScript' -Type 'Script' + +# Should save the module 'TestScript' +Save-PSResource 'TestScript' -Type 'Module', 'Script', 'Library' + +# Should save the scripts 'TestScript1', 'TestScript2', 'TestScript3' +Save-PSResource 'TestScript1', 'TestScript2', 'TestScript3' + +# Should save the latest, non-prerelease version of the script 'TestScript' that is at least 1.5.0 +Save-PSResource 'TestScript' -MinimumVersion '1.5.0' + +# Should save the latest, non-prerelease version of the script 'TestScript' that is at most 1.5.0 +Save-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should save the latest, non-prerelease version of the script 'TestScript' that is at least version 1.0.0 and at most 2.0.0 +Save-PSResource 'TestScript' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should save version 1.5.0 (non-prerelease) of the script 'TestScript' +Save-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should save the latest verison of 'TestScript', including prerelease versions +Save-PSResource 'TestScript' -Prerelease + +# Should save 'TestScript' from one of the specified repositories (based on repo priority) +Save-PSResource 'TestScript' -Repository 'Repository1', 'Repository2' + +# Should save the script 'TestScript' to the specified directory +Save-PSResource 'TestModule' -Path '.\*\somepath' + +# Should save the script 'TestScript' to the specified directory +Save-PSResource 'TestModule' -LiteralPath '.' + +# Should save the script 'TestScript' without prompting message regarding untrusted sources +Save-PSResource 'TestScript' -Force + +#Should save the script 'TestScript' and automatically accept license agreement +Save-PSResource 'TestScript' -AcceptLicense + +#Should save the script 'TestScript' from the input object +Find-PSResource 'TestScript' | Save-PSresource + + +### Saving Nupkgs ### +# Should save the nupkg 'TestNupkg' +Save-PSResource 'TestNupkg' + +# Should save the nupkg 'TestNupkg' +Save-PSResource 'TestNupkg' -Type 'Library' + +# Should save the nupkg 'TestNupkg' +Save-PSResource 'TestNupkg' -Type 'Module', 'Script', 'Library' + +# Should save the nupkgs 'TestNupkg1', 'TestNupkg2', 'TestNupkg3' +Save-PSResource 'TestNupkg1', 'TestNupkg2', 'TestNupkg3' + +# Should save the latest, non-prerelease version of the nupkg 'TestNupkg' that is at least 1.5.0 +Save-PSResource 'TestNupkg' -MinimumVersion '1.5.0' + +# Should save the latest, non-prerelease version of the nupkg 'TestNupkg' that is at most 1.5.0 +Save-PSResource 'TestNupkg' -MaximumVersion '1.5.0' + +# Should save the latest, non-prerelease version of the nupkg 'TestNupkg' that is at least version 1.0.0 and at most 2.0.0 +Save-PSResource 'TestNupkg' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should save version 1.5.0 (non-prerelease) of the nupkg 'TestNupkg' +Save-PSResource 'TestNupkg' -RequiredVersion '1.5.0' + +# Should save the latest verison of 'TestNupkg', including prerelease versions +Save-PSResource 'TestNupkg' -Prerelease + +# Should save the nupkg 'TestNupkg' from one of the specified repositories (based on repo priority) +Save-PSResource 'TestNupkg' -Repository 'Repository1', 'Repository2' + +# Should save the script 'TestScript' to the specified directory +Save-PSResource 'TestModule' -Path '.\*\somepath' + +# Should save the script 'TestScript' to the specified directory +Save-PSResource 'TestModule' -LiteralPath '.' + +# Should save the nupkg 'TestNupkg' without prompting user for confirmation +Save-PSResource 'TestNupkg' -Force + +#Should save the nupkg 'TestNupkg' and automatically accept license agreement +Save-PSResource 'TestNupkg' -AcceptLicense + +#Should save the nupkg 'TestNupkg' as a nupkg (if it was originally nupkg) instead of expanding it into a folder +Save-PSResource 'TestNupkg' -AsNupkg + +#Should save the nupkg 'TestNupkg' and retain the runtimes directory hierarchy within the nupkg to the root of the destination +Save-PSResource 'TestNupkg' -IncludeAllRuntimes diff --git a/v3prototype/Uninstall-PSResource.ps1 b/v3prototype/Uninstall-PSResource.ps1 new file mode 100644 index 00000000..faec5720 --- /dev/null +++ b/v3prototype/Uninstall-PSResource.ps1 @@ -0,0 +1,76 @@ +function Uninstall-PSResource { + [OutputType([void])] + [cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies an array of resource names to uninstall. + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNullOrEmpty()] + [String[]] + $Name, + + # Accepts a PSRepositoryItemInfo object. + # For example, output Get-InstalledModule to a variable and use that variable as the InputObject argument. + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0, + ParameterSetName = 'InputObject')] + [ValidateNotNull()] + [PSCustomObject[]] + $InputObject, + + # Specifies the minimum version of the resource to uninstall (can't be used with the RequiredVersion or AllVersions parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $MinimumVersion, + + # Specifies the exact version number of the reource to uninstall (can't be used with the MinimumVersion, MaximumVersion, or AllVersions parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $RequiredVersion, + + # Specifies the maximum, or newest, version of the resource to uninstall (can't be used with the RequiredVersion or AllVersions parameter). + [Parameter(ValueFromPipelineByPropertyName = $true, + ParameterSetName = 'NameParameterSet')] + [ValidateNotNull()] + [string] + $MaximumVersion, + + # Specifies that you want to include all available versions of a module (can't be used with the MinimumVersion, MaximumVersion, or RequiredVersion parameter). + [Parameter(ParameterSetName = 'NameParameterSet')] + [switch] + $AllVersions, + + # Uninstalls a resource without asking for user confirmation. + [Parameter()] + [Switch] + $Force, + + # Allows a prerelease version to be uninstalled. + [Parameter(ParameterSetName = 'NameParameterSet')] + [switch] + $Prerelease + ) + + begin { } + process { + foreach ($n in $Name) { + if ($pscmdlet.ShouldProcess($n)) { + + if (Get-PSResource $n) { + # Uninstall the resource + Write-Verbose -message "Successfully uninstalled $n" + } + } + } + } + end { } +} diff --git a/v3prototype/Uninstall-PSResourceValidations.ps1 b/v3prototype/Uninstall-PSResourceValidations.ps1 new file mode 100644 index 00000000..55116c04 --- /dev/null +++ b/v3prototype/Uninstall-PSResourceValidations.ps1 @@ -0,0 +1,67 @@ +############################ +### Uninstall-PSResource ### +############################ + +### Uninstalling Modules ### +# Should uninstall the module 'TestModule' +Uninstall-PSResource 'TestModule' + +# Should uninstall the module 'TestModule' +Uninstall-PSResource -name 'TestModule' + +# Should uninstall the modules 'TestModule1', 'TestModule2', 'TestModule3' +Uninstall-PSResource 'TestModule1', 'TestModule2', 'TestModule3' + +# Should uninstall the latest, non-prerelease version of the module 'TestModule' that is at least 1.5.0 +Uninstall-PSResource 'TestModule' -MinimumVersion '1.5.0' + +# Should uninstall the latest, non-prerelease version of the module 'TestModule' that is at most 1.5.0 +Uninstall-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should uninstall the latest, non-prerelease version of the module 'TestModule' that is at least version 1.0.0 and at most 2.0.0 +Uninstall-PSResource 'TestModule' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should uninstall version 1.5.0 (non-prerelease) of the module 'TestModule' +Uninstall-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should uninstall all non-prerelease versions of the module 'TestModule' +Uninstall-PSResource 'TestModule' -AllVersions '1.5.0' + +# Should uninstall the latest verison of 'TestModule', including prerelease versions +Uninstall-PSResource 'TestModule' -Prerelease + +# Should uninstall the module 'TestModule' without asking for user confirmation +Uninstall-PSResource 'TestModule' -Force + + + +### Uninstalling Scripts ### +# Should uninstall the module 'TestScript' +Uninstall-PSResource 'TestScript' + +# Should uninstall the module 'TestScript' +Uninstall-PSResource -name 'TestScript' + +# Should uninstall the modules 'TestScript1', 'TestScript2', 'TestScript3' +Uninstall-PSResource 'TestScript1', 'TestScript2', 'TestScript3' + +# Should uninstall the latest, non-prerelease version of the module 'TestScript' that is at least 1.5.0 +Uninstall-PSResource 'TestScript' -MinimumVersion '1.5.0' + +# Should uninstall the latest, non-prerelease version of the module 'TestScript' that is at most 1.5.0 +Uninstall-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should uninstall the latest, non-prerelease version of the module 'TestScript' that is at least version 1.0.0 and at most 2.0.0 +Uninstall-PSResource 'TestScript' -MinimumVersion '1.0.0' -MaximumVersion '2.0.0' + +# Should uninstall version 1.5.0 (non-prerelease) of the module 'TestScript' +Uninstall-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should uninstall all non-prerelease versions of the module 'TestScript' +Uninstall-PSResource 'TestScript' -AllVersions '1.5.0' + +# Should uninstall the latest verison of 'TestScript', including prerelease versions +Uninstall-PSResource 'TestScript' -Prerelease + +# Should uninstall the module 'TestScript' without asking for user confirmation +Uninstall-PSResource 'TestScript' -Force diff --git a/v3prototype/Update-PSResource.ps1 b/v3prototype/Update-PSResource.ps1 new file mode 100644 index 00000000..46b37a7e --- /dev/null +++ b/v3prototype/Update-PSResource.ps1 @@ -0,0 +1,90 @@ +# Updating resources +function Update-PSResource { + [OutputType([void])] + [cmdletbinding(SupportsShouldProcess = $true)] + Param + ( + # Specifies the names of one or more modules to update. + [Parameter(ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Position = 0)] + [ValidateNotNullOrEmpty()] + [String[]] + $Name, + + # Specifies the required version of the resource to include to be updated (cannot use this parameter with the MaximumVersion or UpdateTo parameters). + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $RequiredVersion, + + # Specifies the required version of the resource to include to be updated (cannot use this parameter with the RequiredVersion or UpdateTo parameters). + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNull()] + [string] + $MaximumVersion, + + # Allows updating to latest path version, minor version, or major version (cannot use this parameter with the MaximumVersion or RequiredVersion parameters). + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateSet("PatchVersion", "MinorVersion", "MajorVersion")] + [string] + $UpdateTo, + + # Specifies a user account that has permission to save a resource from a specific repository. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $Credential, + + # Saves a resource without asking for user confirmation. + [Parameter()] + [ValidateSet("CurrentUser", "AllUsers")] + [string] + $Scope, + + # Specifies a proxy server for the request, rather than connecting directly to an internet resource. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [ValidateNotNullOrEmpty()] + [Uri] + $Proxy, + + # Specifies a user account that has permission to use the proxy server specified by the Proxy parameter. + [Parameter(ValueFromPipelineByPropertyName = $true)] + [PSCredential] + $ProxyCredential, + + # Updates a resource without asking for user confirmation. + [Parameter()] + [Switch] + $Force, + + # Allows an update to a prerelease version. + [Parameter()] + [Switch] + $Prerelease, + + # Automatically accept the license agreement if the resoruce requires it. + [Parameter()] + [switch] + $AcceptLicense, + + # Returns the resource as an object to the console. + [Parameter()] + [switch] + $PassThru + ) + + begin { } + process { + foreach ($n in $Name) { + if ($pscmdlet.ShouldProcess($n)) { + + if (Get-InstalledResource $n) { + # Use install logic to update resource + write-verbose -message "Successfully updated $n" + } + } + } + } + end { } + +} diff --git a/v3prototype/Update-PSResourceValidations.ps1 b/v3prototype/Update-PSResourceValidations.ps1 new file mode 100644 index 00000000..9d680807 --- /dev/null +++ b/v3prototype/Update-PSResourceValidations.ps1 @@ -0,0 +1,93 @@ +########################## +### Update-PSResource ### +########################## + +### Updating Modules ### + +# Should update the module 'TestModule' +Update-PSResource 'TestModule' + +# Should update the module 'TestModule' +Update-PSResource -name 'TestModule' + +# Should update the modules 'TestModule1', 'TestModule2', 'TestModule3' +Update-PSResource 'TestModule1', 'TestModule2', 'TestModule3' + +# Should update to the latest, non-prerelease version of the module 'TestModule' that is at most 1.5.0 +Update-PSResource 'TestModule' -MaximumVersion '1.5.0' + +# Should update to version 1.5.0 (non-prerelease) of the module 'TestModule' +Update-PSResource 'TestModule' -RequiredVersion '1.5.0' + +# Should update to the latest patch version verison of 'TestModule' +Update-PSResource 'TestModule' -UpdateTo 'PatchVersion' + +# Should update to the latest version verison of 'TestModule' +Update-PSResource 'TestModule' -UpdateTo 'MinorVersion' + +# Should update to the latest major verison of 'TestModule' +Update-PSResource 'TestModule' -UpdateTo 'MinorVersion' + +# Should update to the latest verison of 'TestModule', including prerelease versions +Update-PSResource 'TestModule' -Prerelease + +# Should update the module 'TestModule' to the CurrentUser scope +Update-PSResource 'TestModule' -Scope 'CurrentUser' + +# Should update the module 'TestModule' to the AllUsers scope +Update-PSResource 'TestModule' -Scope 'AllUsers' + +# Should update the module 'TestModule' without asking for user confirmation. +Update-PSResource 'TestModule' -Force + +#Should update the module 'TestModule' and automatically accept license agreement +Update-PSResource 'TestModule' -AcceptLicense + +#Should update the module 'TestModule' and return the module as an object to the console +Update-PSResource 'TestModule' -PassThru + + + +### Updating Scripts ### + +# Should install the script 'TestScript' +Install-PSResource 'TestScript' + +# Should update the script 'TestScript' +Update-PSResource 'TestScript' + +# Should update the script 'TestScript' +Update-PSResource -name 'TestScript' + +# Should update the scripts 'TestScript1', 'TestScript2', 'TestScript3' +Update-PSResource 'TestScript1', 'TestScript2', 'TestScript3' + +# Should update to the latest, non-prerelease version of the script 'TestScript' that is at most 1.5.0 +Update-PSResource 'TestScript' -MaximumVersion '1.5.0' + +# Should update to version 1.5.0 (non-prerelease) of the script 'TestScript' +Update-PSResource 'TestScript' -RequiredVersion '1.5.0' + +# Should update to the latest patch version verison of 'TestScript' +Update-PSResource 'TestScript' -UpdateTo 'PatchVersion' + +# Should update to the latest version verison of 'TestScript' +Update-PSResource 'TestScript' -UpdateTo 'MinorVersion' + +# Should update to the latest major verison of 'TestScript' +Update-PSResource 'TestScript' -UpdateTo 'MinorVersion' + +# Should update to the latest verison of 'TestScript', including prerelease versions +Update-PSResource 'TestScript' -Prerelease + +# Should update the script 'TestScript' to the CurrentUser scope +Update-PSResource 'TestScript' -Scope 'CurrentUser' + +# Should update the script 'TestScript' to the AllUsers scope +Update-PSResource 'TestScript' -Scope 'AllUsers' + +# Should update the script 'TestScript' without asking for user confirmation. +Update-PSResource 'TestScript' -Force + +#Should update the script 'TestScript' and automatically accept license agreement +Update-PSResource 'TestScript' -AcceptLicense