I am not a scripter, please if anyone can help me with modify below script by removing UCPID value but keep only servername
Currently below script looking two columns from csv file, now I want to change the behavior to only look for ServerName because now CSV file have only one column which containing server only in each row and update related XML.
$data = Import-Csv .\MyFile.csv
$luTable = @{}
# Create Keys in Lookup Table
$data | % {
if (!$luTable.ContainsKey("$($_.ServerName)")) { $luTable["$($_.UCPID)"] = New-Object System.Collections.ArrayList }
}
$luTable.Keys | % {
$key = $_ # Store Key
$data | where UCPID -Match $_ | select ServerName | % {
$luTable[$key].Add($_.ServerName)
}
}
# Build XML Files
$luTable.Keys | % {
$key = $_
$filetext = gc ".\MyXML.xml"
$filetext = $filetext.Replace("#Title#", $key)
$targets = ""
$luTable[$key] | % {
$targets += "<ComputerName>$($_)</ComputerName>"
}
$filetext = $filetext.Replace("#computername#", $targets)
sc -Path ".\$($key).xml" -Value $filetext
}
I tried deleting below code but its not helping.
# Create Keys in Lookup Table
$data | % {
if (!$luTable.ContainsKey("$($_.ServerName)")) { $luTable["$($_.UCPID)"] = New-Object System.Collections.ArrayList }
}
//CSV file content
ServerName
Server1
Server2
Server3
Server4
Server5
//XML - location where I want server to be copied
<AnnounceOffer>false</AnnounceOffer>
<OfferCategory>false</OfferCategory>
<OfferDescriptionHTML>false</OfferDescriptionHTML>
</SettingsLocks>
<IsUrgent>false</IsUrgent>
<Target>
#computername#
</Target>
</SingleAction>
</BES>
#computername# must be replaced with below-
<ComputerName>Server1</ComputerName>
<ComputerName>Server2</ComputerName>
<ComputerName>Server3</ComputerName>
<ComputerName>Server4</ComputerName>
UCPIDinstead ofIGPIDlike in tha previous question?