header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Powershell Overwrite / Update Array Values
Last Post 27 Jul 2010 03:53 AM by jamesscott11. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
jamesscott11User is Offline
New Member
New Member
Posts:7
Avatar

--
27 Jul 2010 12:12 AM
    Hello All

     I hope this is an easy one to answer, I've no doubt it's extremely basic however google has been of little help. If anybody could assisst I'd appreciate it.

     Basically the code below doesn't work:



    All I'd like to do is overwrite each item in this array (currently simplified although this will be conditional in the finished script,) and then output the result. The problem is nothing updates. Am I missing a cmdlet?

    Many thanks,

    James
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    27 Jul 2010 01:44 AM

    In your example, VFile is a local variable in the foreach loop, so all that is happening is that the variable is being overwritten with the "current" value in each iteration.

    Its sounds like a for loop is what you're after. As an example:

    $arr = @(1, 2, 3, 4, 5)

    for ([Int32]$i = 0; $i -lt $arr.Length; $i++)
    {
        $arr[$i] = 10
    }

    $arr

    ...so in your case, that would be something like:

    $lines = Get-Content -Path "Results.xml"

    for ([Int32]$i = 0; $i -lt $lines.Length; $i++)
    {
        $lines[$i] = "URL"
    }

    $lines

    jamesscott11User is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    27 Jul 2010 03:53 AM
    GWHowarth88 - Thanks for the help (again - twice in two days and it has been a real help).

    James
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer