Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - A array problem

Reply
 
Old 08-10-2007   #1 (permalink)
Jens Diekers
Guest


 
 

A array problem

in this little command i want to access a element of a array: please look

for ($a=0; $a -le 8; $a++) {dsadd group
"CN=$hn$b[$a],OU=local,OU=roles,DC=cz,DC=int-e,DC=kaufland" -scope l

The output of the defined variable $hn is ok, but when i want to access
$b[$a] variable, the array will output his whole content. Do I have to
mascerade my $b variable?

Any help is welcome?
THX

My System SpecsSystem Spec
Old 08-10-2007   #2 (permalink)
Brandon Shell
Guest


 
 

Re: A array problem

try this
"CN=$($hn)$($b[$a]),OU=local,OU=roles,DC=cz,DC=int-e,DC=kaufland"

The "$( )" Expands the result of $b[$a] and outputs the string instead.

"Jens Diekers" <Jens Diekers@discussions.microsoft.com> wrote in message
news:2E8F00FF-EFD5-4874-982A-6635B4CC585F@microsoft.com...
> in this little command i want to access a element of a array: please look
>
> for ($a=0; $a -le 8; $a++) {dsadd group
> "CN=$hn$b[$a],OU=local,OU=roles,DC=cz,DC=int-e,DC=kaufland" -scope l
>
> The output of the defined variable $hn is ok, but when i want to access
> $b[$a] variable, the array will output his whole content. Do I have to
> mascerade my $b variable?
>
> Any help is welcome?
> THX


My System SpecsSystem Spec
Old 08-10-2007   #3 (permalink)
Marco Shaw
Guest


 
 

Re: A array problem

Jens Diekers wrote:
> in this little command i want to access a element of a array: please look
>
> for ($a=0; $a -le 8; $a++) {dsadd group
> "CN=$hn$b[$a],OU=local,OU=roles,DC=cz,DC=int-e,DC=kaufland" -scope l
>
> The output of the defined variable $hn is ok, but when i want to access
> $b[$a] variable, the array will output his whole content. Do I have to
> mascerade my $b variable?
>
> Any help is welcome?
> THX


It could be $b is a string or something else other than an array.
Before doing your loop, what does "$b.gettype()" give?

Marco

------------------
PowerGadgets MVP
http://www.powergadgets.com/mvp
My System SpecsSystem Spec
Old 08-10-2007   #4 (permalink)
Brandon Shell
Guest


 
 

Re: A array problem

p.s. Also... Im not entirely sure what your goal is by $a -le 8, but if you
just want to do it for each element in $b

foreach($element in $b)
{
"CN=$hn$element,OU=local,OU=roles,DC=cz,DC=int-e,DC=kaufland" -scope l
}
"Jens Diekers" <Jens Diekers@discussions.microsoft.com> wrote in message
news:2E8F00FF-EFD5-4874-982A-6635B4CC585F@microsoft.com...
> in this little command i want to access a element of a array: please look
>
> for ($a=0; $a -le 8; $a++) {dsadd group
> "CN=$hn$b[$a],OU=local,OU=roles,DC=cz,DC=int-e,DC=kaufland" -scope l
>
> The output of the defined variable $hn is ok, but when i want to access
> $b[$a] variable, the array will output his whole content. Do I have to
> mascerade my $b variable?
>
> Any help is welcome?
> THX


My System SpecsSystem Spec
Old 08-10-2007   #5 (permalink)
Jens Diekers
Guest


 
 

Re: A array problem

Thank you Brandon and Marco! This Solutions is very effective for my PS
Script. I hope I can help you next time.

P.S. Marco: the b variable returns marketcodes...

Great Support...


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Fast copy method of sub array (=array range) possible? VB Script
How to create array without quotes? $array = (a,b,c) PowerShell
Array indexing: Want to say "Item #2 through the rest of the array." PowerShell
Stupid Array Tricks: Initializing an Array to a Certain Size PowerShell
how to assign values to array and how to create array via variable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46