Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.15k stars 3.78k forks source link

[Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof' #21175

Open BorysMariusz opened 1 year ago

BorysMariusz commented 1 year ago

Description

I got issue with working with the PowerShell script, no matter if it is created in local or in runbook. I try to clean images from image gallery. When the definition has only one version of image, I can not use .indexof method. I am using the indexof method to check which image is the latest as there is no such info in PowerShell or azure cli output.

Issue script & Debug output

Gathering versions for VM Image definition: ubuntu2004-ado-agent
DEBUG: 1:55:12 PM - GetAzureRmGalleryImageVersion begin processing with ParameterSet 'DefaultParameter'.
DEBUG: 1:55:12 PM - using account id ''...
DEBUG: 1:55:12 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: '', environment: 'AzureCloud', tenant: ''
DEBUG: 1:55:12 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:''
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: 
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] [Region discovery] Not using a regional authority. 
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] [Region discovery] Not using a regional authority. 
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] [Region discovery] Not using a regional authority. 
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] [WamBroker] Not a Win10 machine. WAM is not available
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] NullBroker - acting as not installed.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] Found 2 cache accounts and 0 broker accounts
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] Returning 2 accounts
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] MSAL MSAL.NetCore with assembly version '4.49.1.0'. CorrelationId(bac76d56-6619-41e7-b60b-a66b1bb2c8c8)
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] === AcquireTokenSilent Parameters ===
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] LoginHint provided: False
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] Account provided: True
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] ForceRefresh: False
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] 
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) - 
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - True
HomeAccountId - False
CorrelationId - bac76d56-6619-41e7-b60b-a66b1bb2c8c8
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured: 

DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] === Token Acquisition (SilentRequest) started:
         Scopes: https://management.core.windows.net//.default
        Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] [Region discovery] Not using a regional authority. 
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] Access token is not expired. Returning the found cache entry. [Current time (03/10/2023 12:55:12) - Expiration Time (03/10/2023 13:48:54 +00:00) - Extended Expiration Time (03/10/2023 13:48:54 +00:00)]
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] [Region discovery] Not using a regional authority. 
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] 
        === Token Acquisition finished successfully:
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8]  AT expiration time: 3/10/2023 1:48:54 PM +00:00, scopes: https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:  ExpiresOn: 2023-03-10T13:48:54.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '', UserId: ''
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions//resourceGroups/APP518-SIG-PROD-EASTUS2/providers/Microsoft.Compute/galleries/CeridianAppImageGallery/images/ubuntu2004-ado-agent/versions?api-version=2022-03-03

Headers:
Accept-Language               : en-US
x-ms-client-request-id        : 825ff512-5764-4435-8ff8-300ec4ba74db

Body:

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

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-ratelimit-remaining-resource: Microsoft.Compute/ListGalleryImageVersionsInGalleryImage3Min;1498,Microsoft.Compute/ListGalleryImageVersionsInGalleryImage30Min;9956
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-served-by                : f5a9e422-7cdc-4ee9-8efd-7f400c4a0f17_133180968507091114,f5a9e422-7cdc-4ee9-8efd-7f400c4a0f17_133180968507091114
x-ms-request-id               : 4594ec7d-3db2-4165-8af1-b0aba825f2e3
Server                        : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11996
x-ms-correlation-request-id   : 13eb8741-2d60-4822-8c41-bc247baaf4a9
x-ms-routing-request-id       : GERMANYNORTH:20230310T125513Z:13eb8741-2d60-4822-8c41-bc247baaf4a9
X-Content-Type-Options        : nosniff
Date                          : Fri, 10 Mar 2023 12:55:12 GMT

Body:
{
  "value": [
    {
      "name": "2023.01.272239",
      "id": "/subscriptions//resourceGroups/APP518-SIG-PROD-EASTUS2/providers/Microsoft.Compute/galleries/CeridianAppImageGallery/images/ubuntu2004-ado-agent/versions/2023.01.272239",
      "type": "Microsoft.Compute/galleries/images/versions",
      "location": "eastus2",
      "tags": {
        "creationdate": "20230127223904",
        "creator": "ado",
        "environment": "np",
        "ostype": "linux",
        "source": "packer",
        "BillTo": "P&T"
      },
      "properties": {
        "publishingProfile": {
          "targetRegions": [
            {
              "name": "East US 2",
              "regionalReplicaCount": 1,
              "storageAccountType": "Standard_LRS"
            }
          ],
          "replicaCount": 1,
          "excludeFromLatest": false,
          "publishedDate": "2023-01-27T23:48:40.3301357+01:00",
          "storageAccountType": "Standard_LRS"
        },
        "storageProfile": {
          "source": {
            "id": "/subscriptions//resourceGroups/a/providers/Microsoft.Compute/images/CERIDIAN-ubuntu2004-ceridian-adoagent-202301272239"
          },
          "osDiskImage": {
            "sizeInGB": 30,
            "hostCaching": "ReadWrite",
            "source": {}
          }
        },
        "safetyProfile": {
          "reportedForPolicyViolation": false,
          "allowDeletionOfReplicatedLocations": true
        },
        "provisioningState": "Succeeded"
      }
    }
  ]
}

DEBUG: AzureQoSEvent:  Module: Az.Compute:5.4.0; CommandName: Get-AzGalleryImageVersion; PSVersion: 7.3.3; IsSuccess: True; Duration: 00:00:01.0198593
DEBUG: 1:55:13 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:55:13 PM - GetAzureRmGalleryImageVersion end processing.
1
I am here 2023.01.272239 of ubuntu2004-ado-agent
InvalidOperation: /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66:21
Line |
  66 |  …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.11.2                Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     5.4.0                 Az.Compute                          {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk…}

Error output

PS /Users/mariuszborys/azurerepos> Resolve-AzError
DEBUG: 1:57:59 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 1:57:59 PM - using account id ''...
DEBUG: 1:57:59 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        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at lambda_method3151(Closure, Object[], StrongBox`1[], InterpretedFrame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at lambda_method3151(Closure, Object[], StrongBox`1[], InterpretedFrame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at lambda_method3151(Closure, Object[], StrongBox`1[], InterpretedFrame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'.
StackTrace     :    at CallSite.Target(Closure, CallSite, Object, Object)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {

Position       : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21
                 + …         if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

DEBUG: AzureQoSEvent:  Module: Az.Accounts:2.11.2; CommandName: Resolve-AzError; PSVersion: 7.3.3; IsSuccess: True; Duration: 00:00:00.0216611
DEBUG: 1:57:59 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:57:59 PM - ResolveError end processing.
isra-fel commented 1 year ago

Thanks for reporting! Is it possible to share the script (be sure to remove any sensitive data before posting)?

BorysMariusz commented 1 year ago

Yes, should I post it here in the issue ?

BorysMariusz commented 1 year ago

Connect to AZ P0 account

$accessToken = Get-AzAccessToken -ErrorAction SilentlyContinue

check if AZ connection already established

if (!($accessToken )) { Connect-AzAccount }

loop through all subscriptions

Write-Output "Set AZ Context to $AzSubscription" try { $Context = Set-AzContext -Subscription $azsub -ErrorAction Stop } catch { Write-Output "Could not set AZ Context. Error message is: $($_.exception.message)" exit }

collect az galleries

try { $AzGallery = Get-AzGallery -ErrorAction Stop } catch { Write-Output "Could not collect AZ Galleries. Error message is: $($_.exception.message)" exit }

loop through galleries

foreach ($AzGal in $AzGallery) { Write-Output "Gathering Gallery Image Definitions from Azure Gallery name: $($AzGal.Name)" $AzGaldefinitioninfo = Get-AzGalleryImageDefinition -GalleryName $AzGal.Name -ResourceGroupName $AzGal.ResourceGroupName

foreach ($AzGalDefName in $AzGaldefinitioninfo.Name) {
    Write-Output "Gathering versions for VM Image definition: $AzGalDefName"
    # gather versions of the image sorted
    $AzGalDefImageVersions = Get-AzGalleryImageVersion -GalleryName $AzGal.Name -ResourceGroupName $AzGal.ResourceGroupName -GalleryImageDefinitionName $AzGalDefName | Sort-Object -Property Name -Descending # sort for keeping the latest

    # variables to check how many image versions is in the Gallery definition
    $AzGalDefImageVersionsCounter = $AzGalDefImageVersions.count
    $AzGalDefImageVersionsCounter

    if ($AzGalDefImageVersionsCounter -gt 0) {

        # loop through version numbers and check the target repliaction location
        Foreach ($ImageVersion in $AzGalDefImageVersions ) {

            write-output "I am here $($ImageVersion.name) of $AzGalDefName"

            $targetRegionCount = $ImageVersion.PublishingProfile.TargetRegions.count
            #Write-Output "Version: $($ImageVersion.Name) is published on $targetRegionCount regions"
            if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) {
                write-output "Latest element is replicated correctly between $targetRegionCount regions. "
            } elseif (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -lt 8)) {
                Write-Output "Latest version is not replicated correctly. More regions will be added."
                $region1 = @{Name='East US 2';ReplicaCount=1}
                $region2 = @{Name='Central US';ReplicaCount=1}
                $region3 = @{Name='West Europe';ReplicaCount=1}
                $region4 = @{Name='North Europe';ReplicaCount=1}
                $region5 = @{Name='Australia East';ReplicaCount=1}
                $region6 = @{Name='Australia Southeast';ReplicaCount=1}
                $region7 = @{Name='Canada Central';ReplicaCount=1}
                $region8 = @{Name='Canada East';ReplicaCount=1}
                $targetRegions = @($region1,$region2,$region3,$region4,$region5,$region6,$region7,$region8)
                #Update-AzGalleryImageVersion -ResourceGroupName $AzGal.ResourceGroupName -GalleryName $AzGal.Name -GalleryImageDefinitionName $AzGalDefName -Name $ImageVersion.Name -ReplicaCount 1 -TargetRegion $targetRegions -AsJob -WhatIf
            } elseif  ($targetRegionCount -gt 1 ){
                Write-Output "Version $($ImageVersion.Name) is not latest, has more then one replica. Replicated regions will be set only for East US 2"
                $region1 = @{Name='East US 2';ReplicaCount=1}
                $targetRegions = @($region1)
                #Update-AzGalleryImageVersion -ResourceGroupName $AzGal.ResourceGroupName -GalleryName $AzGal.Name -GalleryImageDefinitionName $AzGalDefName -Name $ImageVersion.Name -ReplicaCount 1 -TargetRegion $targetRegions -AsJob -WhatIf
            } else {
                Write-Output "Version $($ImageVersion.Name) is published corectly on $targetRegionCount region"  
            }
            Write-Output "-------------------------------------------------------------------------------------------------------"
        }
        Write-Output "################################# IMAGE VERSION #################################################"
    } else {
        Write-Output "VM Image definition: $AzGalDefName has no versions"
    }
    Write-Output "################################# AZ GEL DEFINITION NAME #################################################"
}

}

From what I understand if the variable $AzGalDefImageVersionsCounter has only one item, (image version) the "INDEXOF" method does not exists. When it has more then one item it is ok. I have checked the get-member output for both of them regardles the amount of image version (zero, one or more items) the Type is the same: Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList

BorysMariusz commented 1 year ago

Any update ?

isra-fel commented 1 year ago

Sorry for late reponse. Let me loop in compute team.

IMO it looks related to the PowerShell design that a cmdlet can return one or more objects. I can think of two potential ways to work around it, first is to handle the case where it returns exactly one object seperately; second is to use piping, e.g. Get-AzGalleryImageVersion | Foreach-Object { ... }

ghost commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Drewm3, @TravisCragg-MSFT, @nikhilpatel909, @sandeepraichura, @hilaryw29, @GabstaMSFT, @ramankumarlive, @ushnaarshadkhan.

Issue Details
### Description I got issue with working with the PowerShell script, no matter if it is created in local or in runbook. I try to clean images from image gallery. When the definition has only one version of image, I can not use .indexof method. I am using the indexof method to check which image is the latest as there is no such info in PowerShell or azure cli output. ### Issue script & Debug output ```PowerShell Gathering versions for VM Image definition: ubuntu2004-ado-agent DEBUG: 1:55:12 PM - GetAzureRmGalleryImageVersion begin processing with ParameterSet 'DefaultParameter'. DEBUG: 1:55:12 PM - using account id ''... DEBUG: 1:55:12 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: [Common.Authentication]: Authenticating using Account: '', environment: 'AzureCloud', tenant: '' DEBUG: 1:55:12 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'' DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] IsLegacyAdalCacheEnabled: yes DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] IsLegacyAdalCacheEnabled: yes DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - 59314f38-bc9b-4f54-bbbf-8d47fd974f38] IsLegacyAdalCacheEnabled: yes DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] [WamBroker] Not a Win10 machine. WAM is not available DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] NullBroker - acting as not installed. DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] Found 2 cache accounts and 0 broker accounts DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z] Returning 2 accounts DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] MSAL MSAL.NetCore with assembly version '4.49.1.0'. CorrelationId(bac76d56-6619-41e7-b60b-a66b1bb2c8c8) DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] === AcquireTokenSilent Parameters === DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] LoginHint provided: False DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] Account provided: True DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] ForceRefresh: False DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] === Request Data === Authority Provided? - True Scopes - https://management.core.windows.net//.default Extra Query Params Keys (space separated) - ApiId - AcquireTokenSilent IsConfidentialClient - False SendX5C - False LoginHint ? False IsBrokerConfigured - True HomeAccountId - False CorrelationId - bac76d56-6619-41e7-b60b-a66b1bb2c8c8 UserAssertion set: False LongRunningOboCacheKey set: False Region configured: DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] === Token Acquisition (SilentRequest) started: Scopes: https://management.core.windows.net//.default Authority Host: login.microsoftonline.com DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] Access token is not expired. Returning the found cache entry. [Current time (03/10/2023 12:55:12) - Expiration Time (03/10/2023 13:48:54 +00:00) - Extended Expiration Time (03/10/2023 13:48:54 +00:00)] DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] Returning access token found in cache. RefreshOn exists ? False DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] === Token Acquisition finished successfully: DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.3 Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 [2023-03-10 12:55:12Z - bac76d56-6619-41e7-b60b-a66b1bb2c8c8] AT expiration time: 3/10/2023 1:48:54 PM +00:00, scopes: https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default. source: Cache DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2023-03-10T13:48:54.0000000+00:00 DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '', UserId: '' DEBUG: ============================ HTTP REQUEST ============================ HTTP Method: GET Absolute Uri: https://management.azure.com/subscriptions//resourceGroups/APP518-SIG-PROD-EASTUS2/providers/Microsoft.Compute/galleries/CeridianAppImageGallery/images/ubuntu2004-ado-agent/versions?api-version=2022-03-03 Headers: Accept-Language : en-US x-ms-client-request-id : 825ff512-5764-4435-8ff8-300ec4ba74db Body: DEBUG: ============================ HTTP RESPONSE ============================ Status Code: OK Headers: Cache-Control : no-cache Pragma : no-cache x-ms-ratelimit-remaining-resource: Microsoft.Compute/ListGalleryImageVersionsInGalleryImage3Min;1498,Microsoft.Compute/ListGalleryImageVersionsInGalleryImage30Min;9956 Strict-Transport-Security : max-age=31536000; includeSubDomains x-ms-served-by : f5a9e422-7cdc-4ee9-8efd-7f400c4a0f17_133180968507091114,f5a9e422-7cdc-4ee9-8efd-7f400c4a0f17_133180968507091114 x-ms-request-id : 4594ec7d-3db2-4165-8af1-b0aba825f2e3 Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0 x-ms-ratelimit-remaining-subscription-reads: 11996 x-ms-correlation-request-id : 13eb8741-2d60-4822-8c41-bc247baaf4a9 x-ms-routing-request-id : GERMANYNORTH:20230310T125513Z:13eb8741-2d60-4822-8c41-bc247baaf4a9 X-Content-Type-Options : nosniff Date : Fri, 10 Mar 2023 12:55:12 GMT Body: { "value": [ { "name": "2023.01.272239", "id": "/subscriptions//resourceGroups/APP518-SIG-PROD-EASTUS2/providers/Microsoft.Compute/galleries/CeridianAppImageGallery/images/ubuntu2004-ado-agent/versions/2023.01.272239", "type": "Microsoft.Compute/galleries/images/versions", "location": "eastus2", "tags": { "creationdate": "20230127223904", "creator": "ado", "environment": "np", "ostype": "linux", "source": "packer", "BillTo": "P&T" }, "properties": { "publishingProfile": { "targetRegions": [ { "name": "East US 2", "regionalReplicaCount": 1, "storageAccountType": "Standard_LRS" } ], "replicaCount": 1, "excludeFromLatest": false, "publishedDate": "2023-01-27T23:48:40.3301357+01:00", "storageAccountType": "Standard_LRS" }, "storageProfile": { "source": { "id": "/subscriptions//resourceGroups/a/providers/Microsoft.Compute/images/CERIDIAN-ubuntu2004-ceridian-adoagent-202301272239" }, "osDiskImage": { "sizeInGB": 30, "hostCaching": "ReadWrite", "source": {} } }, "safetyProfile": { "reportedForPolicyViolation": false, "allowDeletionOfReplicatedLocations": true }, "provisioningState": "Succeeded" } } ] } DEBUG: AzureQoSEvent: Module: Az.Compute:5.4.0; CommandName: Get-AzGalleryImageVersion; PSVersion: 7.3.3; IsSuccess: True; Duration: 00:00:01.0198593 DEBUG: 1:55:13 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: 1:55:13 PM - GetAzureRmGalleryImageVersion end processing. 1 I am here 2023.01.272239 of ubuntu2004-ado-agent InvalidOperation: /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66:21 Line | 66 | … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. ``` ### Environment data ```PowerShell Name Value ---- ----- PSVersion 7.3.3 PSEdition Core GitCommitId 7.3.3 OS Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 ``` ### Module versions ```PowerShell ModuleType Version PreRelease Name ExportedCommands ---------- ------- ---------- ---- ---------------- Script 2.11.2 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…} Script 5.4.0 Az.Compute {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk…} ``` ### Error output ```PowerShell PS /Users/mariuszborys/azurerepos> Resolve-AzError DEBUG: 1:57:59 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'. DEBUG: 1:57:59 PM - using account id ''... DEBUG: 1:57:59 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 : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at lambda_method3151(Closure, Object[], StrongBox`1[], InterpretedFrame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at lambda_method3151(Closure, Object[], StrongBox`1[], InterpretedFrame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at lambda_method3151(Closure, Object[], StrongBox`1[], InterpretedFrame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:66 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 Message : Method invocation failed because [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof'. StackTrace : at CallSite.Target(Closure, CallSite, Object, Object) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) Exception : System.Management.Automation.RuntimeException InvocationInfo : {} Line : if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -and ($targetRegionCount -eq 8)) { Position : At /Users/mariuszborys/azurerepos/scripts/azure_pwsh_tools_scripts/Image galery cleaner/RunbookTEST.ps1:64 char:21 + … if (($AzGalDefImageVersions.indexof($ImageVersion) -eq 0) -an … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : -1 DEBUG: AzureQoSEvent: Module: Az.Accounts:2.11.2; CommandName: Resolve-AzError; PSVersion: 7.3.3; IsSuccess: True; Duration: 00:00:00.0216611 DEBUG: 1:57:59 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: 1:57:59 PM - ResolveError end processing. ```
Author: BorysMariusz
Assignees: isra-fel
Labels: `Compute`, `Service Attention`, `bug`, `customer-reported`
Milestone: -
BorysMariusz commented 1 year ago

