how to get parameters from switch or file [duplicate]
This question already has an answer here:
How do I write a PowerShell script that accepts pipeline input?
4 answers
I've seen in the past before I started scripting that a powershell script that requires a hostname parameter. it could either by typed in like Script.PS1 "hostname"
but you could also run the script in the following method:
gc hostnames.txt | script.ps1
and in this way you could list a number of hostnames in your text file.
how is this achieved.
my parameters looks as follows
Param(
[Parameter(Mandatory=$True)]
[ValidateSet("C","K")]
[ValidateNotNullorEmpty()]
[String]$Action,
[Parameter(Mandatory = $True)]
[ValidateNotNullorEmpty()]
[String]$Computers
)
powershell parameters
marked as duplicate by LotPings, Matt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 14:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I write a PowerShell script that accepts pipeline input?
4 answers
I've seen in the past before I started scripting that a powershell script that requires a hostname parameter. it could either by typed in like Script.PS1 "hostname"
but you could also run the script in the following method:
gc hostnames.txt | script.ps1
and in this way you could list a number of hostnames in your text file.
how is this achieved.
my parameters looks as follows
Param(
[Parameter(Mandatory=$True)]
[ValidateSet("C","K")]
[ValidateNotNullorEmpty()]
[String]$Action,
[Parameter(Mandatory = $True)]
[ValidateNotNullorEmpty()]
[String]$Computers
)
powershell parameters
marked as duplicate by LotPings, Matt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 14:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
The question asked is not about getting parameters from thepipeline
although thesyntax submitted
implies that. The suggested duplicate doesn't address this.
– No Refunds No Returns
Nov 23 '18 at 15:35
add a comment |
This question already has an answer here:
How do I write a PowerShell script that accepts pipeline input?
4 answers
I've seen in the past before I started scripting that a powershell script that requires a hostname parameter. it could either by typed in like Script.PS1 "hostname"
but you could also run the script in the following method:
gc hostnames.txt | script.ps1
and in this way you could list a number of hostnames in your text file.
how is this achieved.
my parameters looks as follows
Param(
[Parameter(Mandatory=$True)]
[ValidateSet("C","K")]
[ValidateNotNullorEmpty()]
[String]$Action,
[Parameter(Mandatory = $True)]
[ValidateNotNullorEmpty()]
[String]$Computers
)
powershell parameters
This question already has an answer here:
How do I write a PowerShell script that accepts pipeline input?
4 answers
I've seen in the past before I started scripting that a powershell script that requires a hostname parameter. it could either by typed in like Script.PS1 "hostname"
but you could also run the script in the following method:
gc hostnames.txt | script.ps1
and in this way you could list a number of hostnames in your text file.
how is this achieved.
my parameters looks as follows
Param(
[Parameter(Mandatory=$True)]
[ValidateSet("C","K")]
[ValidateNotNullorEmpty()]
[String]$Action,
[Parameter(Mandatory = $True)]
[ValidateNotNullorEmpty()]
[String]$Computers
)
This question already has an answer here:
How do I write a PowerShell script that accepts pipeline input?
4 answers
powershell parameters
powershell parameters
asked Nov 23 '18 at 14:34
Cleadus FetusCleadus Fetus
465
465
marked as duplicate by LotPings, Matt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 14:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by LotPings, Matt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 14:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
The question asked is not about getting parameters from thepipeline
although thesyntax submitted
implies that. The suggested duplicate doesn't address this.
– No Refunds No Returns
Nov 23 '18 at 15:35
add a comment |
The question asked is not about getting parameters from thepipeline
although thesyntax submitted
implies that. The suggested duplicate doesn't address this.
– No Refunds No Returns
Nov 23 '18 at 15:35
The question asked is not about getting parameters from the
pipeline
although the syntax submitted
implies that. The suggested duplicate doesn't address this.– No Refunds No Returns
Nov 23 '18 at 15:35
The question asked is not about getting parameters from the
pipeline
although the syntax submitted
implies that. The suggested duplicate doesn't address this.– No Refunds No Returns
Nov 23 '18 at 15:35
add a comment |
1 Answer
1
active
oldest
votes
As asked you could use syntax something like
gc hostnames.txt | % { .script.ps1 -Action A -Computers $_ }
and it would call script.ps1
once for each line in hostnames.txt
.
The $_
is a placeholder for the current value of the array being iterated by the ... | % ...
syntax.
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
1
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As asked you could use syntax something like
gc hostnames.txt | % { .script.ps1 -Action A -Computers $_ }
and it would call script.ps1
once for each line in hostnames.txt
.
The $_
is a placeholder for the current value of the array being iterated by the ... | % ...
syntax.
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
1
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
add a comment |
As asked you could use syntax something like
gc hostnames.txt | % { .script.ps1 -Action A -Computers $_ }
and it would call script.ps1
once for each line in hostnames.txt
.
The $_
is a placeholder for the current value of the array being iterated by the ... | % ...
syntax.
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
1
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
add a comment |
As asked you could use syntax something like
gc hostnames.txt | % { .script.ps1 -Action A -Computers $_ }
and it would call script.ps1
once for each line in hostnames.txt
.
The $_
is a placeholder for the current value of the array being iterated by the ... | % ...
syntax.
As asked you could use syntax something like
gc hostnames.txt | % { .script.ps1 -Action A -Computers $_ }
and it would call script.ps1
once for each line in hostnames.txt
.
The $_
is a placeholder for the current value of the array being iterated by the ... | % ...
syntax.
answered Nov 23 '18 at 14:52
No Refunds No ReturnsNo Refunds No Returns
5,48441936
5,48441936
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
1
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
add a comment |
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
1
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
Correct answer. I'd like to add that I personally prefer to make scripts readable by not using 'gc' but Get-Content and not using '%' but ForEach-Object or ForEach. This makes it a lot easier to understand and especially for the ones without a lot of experience.
– Bernard Moeskops
Nov 23 '18 at 15:21
1
1
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
Old habits die hard for lazy hackers
– No Refunds No Returns
Nov 23 '18 at 15:33
add a comment |
The question asked is not about getting parameters from the
pipeline
although thesyntax submitted
implies that. The suggested duplicate doesn't address this.– No Refunds No Returns
Nov 23 '18 at 15:35