Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

ERROR: Get-AzApiManagementProduct : The pipeline has been stopped. when adding api management user in Azure PS Function #12142

Closed aubreyyan closed 2 years ago

aubreyyan commented 4 years ago

Description

I have been trying to automate this sample script in Azure Functions but am running into an error at the Get-AzApiManagementProduct step.

Here is the specific error:

PS C:\Windows\system32> $product = Get-AzApiManagementProduct -Context $context -Title 'Starter' | Select-Object -First 1
Get-AzApiManagementProduct : The pipeline has been stopped.
At line:1 char:12
+ $product = Get-AzApiManagementProduct -Context $context -Title 'Start ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzApiManagementProduct], PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementProduct

ProductId            : starter
Title                : Starter
Description          : Subscribers will be able to run 5 calls/minute up to a maximum of 100 calls/week.
LegalTerms           : 
SubscriptionRequired : True
ApprovalRequired     : False
SubscriptionsLimit   : 1
State                : Published
Id                   : /subscriptions/**********************/resourceGroups/**********************/providers/Microsoft.ApiManagement/service/**********************/products/start
                       er
ResourceGroupName    : **********************
ServiceName          : **********************

Steps to reproduce

I did the following things in Azure:

  1. Provisioned Azure API Management instance

  2. Created service principal following this video https://www.youtube.com/watch?v=Hg-YsUITnck

  3. Ran the following Azure PS scripts in accordance with the aforementioned sample script step by step, with the goal of creating an api management user and returning the user's new subscription key via Azure Functions. Unfortunately, the error surrounding Get-AzApiManagementProduct I'm getting makes that impossible because the broken output trickles down into

$body = New-AzApiManagementSubscription -Context $context -UserId $user.UserId `
        -ProductId $product.ProductId -Name $subscriptionName -State $subscriptionState

which breaks because $product is empty.

*Video of me trying the full Azure Function in my repository

PS C:\Windows\system32> Install-Module -Name AzureAutomationAuthoringToolkit

PS C:\Windows\system32> $userEmail = "test3@gmail.com"

PS C:\Windows\system32> $userFirstName = "Test"

PS C:\Windows\system32> $userLastName = "User"

PS C:\Windows\system32> $userPassword = ConvertTo-SecureString -String "234" -AsPlainText -Force

PS C:\Windows\system32> $userNote = ""

PS C:\Windows\system32> $subscriptionId = "**********************"

PS C:\Windows\system32> $apimServiceName = "**********************"

PS C:\Windows\system32> $resourceGroupName = "**********************"

PS C:\Windows\system32> $userState = "Active"

PS C:\Windows\system32> $subscriptionName = "**********************"

PS C:\Windows\system32> $subscriptionState = "Active"

PS C:\Windows\system32> $User = "**********************"

PS C:\Windows\system32> $PWord = ConvertTo-SecureString -String **********************" -AsPlainText -Force

PS C:\Windows\system32> $tenant = "**********************"

PS C:\Windows\system32> $Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User,$PWord

PS C:\Windows\system32> if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
    Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
      'Az modules installed at the same time is not supported.')
} else {
    Install-Module -Name Az -AllowClobber -Scope CurrentUser
}

PS C:\Windows\system32> Get-ExecutionPolicy
Restricted

PS C:\Windows\system32> Set-ExecutionPolicy -ExecutionPolicy Unrestricted

PS C:\Windows\system32> Import-Module Az.Accounts

PS C:\Windows\system32> Connect-AzAccount -Credential $Credential -Tenant $tenant -ServicePrincipal
WARNING: The provided service principal secret will be included in the 'AzureRmContext.json' file found in the user profile ( C:\Users\Aubrey\.Azure ). Please ensure that
 this directory has appropriate protections.

Account                              SubscriptionName TenantId                             Environment
-------                              ---------------- --------                             -----------
********************** **********************  ********************** AzureCloud 

PS C:\Windows\system32> Select-AzSubscription -SubscriptionId $subscriptionId

Name                                     Account                          SubscriptionName                Environment                     TenantId                       
----                                     -------                          ----------------                -----------                     --------                       
********************** (**********************... **********************... **********************                 AzureCloud                      **********************...

PS C:\Windows\system32> $context = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName

PS C:\Windows\system32> $context

ResourceGroupName ServiceName
----------------- -----------
**********************       ********************** 

PS C:\Windows\system32> $user = New-AzApiManagementUser -Context $context -FirstName $userFirstName -LastName $userLastName `
        -Password $userPassword -State $userState -Note $userNote -Email $userEmail

