Method invocation failed because System.Object[]] does not contain a method name indexOf in PowerShell

Supermode

I have error IndexOf when i tried to run the following powershell script. Any advise

$unlicensedUsers = Get-MsolUser -UnlicensedUsersOnly
foreach ($aUser in $unlicensedUsers)
{
   if ($unlicensedUsers.IndexOf($aUser) % 10 -eq 0) {
            Write-Host -ForegroundColor yellow $unlicensedUsers.IndexOf($aUser)
   }
}

Error:

IndexOf : Method invocation failed because System.Object[]] does not contain a method name indexOf

Nacht

IndexOf() is a method on the List<T> type, which is usually not used in PowerShell. Most of the time the variables that you use in foreach are going to be object arrays, as in your example, or some other type of collection. Object arrays don't have an equivalent method, so you'll have to hold your own copy of the array index:

$unlicensedUsers = Get-MsolUser -UnlicensedUsersOnly
for ($i = 0; $i -lt $unlicensedUsers.count; $i++)
{
    if ($i % 10 -eq 0) {
        Write-Host -ForegroundColor yellow $i
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

From Java

indexOf method in an object array?

From Java

Error creating bean with name 'embeddedKafka': Invocation of init method failed

From Dev

LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method

From Dev

$string.IndexOf('.') inside powershell function returns method invocation failed

From Dev

Why does List.indexOf use equals method of passed in Object?

From Dev

C# object does not contain a definition for method

From Dev

Error creating bean with name 'entityManagerFactory' Invocation of init method failed

From Dev

Method invocation failed because [System.__ComObject] does not contain a method named 'Close' in Powershell v4.0

From Dev

Powershell Error: Method invocation...doesn't contain a method named 'replace'

From Dev

Why Error "System.String does not contain a method named 'AppendChild'"

From Dev

BeanCreationException : Invocation of init method failed

From Dev

Spock does not detect method invocation

From Dev

Method invocation failed because [System.__ComObject] does not co ntain a method named 'Click'

From Dev

Does the object type contain a protected virtual Finalize method?

From Dev

Spring batch -BatchDatabaseInitializer : Invocation of init method failed

From Dev

Error creating bean with name 'entityManagerFactory' defined in class path resource (Invocation of init method failed)

From Dev

Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

From Dev

BeanCreationException : Invocation of init method failed

From Dev

LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method

From Dev

Dynamic object method invocation using reflection in scala

From Dev

C# object does not contain a definition for method

From Dev

Method invocation failed because System.Object[]] does not contain a method name indexOf in PowerShell

From Dev

Object Does not contain a defination for Database and no extension method Database

From Dev

does not contain definition for "Method"

From Dev

Spock does not detect method invocation

From Dev

Does the object type contain a protected virtual Finalize method?

From Dev

Method invocation failed because [System.__ComObject] does not co ntain a method named 'Click'

From Dev

‘label’ does not contain a definition for ‘Name’ and no extension method

Related Related

  1. 1

    Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

  2. 2

    indexOf method in an object array?

  3. 3

    Error creating bean with name 'embeddedKafka': Invocation of init method failed

  4. 4

    LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method

  5. 5

    $string.IndexOf('.') inside powershell function returns method invocation failed

  6. 6

    Why does List.indexOf use equals method of passed in Object?

  7. 7

    C# object does not contain a definition for method

  8. 8

    Error creating bean with name 'entityManagerFactory' Invocation of init method failed

  9. 9

    Method invocation failed because [System.__ComObject] does not contain a method named 'Close' in Powershell v4.0

  10. 10

    Powershell Error: Method invocation...doesn't contain a method named 'replace'

  11. 11

    Why Error "System.String does not contain a method named 'AppendChild'"

  12. 12

    BeanCreationException : Invocation of init method failed

  13. 13

    Spock does not detect method invocation

  14. 14

    Method invocation failed because [System.__ComObject] does not co ntain a method named 'Click'

  15. 15

    Does the object type contain a protected virtual Finalize method?

  16. 16

    Spring batch -BatchDatabaseInitializer : Invocation of init method failed

  17. 17

    Error creating bean with name 'entityManagerFactory' defined in class path resource (Invocation of init method failed)

  18. 18

    Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

  19. 19

    BeanCreationException : Invocation of init method failed

  20. 20

    LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method

  21. 21

    Dynamic object method invocation using reflection in scala

  22. 22

    C# object does not contain a definition for method

  23. 23

    Method invocation failed because System.Object[]] does not contain a method name indexOf in PowerShell

  24. 24

    Object Does not contain a defination for Database and no extension method Database

  25. 25

    does not contain definition for "Method"

  26. 26

    Spock does not detect method invocation

  27. 27

    Does the object type contain a protected virtual Finalize method?

  28. 28

    Method invocation failed because [System.__ComObject] does not co ntain a method named 'Click'

  29. 29

    ‘label’ does not contain a definition for ‘Name’ and no extension method

HotTag

Archive