Azure / Azure/azure-powershell
Get-AzCloudServicePublicIPAddress returning nothing despite being visible from portal and other commands
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### Description
I have a Cloud Service (Extended Support) on Azure and want to retrieve the associated public IP address from an Azure script. However when I run
```
Get-AzCloudServicePublicIPAddress -CloudServiceName $serviceName -ResourceGroupName $resourceGroup -verbose
```
Nothing seems to happen at all.
Moreover, when I run a swap command, i.e.
```
Switch-AzCloudService -CloudServiceName $serviceName -ResourceGroupName $resourceGroup -Confirm:$
```
it is successful and I can see the public IP address for both the services in the output logging! Obviously I don't want to have to call this command to retrieve the IP address information. Surely something is wrong with the `Az.CloudService` module here?
### Issue script & Debug output
```PowerShell
DEBUG: Initializing ConditionalAssemblyContext. PSEdition is [Desktop]. PSVersion is [5.1.19041.2364].
DEBUG: Initializing ConditionalAssemblyProvider. AssemblyRootPath is
[C:\Users\{SECRET}\Documents\WindowsPowerShell\Modules\Az.Accounts\2.11.1\StartupScripts\..\lib].
DEBUG: 1:53:01 PM - GetAzureRMContextCommand end processing.
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: [CmdletProcessRecordAsyncStart]: Created new QosEvent for command 'Get-AzCloudServicePublicIPAddress_List'
DEBUG: CmdletProcessRecordAsyncStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated:
/subscriptions/{SECRET}/providers/Microsoft.Compute/clou
dServices/{SECRET}/publicipaddresses?api-version=2021-03-01
DEBUG: RequestCreated:
/subscriptions/{SECRET}/resourceGroups/{SECRET}/providers/Microsoft.Compute/clou
dServices/{SECRET}/publicipaddresses?api-version=2021-03-01
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/{SECRET}/resourceGroups/{SECRET}/prov
iders/Microsoft.Compute/cloudServices/{SECRET}/publicipaddresses?api-version=2021-03-01
Headers:
x-ms-unique-id : 1
x-ms-client-request-id : c745aecf-27c5-4082-9fb7-670016432fce
CommandName : Get-AzCloudServicePublicIPAddress
FullCommandName : Get-AzCloudServicePublicIPAddress_List
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v0.0.0,Az.CloudService/1.1.0
Body:
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Pragma : no-cache
x-ms-request-id : ddcec5fb-637f-475e-b2f5-8605738cf0d7
x-ms-correlation-request-id : 5b0c1cfd-496f-4b9d-bef7-7164cf72fe6a
x-ms-arm-service-request-id : 16d096aa-8d43-46c6-80da-461bf70065b1
Strict-Transport-Security : max-age=31536000; includeSubDomains
Cache-Control : no-cache
Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-routing-request-id : AUSTRALIAEAST:20230127T025303Z:5b0c1cfd-496f-4b9d-bef7-7164cf72fe6a
X-Content-Type-Options : nosniff
Date : Fri, 27 Jan 2023 02:53:02 GMT
Body:
{
"value": []
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.CloudService:1.1.0; CommandName: Get-AzCloudServicePublicIPAddress_List; PSVersion: ;
IsSuccess: True; Duration: 00:00:00
DEBUG: Finish sending metric.
DEBUG: CmdletEndProcessing:
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 5.1.19041.2364
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2364
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
### Module versions
```PowerShell
PS > Get-Module Az*
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.11.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}
Script 1.1.0 Az.CloudService {Get-AzCloudService, Get-AzCloudServiceInstanceView, Get-AzCloudServiceNetworkInterface, Get-AzCloudServiceOSFamily...}
```
### Error output
```PowerShell
PS> Resolve-AzError
DEBUG: Got version 0 of Az
DEBUG: Got version 0 of Az.Accounts
DEBUG: 1:59:35 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 1:59:35 PM - using account id '{SECRET}'...
DEBUG: 1:59:35 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = [].
Returning default value [True].
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use
`Resolve-AzError` instead.
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: -1
Message : Unable to find type [Microsoft.PowerShell.Commands.PowerShellGet.Telemetry].
StackTrace : at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
Exception : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line : $telemetryMethods = ([Microsoft.PowerShell.Commands.PowerShellGet.Telemetry] | Get-Member
-Static).Name
Position : At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:715 char:26
+ ... yMethods = ([Microsoft.PowerShell.Commands.PowerShellGet.Telemetry] | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : -1
DEBUG: AzureQoSEvent: Module: Az.Accounts:2.11.1; CommandName: Resolve-AzError; PSVersion: 5.1.19041.2364; IsSuccess:
True; Duration: 00:00:00.2172790
DEBUG: 1:59:35 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 1:59:35 PM - ResolveError end processing.
```
Contributor guide
Research direction
Start at the Get-AzCloudServicePublicIPAddress entry point and inspect its request to the Microsoft.Compute cloudServices publicipaddresses endpoint, then compare it with the public IP information shown by Switch-AzCloudService. Done means the cmdlet returns the associated public IP address instead of an empty value for the reported Cloud Service (Extended Support) case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, powershell
- Domain
- cli, cloud, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100