PS C:\Windows\system32> $user

UserId            : d3938bdc824e4674a1c0b0d159f56638
FirstName         : Test
LastName          : User
Email             : test3@gmail.com
State             : Active
RegistrationDate  : 6/12/2020 9:01:09 PM
Note              : 
Identities        : {[test3@gmail.com, Basic]}
Id                : /subscriptions/**********************/resourceGroups/**********************/providers/Microsoft.ApiManagement/service/**********************/users/**********************
ResourceGroupName : **********************
ServiceName       : **********************

PS C:\Windows\system32> $product = Get-AzApiManagementProduct -Context $context -Title 'Starter' | Select-Object -First 1
Get-AzApiManagementProduct : The pipeline has been stopped.
At line:1 char:12
+ $product = Get-AzApiManagementProduct -Context $context -Title 'Start ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzApiManagementProduct], PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementProduct

ProductId            : starter
Title                : Starter
Description          : Subscribers will be able to run 5 calls/minute up to a maximum of 100 calls/week.
LegalTerms           : 
SubscriptionRequired : True
ApprovalRequired     : False
SubscriptionsLimit   : 1
State                : Published
Id                   : /subscriptions/**********************/resourceGroups/**********************/providers/Microsoft.ApiManagement/service/**********************/products/start
                       er
ResourceGroupName    : **********************
ServiceName          : **********************

