@@ -885,7 +885,7 @@ function New-PureOneConnection {
885885 # throw ($_.errordetails.message |ConvertFrom-Json).error_description
886886 }
887887 }
888- $apiendpoint = " https://api.pure1.purestorage.com/oauth2/1.0/token "
888+ $apiendpoint = $ Global :PureOneRestEndpointURL
889889 $AuthAction = @ {
890890 grant_type = " urn:ietf:params:oauth:grant-type:token-exchange"
891891 subject_token = $jwt
@@ -998,7 +998,7 @@ function New-PureOneOperation {
998998 )
999999 $pureOneHeader = Set-PureOneHeader - pureOneToken $pureOneToken - ErrorAction Stop
10001000 Write-Debug $pureOneHeader.authorization
1001- $apiendpoint = " https://api.pure1.purestorage.com/api /$ ( $global :pureOneRestVersion ) /" + $resourceType + $queryFilter
1001+ $apiendpoint = " $ ( $ global :PureOneRestUrl ) /$ ( $global :pureOneRestVersion ) /" + $resourceType + $queryFilter
10021002 Write-Debug $apiendpoint
10031003 $ErrorActionPreference = " Stop"
10041004 if ($jsonBody -ne " " )
@@ -2742,6 +2742,270 @@ function Get-PureOneArrayLoadMeter {
27422742 }
27432743 return $loadMeters
27442744}
2745+ function Get-PureOneLicense {
2746+ <#
2747+ . SYNOPSIS
2748+ Returns all Pure Storage licenses.
2749+ . DESCRIPTION
2750+ Returns all or specified Pure Storage licenses.
2751+ . INPUTS
2752+ None required. Optional inputs are subscription or license information
2753+ . OUTPUTS
2754+ Returns the Pure Storage licenses information in Pure1.
2755+ . EXAMPLE
2756+ PS C:\ Get-PureOneLicense
2757+
2758+ Returns all licenses
2759+ . EXAMPLE
2760+ PS C:\ Get-PureOneLicense -Name mytestlicense
2761+
2762+ Returns the license with the specified name.
2763+ . EXAMPLE
2764+ PS C:\ Get-PureOneLicense -ArrayName myFlashArray
2765+
2766+ Returns the license for the specified array name.
2767+ . EXAMPLE
2768+ PS C:\ Get-PureOneLicense -ArrayId f5b5f364-c644-441d-adab-5ab894924255
2769+
2770+ Returns the license for the specified array ID.
2771+ . EXAMPLE
2772+ PS C:\ Get-PureOneLicense -SubscriptionName SC-9999990
2773+
2774+ Returns all licenses under the specified subscription name
2775+ . EXAMPLE
2776+ PS C:\ Get-PureOneLicense -SubscriptionId 4844ba62-6e15-4d6f-8e51-40257c28dab1
2777+
2778+ Returns all licenses under the specified subscription ID
2779+ . EXAMPLE
2780+ PS C:\ Get-PureOneLicense -ServiceTierType Block
2781+
2782+ Returns all licenses for the block storage.
2783+ . EXAMPLE
2784+ PS C:\ Get-PureOneLicense -ServiceTierLevel Performance
2785+
2786+ Returns all licenses for the performance tier
2787+ . NOTES
2788+ Version: 1.0
2789+ Author: Cody Hosterman https://codyhosterman.com
2790+ Creation Date: 01/26/2021
2791+ Purpose/Change: Initial release
2792+
2793+ *******Disclaimer:******************************************************
2794+ This scripts are offered "as is" with no warranty. While this
2795+ scripts is tested and working in my environment, it is recommended that you test
2796+ this script in a test lab before using in a production environment. Everyone can
2797+ use the scripts/commands provided here without any written permission but I
2798+ will not be liable for any damage or loss to the system.
2799+ ************************************************************************
2800+ #>
2801+
2802+ [CmdletBinding ()]
2803+ Param (
2804+ [Parameter (Position = 0 )]
2805+ [string ]$Id ,
2806+
2807+ [Parameter (Position = 1 )]
2808+ [ValidateSet (" Block" , " UFFO" )]
2809+ [string ]$ServiceTierType ,
2810+
2811+ [Parameter (Position = 2 )]
2812+ [ValidateSet (" Ultra" , " Premium" , " Performance" , " Capacity" )]
2813+ [string ]$ServiceTierLevel ,
2814+
2815+ [Parameter (Position = 3 )]
2816+ [string ]$Name ,
2817+
2818+ [Parameter (Position = 4 )]
2819+ [string ]$SubscriptionId ,
2820+
2821+ [Parameter (Position = 5 )]
2822+ [string ]$SubscriptionName ,
2823+
2824+ [Parameter (Position = 6 )]
2825+ [string ]$ArrayId ,
2826+
2827+ [Parameter (Position = 7 )]
2828+ [string ]$ArrayName ,
2829+
2830+ [Parameter (Position = 8 )]
2831+ [string ]$PureOneToken ,
2832+
2833+ [Parameter (Position = 9 )]
2834+ [PureOneOrganization []]$PureOneOrganization
2835+ )
2836+ if ((! [string ]::IsNullOrWhiteSpace($Name )) -and (! [string ]::IsNullOrWhiteSpace($Id )))
2837+ {
2838+ throw " Please only pass in a license name or an ID. Not both."
2839+ }
2840+ if ((! [string ]::IsNullOrWhiteSpace($SubscriptionName )) -and (! [string ]::IsNullOrWhiteSpace($SubscriptionId )))
2841+ {
2842+ throw " Please only pass in a subscription name or an ID. Not both."
2843+ }
2844+ if ((! [string ]::IsNullOrWhiteSpace($ArrayName )) -and (! [string ]::IsNullOrWhiteSpace($ArrayId )))
2845+ {
2846+ throw " Please only pass in a array name or an ID. Not both."
2847+ }
2848+ if ($null -ne $global :pureOneRateLimit )
2849+ {
2850+ if ($Global :pureOneRateLimit -in 1 .. 1000 )
2851+ {
2852+ $objectQuery = " ?limit=$ ( $global :pureOneRateLimit ) &"
2853+ }
2854+ else {
2855+ throw " Pure1 Rate limit set to invalid amount. Must be between 1-1000. Currently set to $ ( $global :pureOneRateLimit ) "
2856+ }
2857+ }
2858+ else {
2859+ $objectQuery = " ?"
2860+ }
2861+ if (! [string ]::IsNullOrWhiteSpace($Name ))
2862+ {
2863+ $objectQuery = $objectQuery + " names=`' $ ( $Name ) `' "
2864+ if (! [string ]::IsNullOrWhiteSpace($Id ))
2865+ {
2866+ $objectQuery = $objectQuery + " &ids=`' $ ( $Id ) `' "
2867+ }
2868+ }
2869+ elseif (! [string ]::IsNullOrWhiteSpace($Id )) {
2870+ $objectQuery = $objectQuery + " ids=`' $ ( $Id ) `' "
2871+ }
2872+ $tokens = @ ()
2873+ if ([string ]::IsNullOrWhiteSpace($pureOneToken ))
2874+ {
2875+ $tokens += Get-PureOneToken - pureOneOrganization $pureOneOrganization
2876+ }
2877+ else {
2878+ $tokens += $pureOneToken
2879+ }
2880+ $pureLicenses = @ ()
2881+ foreach ($token in $tokens ) {
2882+ $pureLicenses += New-PureOneOperation - resourceType " subscription-licenses" - queryFilter $objectQuery - pureOneToken $token - restOperationType GET - ErrorAction SilentlyContinue
2883+ }
2884+ if (! [string ]::IsNullOrWhiteSpace($ServiceTierType ))
2885+ {
2886+ $pureLicenses = $pureLicenses | Where-Object {$_.service_tier -like " *$ ( $serviceTierType ) *" }
2887+ }
2888+ if (! [string ]::IsNullOrWhiteSpace($ServiceTierLevel ))
2889+ {
2890+ $pureLicenses = $pureLicenses | Where-Object {$_.service_tier -like " *$ ( $serviceTierLevel ) " }
2891+ }
2892+ if (! [string ]::IsNullOrWhiteSpace($SubscriptionId ))
2893+ {
2894+ $pureLicenses = $pureLicenses | Where-Object {$_.subscription.id -eq $SubscriptionId }
2895+ }
2896+ if (! [string ]::IsNullOrWhiteSpace($SubscriptionName ))
2897+ {
2898+ $pureLicenses = $pureLicenses | Where-Object {$_.subscription.name -eq $SubscriptionName }
2899+ }
2900+ if (! [string ]::IsNullOrWhiteSpace($ArrayId ))
2901+ {
2902+ $pureLicenses = $pureLicenses | Where-Object {$_.resources.id -eq $ArrayId }
2903+ }
2904+ if (! [string ]::IsNullOrWhiteSpace($ArrayName ))
2905+ {
2906+ $pureLicenses = $pureLicenses | Where-Object {$_.resources.name -eq $ArrayName }
2907+ }
2908+ if (($pureLicenses | Measure-Object ).Count -eq 0 )
2909+ {
2910+ throw " No matching licenses were found on entered Pure1 organization(s)."
2911+ }
2912+ return $pureLicenses
2913+ }
2914+
2915+ function Get-PureOneSubscription {
2916+ <#
2917+ . SYNOPSIS
2918+ Returns all Pure Storage subscriptions.
2919+ . DESCRIPTION
2920+ Returns all or specified Pure Storage subscriptions.
2921+ . INPUTS
2922+ None required. Optional inputs are subscription
2923+ . OUTPUTS
2924+ Returns the Pure Storage subscription information in Pure1.
2925+ . EXAMPLE
2926+ PS C:\ Get-PureOneSubscription
2927+
2928+ Returns all subscriptions
2929+ . EXAMPLE
2930+ PS C:\ Get-PureOneSubscription -Name mytestsub
2931+
2932+ Returns the subscription with the specified name.
2933+
2934+ . NOTES
2935+ Version: 1.0
2936+ Author: Cody Hosterman https://codyhosterman.com
2937+ Creation Date: 01/26/2021
2938+ Purpose/Change: Initial release
2939+
2940+ *******Disclaimer:******************************************************
2941+ This scripts are offered "as is" with no warranty. While this
2942+ scripts is tested and working in my environment, it is recommended that you test
2943+ this script in a test lab before using in a production environment. Everyone can
2944+ use the scripts/commands provided here without any written permission but I
2945+ will not be liable for any damage or loss to the system.
2946+ ************************************************************************
2947+ #>
2948+
2949+ [CmdletBinding ()]
2950+ Param (
2951+ [Parameter (Position = 0 )]
2952+ [string ]$Id ,
2953+
2954+ [Parameter (Position = 1 )]
2955+ [string ]$Name ,
2956+
2957+ [Parameter (Position = 2 )]
2958+ [string ]$PureOneToken ,
2959+
2960+ [Parameter (Position = 3 )]
2961+ [PureOneOrganization []]$PureOneOrganization
2962+ )
2963+ if ((! [string ]::IsNullOrWhiteSpace($Name )) -and (! [string ]::IsNullOrWhiteSpace($Id )))
2964+ {
2965+ throw " Please only pass in a license name or an ID. Not both."
2966+ }
2967+ if ($null -ne $global :pureOneRateLimit )
2968+ {
2969+ if ($Global :pureOneRateLimit -in 1 .. 1000 )
2970+ {
2971+ $objectQuery = " ?limit=$ ( $global :pureOneRateLimit ) &"
2972+ }
2973+ else {
2974+ throw " Pure1 Rate limit set to invalid amount. Must be between 1-1000. Currently set to $ ( $global :pureOneRateLimit ) "
2975+ }
2976+ }
2977+ else {
2978+ $objectQuery = " ?"
2979+ }
2980+ if (! [string ]::IsNullOrWhiteSpace($Name ))
2981+ {
2982+ $objectQuery = $objectQuery + " names=`' $ ( $Name ) `' "
2983+ if (! [string ]::IsNullOrWhiteSpace($Id ))
2984+ {
2985+ $objectQuery = $objectQuery + " &ids=`' $ ( $Id ) `' "
2986+ }
2987+ }
2988+ elseif (! [string ]::IsNullOrWhiteSpace($Id )) {
2989+ $objectQuery = $objectQuery + " ids=`' $ ( $Id ) `' "
2990+ }
2991+ $tokens = @ ()
2992+ if ([string ]::IsNullOrWhiteSpace($pureOneToken ))
2993+ {
2994+ $tokens += Get-PureOneToken - pureOneOrganization $pureOneOrganization
2995+ }
2996+ else {
2997+ $tokens += $pureOneToken
2998+ }
2999+ $pureSubscriptions = @ ()
3000+ foreach ($token in $tokens ) {
3001+ $pureSubscriptions += New-PureOneOperation - resourceType " subscriptions" - queryFilter $objectQuery - pureOneToken $token - restOperationType GET - ErrorAction SilentlyContinue
3002+ }
3003+ if (($pureSubscriptions | Measure-Object ).Count -eq 0 )
3004+ {
3005+ throw " No matching subscriptions were found on entered Pure1 organization(s)."
3006+ }
3007+ return $pureSubscriptions
3008+ }
27453009
27463010# internal functions
27473011function Resolve-JWTtoken {
@@ -2882,6 +3146,8 @@ class WindowsPureOneOrganization : PureOneOrganization {
28823146$global :pureOneRateLimit = $null
28833147$global :pureOneRestVersion = " 1.latest"
28843148$Global :PureOneConnections = @ ()
3149+ $Global :PureOneRestUrl = " https://api.pure1.purestorage.com/api"
3150+ $Global :PureOneRestEndpointUrl = " https://api.pure1.purestorage.com/oauth2/1.0/token"
28853151
28863152New-Alias - Name Get-PureOneArrayBusyMeter - Value Get-PureOneArrayLoadMeter
28873153New-Alias - Name New-PureOneRestConnection - Value New-PureOneConnection
0 commit comments