Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8572183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:57:01+00:00 2026-06-11T18:57:01+00:00

Assume I have created and opened runspace via var rs = RunspaceFactory.CreateRunspace(); rs.Open(); Let’s

  • 0

Assume I have created and opened runspace via

            var rs = RunspaceFactory.CreateRunspace();
            rs.Open();

Let’s further assume that I want to add a variable into that runspace that is typed as an array by using the New-Variable cmdlet like so:

            // create a pipeline to add the variable into the runspace
            var pipeline = PowerShell.Create();
            // create a command object, add commands and parameters to it...
            var cmd = new PSCommand();
            cmd.AddCommand("New-Variable");
            cmd.AddParameter("Name", "foo");
            cmd.AddParameter("Value", "@()");
            // associate the command with the pipeline and runspace, and then invoke
            pipeline.Commands = cmd;
            pipeline.Runspace = rs;
            pipeline.Invoke();

The code works and I get no errors, but the variable ‘foo’ is not created as an array type. I’ve tried many different variations on “@()”, but none of them have panned out thus far. Ultimately, I think the question boils down to how to properly format the Value argument to New-Variable so that ‘foo’ will be interpreted as an empty PowerShell array type.

Thanks,

Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:57:03+00:00Added an answer on June 11, 2026 at 6:57 pm

    PSCommand.AddParameter takes a string for the parameter name, and an object for the parameter value. See the docs here.

    You should put a “real” empty array, not a string representing the powershell script equivalent.

    cmd.AddParameter("Value", new object[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that i have created a client TCP Socket in Activity A. I want
Let's assume that I have created my REST service smoothly and I am returning
Let's assume that I have created my REST service smoothly and I am returning
Let's assume that I have mytable in mySQL CREATE TABLE `mytable` ( `gender` enum('MALE','FEMALE','UNISEX')
I have created MDI application in Delphi. Lets assume that I have a bunch
I'm trying to create ProgressMonitor with changing totalWork. Lets assume that I have 2
I'm trying to create an expression tree dynamicly. Let asume that I have two
Assume I have an enumerable object enum and now I want to get the
I have created a web app that authenticates users on our page and I'd
I have created a custom control (based on a panel) in wxPython that provides

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.