Thank you for feedback. Yes I have code the if statement when there is only 1 object and I am not using indexof method then. Is that "the issue" and will be fixed someday ?

sandeepraichura commented 1 year ago

Thanks for reporting, this issue is being investigated currently. I will keep this thread updated on status.

BorysMariusz commented 1 year ago

Thank you. !!!!

Sent from Outlookhttp://aka.ms/weboutlook


From: saraic @.> Sent: Wednesday, April 26, 2023 7:57 PM To: Azure/azure-powershell @.> Cc: Mariusz Borys @.>; Author @.> Subject: Re: [Azure/azure-powershell] [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof' (Issue #21175)

Thanks for reporting, this issue is being investigated currently. I will keep this thread updated on status.

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-powershell/issues/21175#issuecomment-1523831113, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH2PW3CCYDLS533KQQ3CP33XDFOW3ANCNFSM6AAAAAAVWN3O5Q. You are receiving this because you authored the thread.Message ID: @.***>

sandeepraichura commented 1 year ago

Assigning to @haagha

haagha commented 1 year ago

Hi @BorysMariusz Powershell allows IndexOf() to be used on strings. In this case it looks like you are trying to invoke the method on a PSObject with a collection.

BorysMariusz commented 1 year ago

hm, understood. thank you for the tip. I will investigate that and get back to you 🙂

Sent from Outlookhttp://aka.ms/weboutlook


From: Haider Agha @.> Sent: Friday, June 9, 2023 7:10 PM To: Azure/azure-powershell @.> Cc: Mariusz Borys @.>; Mention @.> Subject: Re: [Azure/azure-powershell] [Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList] does not contain a method named 'indexof' (Issue #21175)

Hi @BorysMariuszhttps://github.com/BorysMariusz Powershell allows IndexOf() to be used on strings. In this case it looks like you are trying to invoke the method on a PSObject with a collection.

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-powershell/issues/21175#issuecomment-1584901371, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH2PW3CF75OZNWLRXS33QXDXKNKHZANCNFSM6AAAAAAVWN3O5Q. You are receiving this because you were mentioned.Message ID: @.***>

sandeepraichura commented 11 months ago

@BorysMariusz - let us know if the tip worked for you.

BorysMariusz commented 11 months ago

Hi @BorysMariusz Powershell allows IndexOf() to be used on strings. In this case it looks like you are trying to invoke the method on a PSObject with a collection.

As I wrote above: From what I understand if the variable $AzGalDefImageVersionsCounter has only one item, (image version) the "INDEXOF" method does not exists. When it has more then one item it is ok. I have checked the get-member output for both of them regardles the amount of image version (zero, one or more items) the Type is the same: Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImageVersionList

I understand that IndexOf is for strings, so why it working in the example I described ? when it is more then 1 item in the AzGalDefImage ?

BorysMariusz commented 2 weeks ago

Hello Please find a screen from running of my script . azgellery