none
how to set {} to the collection? RRS feed

  • Question


  • I want to set Owners to  empty {}  by the script below, but got the error above.

    Get-ClusterGroup -Name "SQL Server (MSSQLSERVER)"|set-ClusterOwnerNode -Owners {}

    Please click the Mark as Answer button if a post solves your problem!



    • Edited by Michael CS Saturday, April 4, 2015 7:28 AM
    Saturday, April 4, 2015 7:23 AM

Answers

  • I found I successfully set it to {} by the ''

    Get-ClusterGroup -Name "SQL Server (MSSQLSERVER)"|set-ClusterOwnerNode -Owners ''

    Anyway, Thank you for your reply Leif-Arne



    Please click the Mark as Answer button if a post solves your problem!


    Saturday, April 4, 2015 8:13 AM

All replies

  • Does this work?

    $Owners = New-Object System.Collections.Specialized.StringCollection
    Get-ClusterGroup -Name "SQL Server (MSSQLSERVER)" | Set-ClusterOwnerNode -Owners $Owners

    Saturday, April 4, 2015 7:53 AM
  • Does this work?

    $Owners = New-Object System.Collections.Specialized.StringCollection
    Get-ClusterGroup -Name "SQL Server (MSSQLSERVER)" | Set-ClusterOwnerNode -Owners $Owners

    Got the error  below

    Set-ClusterOwnerNode : Cannot bind argument to parameter 'Owners' because it is an empty collection.



    Please click the Mark as Answer button if a post solves your problem!

    Saturday, April 4, 2015 8:07 AM

  • Original it is {}, then I set it to {vm22,vm4}, now I failed to restore it to Original {}
    Please click the Mark as Answer button if a post solves your problem!


    • Edited by Michael CS Saturday, April 4, 2015 8:10 AM
    Saturday, April 4, 2015 8:10 AM
  • I found I successfully set it to {} by the ''

    Get-ClusterGroup -Name "SQL Server (MSSQLSERVER)"|set-ClusterOwnerNode -Owners ''

    Anyway, Thank you for your reply Leif-Arne



    Please click the Mark as Answer button if a post solves your problem!


    Saturday, April 4, 2015 8:13 AM
  • OK, so empty string works, but empty stringcollection does not. Good to know.
    Saturday, April 4, 2015 8:41 AM
  • Just out of curiosity, could you try the following see if it works as well? Am interested to see if that's PowerShell coercion in effect:

    Get-ClusterGroup -Name "SQL Server (MSSQLSERVER)" | Set-ClusterOwnerNode -Owners @($null)


    Saturday, April 4, 2015 12:34 PM
  • Actually just saw that it expects a System.String, so @($null) should work, but only because the $null is getting coerced into an empty string, not the other way around (I thought the '' was getting coerced into a $null, but that's only the case if the object expected is NOT System.String.
    Saturday, April 4, 2015 12:37 PM