Reputation: 11
I'm trying to create a simple script to add a new proxy for each ip address. The script gets to id125 before slowing to an absolute crawl. I'm not sure why it's consuming so much memory, can anyone help optimize what i'm doing here?
$xml = New-Object -TypeName XML
$xml.Load($Path)
$ipAddresses = Get-Content "D:\Downloads\ipaddresses.txt"
$proxy = ($xml.ProxifierProfile.ProxyList.Proxy[0])
$counter = 102
foreach($ipAddress in $ipAddresses){
$newproxy = $proxy.CloneNode($true)
$newproxy.id = [string](++$counter)
$newproxy.Address = [string]$ipAddress
$proxy.AppendChild($newproxy)
}
$newpath = "c:\temp\newfile.ppx"
$xml.Save($newpath)
Upvotes: 0
Views: 51
Reputation: 11
Got it working, thanks. Not sure why AppendChild & insertafter don't work similarly...
$xml = New-Object -TypeName XML
$xml.Load($Path)
$ipAddresses = Get-Content "D:\Downloads\ipaddresses.txt"
$newpath = "c:\temp\newfile.ppx"
$proxy = ($xml.ProxifierProfile.ProxyList.Proxy[-1])
$counter = 101
foreach($ipAddress in $ipAddresses){
$newproxy = $proxy.CloneNode($true)
$newproxy.id = [string](++$counter)
$newproxy.Address = [string]$ipAddress
$Latestproxy = $xml
$proxy.ParentNode.InsertAfter($newproxy,$proxy)
}
$xml.Save($newpath)
Upvotes: 1