Invoke-Command returns only a single object when called using ScriptBlock and ArgumentListhow to edit a file in powershell remoting session (powershell)Using Powershell's Invoke-Command to call a batch file with argumentsNew-PSSession in Job blocks JobInvoke-WmiMethod not working with powershell pssession (invoke-command)How can my local PowerShell script call a remote PowerShell script?Issues with Powershell Invoke-CommandInvoke-Command and Enter-PSsession - DiffrencesFunctions tabular output changing on some remote computersHow to correctly pass a string array as a parameter in a PowerShell 4.0 Invoke-Command -ScriptBlockUsing invoke-command with register-scheduledjob and passing parameters: nested -argumentlist?
Can somebody explain Brexit in a few child-proof sentences?
Divine apple island
Folder comparison
Have I saved too much for retirement so far?
Varistor? Purpose and principle
How should I respond when I lied about my education and the company finds out through background check?
Should I stop contributing to retirement accounts?
How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?
How can "mimic phobia" be cured or prevented?
Can a significant change in incentives void an employment contract?
Query about absorption line spectra
What does this horizontal bar at the first measure mean?
Translation of Scottish 16th century church stained glass
Drawing ramified coverings with tikz
List of people who lose a child in תנ"ך
Reply 'no position' while the job posting is still there
Why did the EU agree to delay the Brexit deadline?
Some numbers are more equivalent than others
Can I use my Chinese passport to enter China after I acquired another citizenship?
Is there a conventional notation or name for the slip angle?
Visiting the UK as unmarried couple
Difference between -| and |- in TikZ
Fuse symbol on toroidal transformer
A social experiment. What is the worst that can happen?
Invoke-Command returns only a single object when called using ScriptBlock and ArgumentList
how to edit a file in powershell remoting session (powershell)Using Powershell's Invoke-Command to call a batch file with argumentsNew-PSSession in Job blocks JobInvoke-WmiMethod not working with powershell pssession (invoke-command)How can my local PowerShell script call a remote PowerShell script?Issues with Powershell Invoke-CommandInvoke-Command and Enter-PSsession - DiffrencesFunctions tabular output changing on some remote computersHow to correctly pass a string array as a parameter in a PowerShell 4.0 Invoke-Command -ScriptBlockUsing invoke-command with register-scheduledjob and passing parameters: nested -argumentlist?
When code is invoked though Invoke-Command
using the -ScriptBlock
, -ArgumentList
and -Computer
parameters, only a single item is returned from each call to the servers.
Two examples can be found below highlighting the problem.
$s = New-PSSession -ComputerName Machine01, Machine02
# when called, this block only retuns a single item from the script block
# notice that the array variable is being used
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
write-host "`r`n======================================`r`n"
# when called, this block retuns all items from the script block
# notice that the call is the same but instead of using the array variable we use a local array
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
$s | Remove-PSSession
Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.
powershell powershell-remoting
add a comment |
When code is invoked though Invoke-Command
using the -ScriptBlock
, -ArgumentList
and -Computer
parameters, only a single item is returned from each call to the servers.
Two examples can be found below highlighting the problem.
$s = New-PSSession -ComputerName Machine01, Machine02
# when called, this block only retuns a single item from the script block
# notice that the array variable is being used
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
write-host "`r`n======================================`r`n"
# when called, this block retuns all items from the script block
# notice that the call is the same but instead of using the array variable we use a local array
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
$s | Remove-PSSession
Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.
powershell powershell-remoting
add a comment |
When code is invoked though Invoke-Command
using the -ScriptBlock
, -ArgumentList
and -Computer
parameters, only a single item is returned from each call to the servers.
Two examples can be found below highlighting the problem.
$s = New-PSSession -ComputerName Machine01, Machine02
# when called, this block only retuns a single item from the script block
# notice that the array variable is being used
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
write-host "`r`n======================================`r`n"
# when called, this block retuns all items from the script block
# notice that the call is the same but instead of using the array variable we use a local array
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
$s | Remove-PSSession
Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.
powershell powershell-remoting
When code is invoked though Invoke-Command
using the -ScriptBlock
, -ArgumentList
and -Computer
parameters, only a single item is returned from each call to the servers.
Two examples can be found below highlighting the problem.
$s = New-PSSession -ComputerName Machine01, Machine02
# when called, this block only retuns a single item from the script block
# notice that the array variable is being used
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
write-host "`r`n======================================`r`n"
# when called, this block retuns all items from the script block
# notice that the call is the same but instead of using the array variable we use a local array
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1,2,3
$s | Remove-PSSession
Can anyone explain to me what i am doing wrong? I cant be the only person caught out by this.
powershell powershell-remoting
powershell powershell-remoting
edited Mar 21 at 13:52
marsze
5,87132042
5,87132042
asked Mar 21 at 13:32
SteveSteve
502148
502148
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
-ArgumentList
does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array
. Therefore, you only get the first value from the arg list.
See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1, 2, 3
So, what you actually want to do is pass one array as one single parameter.
One way to accomplish that would be:
-ArgumentList (,(1, 2, 3))
Final code:
Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName
-ArgumentList (, (1, 2, 3))
Another way (in this simple case) would be using the automatic $args
variable:
Invoke-Command -ScriptBlock
$args -ArgumentList 1, 2, 3
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281599%2finvoke-command-returns-only-a-single-object-when-called-using-scriptblock-and-ar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
-ArgumentList
does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array
. Therefore, you only get the first value from the arg list.
See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1, 2, 3
So, what you actually want to do is pass one array as one single parameter.
One way to accomplish that would be:
-ArgumentList (,(1, 2, 3))
Final code:
Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName
-ArgumentList (, (1, 2, 3))
Another way (in this simple case) would be using the automatic $args
variable:
Invoke-Command -ScriptBlock
$args -ArgumentList 1, 2, 3
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
add a comment |
-ArgumentList
does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array
. Therefore, you only get the first value from the arg list.
See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1, 2, 3
So, what you actually want to do is pass one array as one single parameter.
One way to accomplish that would be:
-ArgumentList (,(1, 2, 3))
Final code:
Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName
-ArgumentList (, (1, 2, 3))
Another way (in this simple case) would be using the automatic $args
variable:
Invoke-Command -ScriptBlock
$args -ArgumentList 1, 2, 3
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
add a comment |
-ArgumentList
does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array
. Therefore, you only get the first value from the arg list.
See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1, 2, 3
So, what you actually want to do is pass one array as one single parameter.
One way to accomplish that would be:
-ArgumentList (,(1, 2, 3))
Final code:
Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName
-ArgumentList (, (1, 2, 3))
Another way (in this simple case) would be using the automatic $args
variable:
Invoke-Command -ScriptBlock
$args -ArgumentList 1, 2, 3
-ArgumentList
does what the name implies, it passes a list of arguments to the command. Each value from that list is, if possible, assigned to a defined parameter. But you only have one parameter defined: $array
. Therefore, you only get the first value from the arg list.
See, this is actually how it's supposed to work (3 arguments bound to 3 parameters):
Invoke-Command -Session $s -ScriptBlock % select @name='__id'; ex=$i , DisplayName
-ArgumentList 1, 2, 3
So, what you actually want to do is pass one array as one single parameter.
One way to accomplish that would be:
-ArgumentList (,(1, 2, 3))
Final code:
Invoke-Command -Session $s -ScriptBlock % select @n = '__id'; e = $i, DisplayName
-ArgumentList (, (1, 2, 3))
Another way (in this simple case) would be using the automatic $args
variable:
Invoke-Command -ScriptBlock
$args -ArgumentList 1, 2, 3
edited Mar 21 at 13:49
answered Mar 21 at 13:40
marszemarsze
5,87132042
5,87132042
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
add a comment |
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
thanks a lot. I've use the "," before an array before but had completely forgotten about it. still cant remember its name.
– Steve
Mar 21 at 13:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281599%2finvoke-command-returns-only-a-single-object-when-called-using-scriptblock-and-ar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown