Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: General » microsoft.public.windows.powershell
Thread: variable probleme

HTVi
TV Discussion Newsgroups

variable probleme
steph 12/30/2008 3:54:06 AM
Hi

I would like to do this :

$list="get-command","get-service"
foreach ($l in $list)
{
echo $l
foreach($i in $l)
{
$a=$i.name
echo $a
}
}
The probleme is :
The variable in the second foreach ($ l) appears to be seen as a string and
not a command.do anyone have an idea ?
Thanks
Re: variable probleme
"Vadims Podans" <vpodans> 12/30/2008 7:00:02 AM
your $list contains strings, not commands. What you want to get?

"steph" <steph[ at ]discussions.microsoft.com> rakstīja ziņojumā
"news:1C916815-6FC5-4B0F-A39C-24CA307A0BE8[ at ]microsoft.com"...
[Quoted Text]
> Hi
>
> I would like to do this :
>
> $list="get-command","get-service"
> foreach ($l in $list)
> {
> echo $l
> foreach($i in $l)
> {
> $a=$i.name
> echo $a
> }
> }
> The probleme is :
> The variable in the second foreach ($ l) appears to be seen as a string
> and
> not a command.do anyone have an idea ?
> Thanks

Re: variable probleme
"Kiron" <Kiron[ at ]HighPlainsDrifter.com> 12/30/2008 7:25:07 AM
To execute the Cmdlet in the second Foreach use the Call operator '&'.
You can also use Invoke-Expression or a dot.

# call operator
foreach($i in & $l)

# invoke-expression's alias
foreach($i in iex $l)

# a dot
foreach($i in . $l)

--
Kiron
Re: variable probleme
steph 12/30/2008 11:58:01 AM
thanks to all

"Kiron" wrote:

[Quoted Text]
> To execute the Cmdlet in the second Foreach use the Call operator '&'.
> You can also use Invoke-Expression or a dot.
>
> # call operator
> foreach($i in & $l)
>
> # invoke-expression's alias
> foreach($i in iex $l)
>
> # a dot
> foreach($i in . $l)
>
> --
> Kiron
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen