locked
Pass an array as a parameter RRS feed

  • Question

  • I've got a script I'm working on with a MS program's PS Module.  I've got one array that is holding a series of names in a domain\user format and am trying to pass it to a command  it gives me an odd error message.  

    Command:

    remove-CrmDeploymentAdministrator -name $dropadmin

    Error:

    remove-CrmDeploymentAdministrator : Cannot convert 'System.String[]' to the type 'System.String' required by the parameter 'Name'.  Specified method is not supported.  

    I'm not sure what the best solution here is and if there is a nuance to the way it is mentioning those strings that I need to run some sort of convert on the array values before I'm going to be able to pass them to the command.  

    Thanks!

    Monday, February 18, 2019 3:31 PM

Answers

  • To clarify, in the error message 'System.String[]' refers to an array of strings, while type 'System.String' refers to a string. The "[]" is used to signify an array. PowerShell cannot convert the array into a string required by the cmdlet.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by BOfH-666 Monday, February 18, 2019 4:02 PM
    • Marked as answer by Jarrod A Williams Monday, February 18, 2019 4:20 PM
    Monday, February 18, 2019 4:00 PM

All replies

  • The error message is actually pretty obvious. You are passing an array but the cmdlet Remove-CrmDeploymentAdministration only accepts a single string. You will have to create a loop to process more than one name at a time.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Monday, February 18, 2019 3:54 PM
    • Proposed as answer by jrv Monday, February 18, 2019 3:54 PM
    Monday, February 18, 2019 3:53 PM
  • To clarify, in the error message 'System.String[]' refers to an array of strings, while type 'System.String' refers to a string. The "[]" is used to signify an array. PowerShell cannot convert the array into a string required by the cmdlet.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by BOfH-666 Monday, February 18, 2019 4:02 PM
    • Marked as answer by Jarrod A Williams Monday, February 18, 2019 4:20 PM
    Monday, February 18, 2019 4:00 PM
  • Thank you both for the quick and concise answers.  I'm definitely more used to working within SQL than within PowerShell and still getting the hang of some of the aspects and their nuances.  

    Monday, February 18, 2019 4:22 PM