PS C:\Windows\system32> $body = New-AzApiManagementSubscription -Context $context -UserId $user.UserId `
        -ProductId $product.ProductId -Name $subscriptionName -State $subscriptionState
New-AzApiManagementSubscription : Cannot validate argument on parameter 'ProductId'. The argument is null or empty. Provide an argument that is not null or empty, and 
then try the command again.
At line:2 char:20
+         -ProductId $product.ProductId -Name $subscriptionName -State  ...
+                    ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-AzApiManagementSubscription], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.NewAzureApiManagementSubscription

PS C:\Windows\system32> $product

PS C:\Windows\system32>

Environment data

PS C:\Windows\system32> $PSVersionTable

Name                           Value                                                                                                                                     
----                           -----                                                                                                                                     
PSVersion                      5.1.17763.1007                                                                                                                            
PSEdition                      Desktop                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                   
BuildVersion                   10.0.17763.1007                                                                                                                           
CLRVersion                     4.0.30319.42000                                                                                                                           
WSManStackVersion              3.0                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                       
SerializationVersion           1.1.0.1

Module versions

PS C:\Windows\system32> Get-Module  -ListAvailable

    Directory: C:\Users\Aubrey\Documents\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                                                                               
---------- -------    ----                                ----------------                                                                                               
Script     1.8.1      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}    
Script     1.1.1      Az.Advisor                          {Get-AzAdvisorRecommendation, Enable-AzAdvisorRecommendation, Disable-AzAdvisorRecommendation, Get-AzAdvisor...
Script     1.1.1      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredential...}                                                
Script     1.1.3      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServicesServer, Remove-AzA...
Script     2.0.1      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion, Add-AzApiMan...
Script     1.1.0      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, Update-AzApplicationIns...
Script     1.3.6      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, I...
Script     3.0.0      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKey, New-AzBatchAccount...}                      
Script     1.0.3      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumptionBudget...}               
Script     1.4.3      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile...}                           
Script     1.4.0      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSku, Get-A...
Script     4.1.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}          
Script     1.0.3      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzContainerGroup, Get-AzContainerInstanceLog}              
Script     1.1.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-AzContainerRegistry...}  
Script     1.1.0      Az.DataBoxEdge                      {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdgeDevice, Invoke-AzDataBoxEdgeDevice, New-AzDataBoxEdgeDevice...}        
Script     1.8.1      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactoryV2...}                  
Script     1.0.2      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-AzDataLakeAnalyticsCata...
Script     1.2.8      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewa...
Script     1.0.0      Az.DataShare                        {New-AzDataShareAccount, Get-AzDataShareAccount, Remove-AzDataShareAccount, New-AzDataShare...}                
Script     1.1.0      Az.DeploymentManager                {Get-AzDeploymentManagerArtifactSource, New-AzDeploymentManagerArtifactSource, Set-AzDeploymentManagerArtifa...
Script     1.0.0      Az.DesktopVirtualization            {Disconnect-AzWvdUserSession, Get-AzWvdApplication, Get-AzWvdApplicationGroup, Get-AzWvdDesktop...}            
Script     1.0.2      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy, Get-AzDtlVMsPerLabPol...
Script     1.1.2      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}                      
Script     1.2.3      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}                 
Script     1.4.3      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzEventHubNamespace...}     
Script     1.5.0      Az.FrontDoor                        {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove-AzFrontDoor...}                                     
Script     1.0.0      Az.Functions                        {Get-AzFunctionApp, Get-AzFunctionAppAvailableLocation, Get-AzFunctionAppPlan, Get-AzFunctionAppSetting...}    
Script     3.2.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDInsightStreamingMapRedu...
Script     1.0.2      Az.HealthcareApis                   {New-AzHealthcareApisService, Remove-AzHealthcareApisService, Set-AzHealthcareApisService, Get-AzHealthcareA...
Script     2.5.0      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}         
Script     2.0.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaul...
Script     1.3.2      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAccountBatchConfigura...
Script     1.1.3      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlanUsageHistory, Remove-A...
Script     1.0.0      Az.Maintenance                      {Get-AzApplyUpdate, Get-AzConfigurationAssignment, Get-AzMaintenanceConfiguration, Get-AzMaintenanceUpdate...} 
Script     1.0.2      Az.ManagedServices                  {Get-AzManagedServicesAssignment, New-AzManagedServicesAssignment, Remove-AzManagedServicesAssignment, Get-A...
Script     1.0.2      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}                                                               
Script     1.1.1      Az.Media                            {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, Get-AzMediaServiceKey, Get-AzMediaServiceNameAvailabi...
Script     2.0.0      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile...}                               
Script     3.0.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-A...
Script     1.1.1      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRule, Get-AzNotificationHubListKey, Get-AzNotifica...
Script     2.1.0      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-...
Script     1.3.1      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}                   
Script     1.1.2      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollectionAcce...
Script     1.0.3      Az.PrivateDns                       {Get-AzPrivateDnsZone, Remove-AzPrivateDnsZone, Set-AzPrivateDnsZone, New-AzPrivateDnsZone...}                 
Script     2.9.1      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile,...
Script     1.2.1      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheScheduleEntry, Get-AzRedisCachePatchSchedule, New-AzRedis...
Script     1.0.3      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNamespace...}                 
Script     2.1.0      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}              
Script     1.4.1      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespa...
Script     2.1.0      Az.ServiceFabric                    {Add-AzServiceFabricClientCertificate, Add-AzServiceFabricClusterCertificate, Add-AzServiceFabricNode, Add-A...
Script     1.1.1      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey...}                                          
Script     2.7.0      Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDa...
Script     1.1.0      Az.SqlVirtualMachine                {New-AzSqlVM, Get-AzSqlVM, Update-AzSqlVM, Remove-AzSqlVM...}                                                  
Script     2.1.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}              
Script     1.2.3      Az.StorageSync                      {Invoke-AzStorageSyncCompatibilityCheck, New-AzStorageSyncService, Get-AzStorageSyncService, Remove-AzStorag...
Script     1.0.1      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefaultFunctionDefinition, New-AzStreamAnalyticsFunctio...
Script     1.0.0      Az.Support                          {Get-AzSupportService, Get-AzSupportProblemClassification, Get-AzSupportTicket, Get-AzSupportTicketCommunica...
Script     1.0.4      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEndpoint, Add-AzTrafficM...
Script     1.9.0      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}                 

    Directory: C:\Users\Aubrey\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell

ModuleType Version    Name                                ExportedCommands                                                                                               
---------- -------    ----                                ----------------                                                                                               
Script     1.0.1.10   GoogleCloud                         {Add-GcsBucketAcl, Get-GcsBucketAcl, Remove-GcsBucketAcl, Add-GcsObjectAcl...}                                 
Script     1.0.1.10   GoogleCloudBeta                     {Get-BqDataset, Set-BqDataset, New-BqDataset, Remove-BqDataset...}                                             

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                                                                               
---------- -------    ----                                ----------------                                                                                               
Script     0.2.4.2    AzureAutomationAuthoringToolkit     {Get-AutomationVariable, Get-AutomationCertificate, Get-AutomationPSCredential, Get-AutomationConnection...}   
Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}                                                          
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}                                         
Script     3.4.0      Pester                              {Describe, Context, It, Should...}                                                                             
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}                                                   
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-PSReadLineOption...}     

    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name                                ExportedCommands                                                                                               
---------- -------    ----                                ----------------                                                                                               
Manifest   1.0.0.0    AppBackgroundTask                   {Disable-AppBackgroundTaskDiagnosticLog, Enable-AppBackgroundTaskDiagnosticLog, Set-AppBackgroundTaskResourc...
Manifest   2.0.1.0    Appx                                {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageManifest, Remove-AppxPackage...}                             
Manifest   1.0.0.0    BitLocker                           {Unlock-BitLocker, Suspend-BitLocker, Resume-BitLocker, Remove-BitLockerKeyProtector...}                       
Manifest   2.0.0.0    BitsTransfer                        {Add-BitsFile, Complete-BitsTransfer, Get-BitsTransfer, Remove-BitsTransfer...}                                
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, Get-CimSession...}                                  
Manifest   1.0        Defender                            {Get-MpPreference, Set-MpPreference, Add-MpPreference, Remove-MpPreference...}                                 
Manifest   1.0.1.0    DeliveryOptimization                {Get-DeliveryOptimizationStatus, Get-DeliveryOptimizationPerfSnap, Get-DeliveryOptimizationLog, Get-DOConfig...
Manifest   1.0.0.0    DirectAccessClientComponents        {Disable-DAManualEntryPointSelection, Enable-DAManualEntryPointSelection, Get-DAClientExperienceConfiguratio...
Script     3.0        Dism                                {Add-AppxProvisionedPackage, Add-WindowsDriver, Add-WindowsCapability, Add-WindowsImage...}                    
Manifest   1.0.0.0    DnsClient                           {Resolve-DnsName, Clear-DnsClientCache, Get-DnsClient, Get-DnsClientCache...}                                  
Manifest   1.0.0.0    EventTracingManagement              {Start-EtwTraceSession, New-EtwTraceSession, Get-EtwTraceSession, Update-EtwTraceSession...}                   
Manifest   2.0.0.0    International                       {Get-WinDefaultInputMethodOverride, Set-WinDefaultInputMethodOverride, Get-WinHomeLocation, Set-WinHomeLocat...
Manifest   1.0.0.0    iSCSI                               {Get-IscsiTargetPortal, New-IscsiTargetPortal, Remove-IscsiTargetPortal, Update-IscsiTargetPortal...}          
Script     1.0.0.0    ISE                                 {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}                                                            
Manifest   1.0.0.0    Kds                                 {Add-KdsRootKey, Get-KdsRootKey, Test-KdsRootKey, Set-KdsConfiguration...}                                     
Manifest   1.0.1.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}                                                                             
Manifest   3.0.0.0    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...}                                                 
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}                                                                            
Manifest   1.0.0.0    Microsoft.PowerShell.LocalAccounts  {Add-LocalGroupMember, Disable-LocalUser, Enable-LocalUser, Get-LocalGroup...}                                 
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}                                                 
Script     1.0        Microsoft.PowerShell.ODataUtils     Export-ODataEndpointProxy                                                                                      
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...}                                                      
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}                                                     
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSSP, Set-WSManQuickConfig...}                         
Manifest   1.0        MMAgent                             {Disable-MMAgent, Enable-MMAgent, Set-MMAgent, Get-MMAgent...}                                                 
Manifest   1.0.0.0    MsDtc                               {New-DtcDiagnosticTransaction, Complete-DtcDiagnosticTransaction, Join-DtcDiagnosticResourceManager, Receive...
Manifest   2.0.0.0    NetAdapter                          {Disable-NetAdapter, Disable-NetAdapterBinding, Disable-NetAdapterChecksumOffload, Disable-NetAdapterEncapsu...
Manifest   1.0.0.0    NetConnection                       {Get-NetConnectionProfile, Set-NetConnectionProfile}                                                           
Manifest   1.0.0.0    NetDiagnostics                      Get-NetView                                                                                                    
Manifest   1.0.0.0    NetEventPacketCapture               {New-NetEventSession, Remove-NetEventSession, Get-NetEventSession, Set-NetEventSession...}                     
Manifest   2.0.0.0    NetLbfo                             {Add-NetLbfoTeamMember, Add-NetLbfoTeamNic, Get-NetLbfoTeam, Get-NetLbfoTeamMember...}                         
Manifest   1.0.0.0    NetNat                              {Get-NetNat, Get-NetNatExternalAddress, Get-NetNatStaticMapping, Get-NetNatSession...}                         
Manifest   2.0.0.0    NetQos                              {Get-NetQosPolicy, Set-NetQosPolicy, Remove-NetQosPolicy, New-NetQosPolicy}                                    
Manifest   2.0.0.0    NetSecurity                         {Get-DAPolicyChange, New-NetIPsecAuthProposal, New-NetIPsecMainModeCryptoProposal, New-NetIPsecQuickModeCryp...
Manifest   1.0.0.0    NetSwitchTeam                       {New-NetSwitchTeam, Remove-NetSwitchTeam, Get-NetSwitchTeam, Rename-NetSwitchTeam...}                          
Manifest   1.0.0.0    NetTCPIP                            {Get-NetIPAddress, Get-NetIPInterface, Get-NetIPv4Protocol, Get-NetIPv6Protocol...}                            
Manifest   1.0.0.0    NetworkConnectivityStatus           {Get-DAConnectionStatus, Get-NCSIPolicyConfiguration, Reset-NCSIPolicyConfiguration, Set-NCSIPolicyConfigura...
Manifest   1.0.0.0    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEthernetPort, Get-NetworkSwitchEthernetPort, Remove-...
Manifest   1.0.0.0    NetworkTransition                   {Add-NetIPHttpsCertBinding, Disable-NetDnsTransitionConfiguration, Disable-NetIPHttpsProfile, Disable-NetNat...
Manifest   1.0.0.0    PcsvDevice                          {Get-PcsvDevice, Start-PcsvDevice, Stop-PcsvDevice, Restart-PcsvDevice...}                                     
Binary     1.0.0.0    PersistentMemory                    {Get-PmemDisk, Get-PmemPhysicalDevice, Get-PmemUnusedRegion, New-PmemDisk...}                                  
Manifest   1.0.0.0    PKI                                 {Add-CertificateEnrollmentPolicyServer, Export-Certificate, Export-PfxCertificate, Get-CertificateAutoEnroll...
Manifest   1.0.0.0    PnpDevice                           {Get-PnpDevice, Get-PnpDeviceProperty, Enable-PnpDevice, Disable-PnpDevice}                                    
Manifest   1.1        PrintManagement                     {Add-Printer, Add-PrinterDriver, Add-PrinterPort, Get-PrintConfiguration...}                                   
Binary     1.0.11     ProcessMitigations                  {Get-ProcessMitigation, Set-ProcessMitigation, ConvertTo-ProcessMitigationPolicy}                              
Script     3.0        Provisioning                        {Install-ProvisioningPackage, Export-ProvisioningPackage, Install-TrustedProvisioningCertificate, Export-Tra...
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration, Test-DscConfiguration, Publish-DscConfiguration...} 
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSManTrace, Enable-PSTrace...}                         
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-JobTrigger...}                                         
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}                                                   
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow                                                                                              
Manifest   1.0.0.0    ScheduledTasks                      {Get-ScheduledTask, Set-ScheduledTask, Register-ScheduledTask, Unregister-ScheduledTask...}                    
Manifest   2.0.0.0    SecureBoot                          {Confirm-SecureBootUEFI, Set-SecureBootUEFI, Get-SecureBootUEFI, Format-SecureBootUEFI...}                     
Manifest   2.0.0.0    SmbShare                            {Get-SmbShare, Remove-SmbShare, Set-SmbShare, Block-SmbShareAccess...}                                         
Manifest   2.0.0.0    SmbWitness                          {Get-SmbWitnessClient, Move-SmbWitnessClient, gsmbw, msmbw...}                                                 
Manifest   1.0.0.0    StartLayout                         {Export-StartLayout, Import-StartLayout, Export-StartLayoutEdgeAssets, Get-StartApps}                          
Manifest   2.0.0.0    Storage                             {Add-InitiatorIdToMaskingSet, Add-PartitionAccessPath, Add-PhysicalDisk, Add-StorageFaultDomain...}            
Manifest   1.0.0.0    StorageBusCache                     {Clear-StorageBusDisk, Disable-StorageBusCache, Disable-StorageBusDisk, Enable-StorageBusCache...}             
Manifest   2.0.0.0    TLS                                 {New-TlsSessionTicketKey, Enable-TlsSessionTicketKey, Disable-TlsSessionTicketKey, Export-TlsSessionTicketKe...
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}                                                          
Manifest   2.0.0.0    TrustedPlatformModule               {Get-Tpm, Initialize-Tpm, Clear-Tpm, Unblock-Tpm...}                                                           
Manifest   2.0.0.0    VpnClient                           {Add-VpnConnection, Set-VpnConnection, Remove-VpnConnection, Get-VpnConnection...}                             
Manifest   1.0.0.0    Wdac                                {Get-OdbcDriver, Set-OdbcDriver, Get-OdbcDsn, Add-OdbcDsn...}                                                  
Manifest   1.0.0.0    WindowsDeveloperLicense             {Get-WindowsDeveloperLicense, Unregister-WindowsDeveloperLicense, Show-WindowsDeveloperLicenseRegistration}    
Script     1.0        WindowsErrorReporting               {Enable-WindowsErrorReporting, Disable-WindowsErrorReporting, Get-WindowsErrorReporting}                       
Manifest   1.0.0.0    WindowsSearch                       {Get-WindowsSearchSetting, Set-WindowsSearchSetting}                                                           
Manifest   1.0.0.0    WindowsUpdate                       Get-WindowsUpdateLog                                                                                           
Manifest   1.0.0.2    WindowsUpdateProvider               {Get-WUAVersion, Get-WULastInstallationDate, Get-WULastScanSuccessDate, Get-WUIsPendingReboot...}  

Debug output

PS C:\Windows\system32> $DebugPreference='Continue'

PS C:\Windows\system32> $product = Get-AzApiManagementProduct -Context $context -Title 'Starter' | Select-Object -First 1
DEBUG: 2:43:08 PM - GetAzureApiManagementProduct begin processing with ParameterSet 'GetByTitle'.
DEBUG: 2:43:08 PM - using account id 'b482e878-bebf-489e-bfcb-0f18fd159a67'...
DEBUG: [Common.Authentication]: Authenticating using Account: 'b482e878-bebf-489e-bfcb-0f18fd159a67', environment: 'AzureCloud', tenant: '7225aaa4-1295-4698-838d-f087e1bb
6ad5'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '7225aaa4-1295-4698-838d-f087e1bb6ad5', Endpoint: 'https://login.microsoftonline.com/',
 ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthori
ty: 'True'
DEBUG: [Common.Authentication]: Renewing token using AppId: 'b482e878-bebf-489e-bfcb-0f18fd159a67', AdalConfiguration with ADDomain: '7225aaa4-1295-4698-838d-f087e1bb6ad5
', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', RedirectUri: 'urn:ietf:wg:oauth:2.0:oob'
DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6487179Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: ADAL PCL.Desktop with assembly version '3.19.2.6005', file
 version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6487179Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: ADAL PCL.Desktop with assembly version '3.19.2.6005', file
 version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6487179Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: === Token Acquisition started: 
    CacheType: null
    Authentication Target: Client
    , Authority Host: login.microsoftonline.com

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6487179Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: === Token Acquisition started:
    Authority: https://login.microsoftonline.com/7225aaa4-1295-4698-838d-f087e1bb6ad5/
    Resource: https://management.core.windows.net/
    ClientId: b482e878-bebf-489e-bfcb-0f18fd159a67
    CacheType: null
    Authentication Target: Client

DEBUG: [ADAL]: Verbose: 2020-06-13T18:43:08.6487179Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Verbose: 2020-06-13T18:43:08.6487179Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 3 items to token cache.

DEBUG: [ADAL]: Verbose: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: An item matching the requested resource was found in the c
ache

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: An item matching the requested resource was found in the c
ache

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: 58.6558043983333 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: 58.6558043983333 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: A matching item (access token or refresh token or both) wa
s found in the cache

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6497361Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: A matching item (access token or refresh token or both) wa
s found in the cache

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6502056Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: === Token Acquisition finished successfully. An access tok
en was returned: Expiration Time: 6/13/2020 7:41:47 PM +00:00

DEBUG: [ADAL]: Information: 2020-06-13T18:43:08.6502056Z: dec15588-27be-43e3-bca1-e2134c51bbe3 - LoggerBase.cs: === Token Acquisition finished successfully. An access tok
en was returned: Expiration Time: 6/13/2020 7:41:47 PM +00:00Access Token Hash: Io+iefn6AoLjQvzL233PkJBdyozoSragnU7NhRDGceo=
     User id: 

DEBUG: [Common.Authentication]: Checking token expiration, token expires '06/13/2020 19:41:47 +00:00' Comparing to '06/13/2020 18:43:08 +00:00' With threshold '00:05:00',
 calculated time until token expiry: '00:58:39.3462505'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/2ad243e6-49d4-4a01-a5c9-7fef5b3a6e46/resourceGroups/gatech-rsrc/providers/Microsoft.ApiManagement/service/gatech-api/products?$
filter=properties/displayName eq 'Starter'&api-version=2019-12-01

Headers:
x-ms-client-request-id        : 2f2e2b23-01de-49f6-8d21-2833b396f9b3
accept-language               : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : 9e74bedf-310d-407b-9fad-0b4148efa6ab
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-correlation-request-id   : c88f30f5-afa4-408b-9a5b-9d087cfa75d3
x-ms-routing-request-id       : CANADACENTRAL:20200613T184316Z:c88f30f5-afa4-408b-9a5b-9d087cfa75d3
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Sat, 13 Jun 2020 18:43:16 GMT
Server                        : Microsoft-HTTPAPI/2.0

Body:
{
  "value": [
    {
      "id": "/subscriptions/2ad243e6-49d4-4a01-a5c9-7fef5b3a6e46/resourceGroups/gatech-rsrc/providers/Microsoft.ApiManagement/service/gatech-api/products/starter",
      "type": "Microsoft.ApiManagement/service/products",
      "name": "starter",
      "properties": {
        "displayName": "Starter",
        "description": "Subscribers will be able to run 5 calls/minute up to a maximum of 100 calls/week.",
        "terms": "",
        "subscriptionRequired": true,
        "approvalRequired": false,
        "subscriptionsLimit": 1,
        "state": "published"
      }
    }
  ],
  "count": 1
}

Get-AzApiManagementProduct : The pipeline has been stopped.
At line:1 char:12
+ $product = Get-AzApiManagementProduct -Context $context -Title 'Start ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzApiManagementProduct], PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementProduct

DEBUG: AzureQoSEvent: CommandName - Get-AzApiManagementProduct; IsSuccess - False; Duration - 00:00:00.6149827;; Exception - System.Management.Automation.PipelineStoppedE
xception: The pipeline has been stopped.
   at System.Management.Automation.CommandProcessor.ProcessRecord()
   at System.Management.Automation.CommandProcessorBase.DoExecute()
   at System.Management.Automation.Internal.Pipe.AddToPipe(Object obj)
   at System.Management.Automation.Internal.Pipe.AddItems(Object objects)
   at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
   at System.Management.Automation.MshCommandRuntime.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
   at System.Management.Automation.Cmdlet.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
   at Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementProduct.ExecuteApiManagementCmdlet()
   at Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.AzureApiManagementCmdletBase.ExecuteCmdlet();
DEBUG: Finish sending metric.
DEBUG: 2:43:09 PM - GetAzureApiManagementProduct end processing.

ProductId            : starter
Title                : Starter
Description          : Subscribers will be able to run 5 calls/minute up to a maximum of 100 calls/week.
LegalTerms           : 
SubscriptionRequired : True
ApprovalRequired     : False
SubscriptionsLimit   : 1
State                : Published
Id                   : /subscriptions/2ad243e6-49d4-4a01-a5c9-7fef5b3a6e46/resourceGroups/gatech-rsrc/providers/Microsoft.ApiManagement/service/gatech-api/products/start
                       er
ResourceGroupName    : gatech-rsrc
ServiceName          : gatech-api

Error output

PS C:\Windows\system32> Resolve-AzError -Last
WARNING: Breaking changes in the cmdlet 'Resolve-AzError' :
WARNING:  - The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.

WARNING: NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell
.

   HistoryId: 36

Message        : The pipeline has been stopped.
StackTrace     :    at System.Management.Automation.CommandProcessor.ProcessRecord()
                    at System.Management.Automation.CommandProcessorBase.DoExecute()
                    at System.Management.Automation.Internal.Pipe.AddToPipe(Object obj)
                    at System.Management.Automation.Internal.Pipe.AddItems(Object objects)
                    at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
                    at System.Management.Automation.MshCommandRuntime.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
                    at System.Management.Automation.Cmdlet.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
                    at Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementProduct.ExecuteApiManagementCmdlet()
                    at Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.AzureApiManagementCmdletBase.ExecuteCmdlet()
Exception      : System.Management.Automation.PipelineStoppedException
InvocationInfo : {Get-AzApiManagementProduct}
Line           : $product = Get-AzApiManagementProduct -Context $context -Title 'Starter' | Select-Object -First 1
Position       : At line:1 char:12
                 + $product = Get-AzApiManagementProduct -Context $context -Title 'Start ...
                 +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 36

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
aubreyyan commented 4 years ago

Update: Someone came up with a solution on stack overflow: https://stackoverflow.com/a/62381496/8652920

Wrt next steps, if this isn't just a localized problem that I'm facing, it would be helpful to update the "Add a user" documentation that was linked initially.

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @miaojiang.

dingmeng-xue commented 4 years ago

API management team, please help to look into this question.

SaurabhSharma-MSFT commented 3 years ago

@aubrey-y Apologies for the delayed response. I see that this issue is opened long time ago and no further activity had taken place. So wanted to check if you are still looking for assistance on this query? Please let us know .

ghost commented 3 years ago

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

aubreyyan commented 3 years ago

@aubrey-y Apologies for the delayed response. I see that this issue is opened long time ago and no further activity had taken place. So wanted to check if you are still looking for assistance on this query? Please let us know .

your documentation is inaccurate, see the stack overflow post

navba-MSFT commented 2 years ago

@aubrey-y Apologies for the late reply. Thanks for raising this issue. We have filed a PR #17149 to include an example as mentioned in your comment. In the meantime, if you have any questions on this, do let us know. We could be happy to help. Awaiting your reply.