Remove specific xml elements using PowerShell - powershell

I have the following xml:
<NS1:PriceMaintenanceRequest xmlns:NS1="http://retalix.com/R10/services" MajorVersion="2" MinorVersion="0" FixVersion="0">
<NS1:Header>
<NS1:MessageId>1234</NS1:MessageId>
<NS1:Bulk UnitOfWork="false"/>
</NS1:Header>
<NS1:ProductPrice BusinessUnitId="9200" Action="AddOrUpdate">
<NS1:ProductId>2840000133</NS1:ProductId>
<NS1:Price Action="AddUpdate" Sequence="1234">
<NS1:UnitOfMeasureCode>EA</NS1:UnitOfMeasureCode>
<NS1:EffectiveDateTimestamp>2012-09-20T00:00:00</NS1:EffectiveDateTimestamp>
<NS1:EndDateTimestamp>2056-12-12T23:59:00</NS1:EndDateTimestamp>
<NS1:CatalogPrice Currency="USD">4.2900</NS1:CatalogPrice>
<NS1:BatchID>491364c5-73f5-45a4-8355-79cc0a720ea0</NS1:BatchID>
<NS1:ChangeStatus>NA</NS1:ChangeStatus>
</NS1:Price>
</NS1:ProductPrice>
<NS1:ProductPrice BusinessUnitId="90" Action="AddOrUpdate">
<NS1:ProductId>2840000133</NS1:ProductId>
<NS1:Price Action="AddUpdate" Sequence="1234">
<NS1:UnitOfMeasureCode>EA</NS1:UnitOfMeasureCode>
<NS1:EffectiveDateTimestamp>2012-09-20T00:00:00</NS1:EffectiveDateTimestamp>
<NS1:EndDateTimestamp>2056-12-12T23:59:00</NS1:EndDateTimestamp>
<NS1:CatalogPrice Currency="USD">4.2900</NS1:CatalogPrice>
<NS1:BatchID>491364c5-73f5-45a4-8355-79cc0a720ea0</NS1:BatchID>
<NS1:ChangeStatus>NA</NS1:ChangeStatus>
</NS1:Price>
</NS1:ProductPrice>
<NS1:ProductPrice BusinessUnitId="90" Action="AddOrUpdate">
<NS1:ProductId>2840000133</NS1:ProductId>
<NS1:Price Action="AddUpdate" Sequence="1234">
<NS1:UnitOfMeasureCode>EA</NS1:UnitOfMeasureCode>
<NS1:EffectiveDateTimestamp>2012-09-20T00:00:00</NS1:EffectiveDateTimestamp>
<NS1:EndDateTimestamp>2056-12-12T23:59:00</NS1:EndDateTimestamp>
<NS1:CatalogPrice Currency="USD">4.2900</NS1:CatalogPrice>
<NS1:BatchID>491364c5-73f5-45a4-8355-79cc0a720ea0</NS1:BatchID>
<NS1:ChangeStatus>NA</NS1:ChangeStatus>
</NS1:Price>
</NS1:ProductPrice>
</NS1:PriceMaintenanceRequest>
I need to remove all nodes with BusinessUnitId="90". So in this example, I end up with this:
<NS1:PriceMaintenanceRequest xmlns:NS1="http://retalix.com/R10/services" MajorVersion="2" MinorVersion="0" FixVersion="0">
<NS1:Header>
<NS1:MessageId>1234</NS1:MessageId>
<NS1:Bulk UnitOfWork="false"/>
</NS1:Header>
<NS1:ProductPrice BusinessUnitId="9200" Action="AddOrUpdate">
<NS1:ProductId>2840000133</NS1:ProductId>
<NS1:Price Action="AddUpdate" Sequence="1234">
<NS1:UnitOfMeasureCode>EA</NS1:UnitOfMeasureCode>
<NS1:EffectiveDateTimestamp>2012-09-20T00:00:00</NS1:EffectiveDateTimestamp>
<NS1:EndDateTimestamp>2056-12-12T23:59:00</NS1:EndDateTimestamp>
<NS1:CatalogPrice Currency="USD">4.2900</NS1:CatalogPrice>
<NS1:BatchID>491364c5-73f5-45a4-8355-79cc0a720ea0</NS1:BatchID>
<NS1:ChangeStatus>NA</NS1:ChangeStatus>
</NS1:Price>
</NS1:ProductPrice>
</NS1:PriceMaintenanceRequest>
How do i do it with PowerShell?
I need to load a files containing this xml from a directory, manipulate them, and save them.
Thanks a lot

You can do something like this:
Get-ChildItem -Path "C:\FolderWithXMLs" -Filter "*.xml" | ForEach-Object {
$path = $_.FullName
$xml = [xml](Get-Content $path)
$xml.PriceMaintenanceRequest.ProductPrice | ? { $_.BusinessUnitId -eq "90" } | % {
#Remove node
$xml.PriceMaintenanceRequest.RemoveChild($_)
}
$xml.Save($path)
}

Related

Manipulate text file - change multiple lines

Have been looking at what I thought would be a really simple task this morning.... and turns out it wasn't, at least not for me.
What I am trying to do is get powershell to read through an ini-file, and change multiple values under specific headers only.
[Datoformat]
Separator=.
[Database]
Path=servername:d:\mycompany\nextsys_db\next.fdb
DokumentDbPath=
FireBird25=Nei
[Pictures]
Path=T:\nextsys_bilde
DbExtractFolder=
[Brukerinnstillinger]
Prioriter=Ja
�pneJournalAuto=Nei
TillatBrukerBytte=Ja
EnkelJournal=Nei
AvtBokRadHoyde=
AvtBokMndKolonneBredde=
Resepsjonsmaskin=Nei
Tilgangsoversikt=Nei
AvtaleHentPasientAutomatisk=Ja
VisFargeForAnsvarlig=Nei
[Eksport]
Automatisk=Nei
[Import]
Automatisk=Nei
[Skjerm]
HuskSkjermPosisjon=Ja
ProgramSkjermPosX=-8
ProgramSkjermPosY=-8
ProgramSkjermBredde=1936
ProgramSkjermHoyde=1056
MaksimertSkjermPosisjon=Ja
EgenDefSkjermSizeX=1919
EgenDefSkjermSizeY=1080
UtvidetAvtalebok=Ja
UtvidetJournal=Ja
UtvidetRecall=Ja
UtvidetOmsetning=Ja
UtvidetUtestaaende=Ja
UtvidetRegnskap=Ja
UtvidetFakturaOversikt=Ja
UtvidetGenerelleModuler=Ja
UtvidetAlleModuler=Ja
1280800=Nei
1440900=Nei
16801050=Nei
19201080=Nei
Egendefinert=Ja
AutomaticSize=Nei
[Spesialinnstillinger]
EnForekomst=Nei
TestModusInfo=Nei
AktiverRegningskortJournalSjekk=Nei
IkkeSpmOmHelseskjema=Nei
IkkeSpmOmBrukerBytteAvtale=Nei
IkkeSpmOmBrukerBytteAnsvarlig=Nei
[Vedlegg]
Path=
[Avtalebok]
Utseende=
Bakgrunn=
[Journal]
JournalTextSize=8
JournalTextFont=
JournalTextStyle=
FetSkrift=Nei
[Rontgen]
AlternativAapning=Nei
[Utseende]
IkkeVisDagensPasienter=Nei
[MediLink]
BenyttMediLink=Nei
AutomatiskInnlesing=Nei
MediLinkInnlesingIntervall=
[AutomatiskOppdatering]
VedOppstart=Nei
Alltid=Nei
FraLokaltNettverk=Nei
NettverkPath=
UtenBekreftelse=Nei
[BankTerminal]
PosPay=Nei
BetTermAlwaysOn=Ja
BBSFlerBrukerTerminal=Nei
ThisMerchantHighest=Nei
MerchantId=
TerminalId=
BrukerBoPosDrivere=Nei
BrukerBaxiDrivere=Ja
BaxiAktiverXReport=Ja
BaxiAktiverZReport=Nei
BaxiAktiverReversal=Nei
[EasyPanel]
Benytt=Nei
Notat=Nei
Diagnose=Nei
Epikriser=Nei
Sykemelding=Nei
Resept=Nei
Henvisning=Nei
Helseskjema=Nei
Endo=Nei
Perio=Nei
Bilder=Nei
Tekn.skjema=Nei
Skjema=Nei
Dokumentmodul=Nei
[Oppstartsbilde]
VisesVedOppstart=Nei
[Printer]
LokaltOppsett=Ja
TryktA5Resept=Nei
TryktA5ReseptDesign2=Nei
TimeKortKvittSkriver=Nei
VisMinimalBaxInfo=Nei
ReseptKvittSkriver=Nei
JusteringVenstreMargX=
JusteringToppMargY=
Faktura=HP LaserJet Pro MFP M125-M126 PCLmS
Recallkort=HP LaserJet Pro MFP M125-M126 PCLmS
Timekort=HP LaserJet Pro MFP M125-M126 PCLmS
Kvittering=HP LaserJet Pro MFP M125-M126 PCLmS
Resept=HP LaserJet Pro MFP M125-M126 PCLmS
Standard=HP LaserJet Pro MFP M125-M126 PCLmS
Tekniker=HP LaserJet Pro MFP M125-M126 PCLmS
FakturaStorrelse=A4
RecallKortStorrelse=A4
TimekortStorrelse=A4
KvitteringStorrelse=A4
ReseptStorrelse=A4
TeknikerStorrelse=A4
StandardStorrelse=A4
FakturaOppsettKode=
RecallkortOppsettKode=
TimekortOppsettKode=
KvitteringOppsettKode=
ReseptOppsettKode=
TeknikerOppsettKode=
StandardOppsettKode=
FakturaPapirretning=St�ende
RecallKortPapirretning=St�ende
TimekortPapirretning=St�ende
KvitteringPapirretning=St�ende
ReseptPapirretning=St�ende
TeknikerPapirretning=St�ende
StandardPapirretning=St�ende
FakturaPreview=Ja
RecallKortPreview=Ja
TimekortPreview=Ja
KvitteringPreview=Ja
ReseptPreview=Ja
TeknikerPreview=Ja
StandardPreview=Ja
[Paaminnelse]
Automatisk=Nei
AutomatiskService=Nei
Tidspunkt=
Dagens=Nei
KunMerketOnsker=Nei
AutomatiskEpost=Nei
AntallDagerFrem=Nei
AntallDagerFremAntall=2
ErstattTekst=Nei
PaaminnelseTekst=Hei [fornavn], minner om time reservert til deg: [dato] kl. [tid]. Timer som ikke passer m� avbestilles senest 24 timer i forveien. Mvh. [tittel] [brukernavn]
[SMS]
Testmodus=Nei
VisAdvarslerVedIkkeSendtSMS=Nei
[Innlogging]
TillatInnloggingMedEldreProgramversjonEnnDatabase=Nei
I want to change the values "Automatisk=Nei" to "Automatisk=Ja", "Tidspunkt=" to "Tidspunkt=10:00" and "AntallDagerFrem=Nei" to "AntallDagerFrem=Ja"... The Tidspunkt and AntallDagerFrem values shouldn't be that hard since they only appear once in the file, but "Automatisk=Nei" appears 4 times, and I only want to change the one below [Paaminnelse]
$content = #(if ((Get-Content $inifile) -join "`n" -match '\[Paaminnelse\]([\s\S]*)\[SMS\]') { $Matches[1] })
$newcontent = $test -replace 'Automatisk=Nei','Automatisk=Ja' -replace 'Tidspunkt=','Tidspunkt=10:00' -replace 'AntallDagerFrem=Nei','AntallDagerFrem=Ja'
This finds the correct lines from the ini-file and changes the values I want to change, but using Set-Content $inifile -Value $newcontent will of course remove all everything else from the file which is not what I want :)
More used to cat, grep, awk and sed than PowerShell to be honest so any pointers would be helpful.
As Theo notes, consider using a dedicated INI file parser, such as the one provided by the third-party PsIni module - see this answer for how to install and use it.
Update: Your own answer now shows how to use it to solve your specific problem.
If installing a module isn't an option, I suggest using a -switch statement, which has awk-like capabilities:
# Array of sample lines, as would be returned by:
# Get-Content $inifile
$iniFileLines = #'
[Datoformat]
Separator=.
[Eksport]
Automatisk=Nei
[Paaminnelse]
Automatisk=Nei
AutomatiskService=Nei
Tidspunkt=
[Printer]
AutomatiskEpost=Nei
AntallDagerFrem=Nei
AntallDagerFremAntall=2
'# -split '\r?\n'
$inPaaminnelseSect = $false
# Note: To operate directly on your file, replace
# ($iniFileLines) with -File $iniFile
switch -Regex ($iniFileLines) {
'^(Tidspunkt)=$' { '{0}=10:00' -f $Matches[1]; continue }
'^(AntallDagerFrem)=Nei' { '{0}=Ja' -f $Matches[1]; continue }
'^(Automatisk)=Nei' {
if ($inPaaminnelseSect) { '{0}=Ja' -f $Matches[1] } else { $_ }; continue
}
'^\[(.+)\]' { $inPaaminnelseSect = $Matches[1] -eq 'Paaminnelse'; $_ }
default { $_ } # pass through
}
Note:
The above assumes:
that your file has exactly the format as shown in your question. However, it would be easy to make parsing more flexible with respect to optional whitespace.
that you only want to replace entries if they have a specific current value (or none); this too could easily be changed to replace the values irrespective of the current value.
Matching is case-insensitive, as PowerShell generally is by default; add the -CaseSensitive switch to make it case-sensitive.
Output:
[Datoformat]
Separator=.
[Eksport]
Automatisk=Nei
[Paaminnelse]
Automatisk=Ja
AutomatiskService=Nei
Tidspunkt=10:00
[Printer]
AutomatiskEpost=Nei
AntallDagerFrem=Ja
AntallDagerFremAntall=2
Theo and mklement0 have both pointed to the PsIni-module which does exactly what I wanted to do - so consider the question answered.
Set-IniContent $inifile -Sections 'Paaminnelse' -NameValuePairs #{
Automatisk='Ja'; Tidspunkt='10:00'; AntallDagerFrem='Ja'
} | Out-IniFile $inifile -Force

PowerShell Active Directory list all Multi-Valued attributes

not sure if I'm chaing the wild goose here but as per subject I'd need to get a list of AD attributes, for the user ObjectClass, that are multie valued.
For example the proxyAddresses exchange specific attribute is multi valued where extensionAttribute* only accept a single string.
We use a heavily customized schema and while I could go through each attribute documentation I'd rather get a list of aforementioned attributes via PowerShell.
I've tried using ldp.exe but could not achive desired results and was wondering if there is a way to do this via PowerShell or .Net managed code.
Thanks in advance for any help/pointer.
So you have to query the Schema part of the directory and look for objectClass attributeSchema and attribute isSingleValued (FALSE). The part of the distinguichName wichh is invariant is : CN=Schema,CN=Configuration.
try first with CSV :
csvde -f MultivaluedAttributes.csv -d CN=Schema,CN=Configuration,DC=MySubdomain,DC=MyDomain,DC=com -r "(&(objectclass=attributeSchema)(isSingleValued=FALSE))" -l lDAPDisplayName
Here is the powershell code.
# LDAPSchemaQuery.PS1
try
{
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://179.22.21.01/CN=Schema,CN=Configuration,DC=MyDomain,DC=MyExt","MyUser", 'MyPassword')
# Query into the Schema
# csvde -f MultivaluedAttributes.csv -d CN=Schema,CN=Configuration,DC=office,DC=coyotesystems,DC=com -r "(&(objectclass=attributeSchema)(isSingleValued=FALSE))" -l lDAPDisplayName
$Rech = new-object System.DirectoryServices.DirectorySearcher($dn)
#$Rech.filter = "(&(objectclass=user)(mail=*)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))"
$Rech.filter = "(&(objectclass=attributeSchema)(isSingleValued=FALSE))"
$Rech.SearchScope = "subtree"
$dumy=$Rech.PropertiesToLoad.Add("lDAPDisplayName")
$adAttributes = $Rech.findall()
foreach ($adAttribute in $adAttributes)
{
$multivaluedAttribute = try{$adAttribute.Properties["lDAPDisplayName"]}catch{""}
$multivaluedAttribute
}
}
catch
{
Write-Verbose "LDAPSchemaQuery : PB with $($adAttribute.Path)"
}

Create new element in existing XML Document using Powershell

I have a script that reads from an XML file, performs some web services, from which it gets a response and I'd now like the XML fie to be amended with the webs response as below.
Original XML:
<ItemNum>
<Key>11233</Key>
<Item>123.jpg</Item>
<Item>456.jpg</Item>
<Item>789.jpg</Item>
<Detail>Processed on 8-12-2017</Detail>
</ItemNum>
The script will process the items from the XML and iterate through the itemlist, similar to below:
[xml]$xml = Get-Content -Path $xmlPath
Foreach ($websResponse in $websResponseList) {
<Create New Element>
<Add Webs Response to Element>
}
$xml.save($xmlPath)
The result should be the original XML modified to look like the below:
<ItemNum>
<Key>11233</Key>
<Item>123.jpg</Item>
<Item>456.jpg</Item>
<Item>789.jpg</Item>
<Detail>Processed on 8-12-2017</Detail>
<WebS>00001</WebS>
<WebS>00002</WebS>
<WebS>00003</WebS>
</ItemNum>
I've read countless articles on working with XML in Powershell and probably some that are very similar what I'm trying to achieve but this is for some reason stumping me so would appreciate any pointers.
You're almost there:
[xml]$xml = Get-Content -Path $xmlPath
foreach ($websResponse in $websResponseList)
{
$elem = $xml.CreateElement('WebS','00001') # substitute with data
$xml.ItemNum.AppendChild($elem)
}
$xml.save($xmlPath)

Function to return smallest db is not working

I have some PoSH function that I found online that will return the smallest exchange database. In testing the script I found that it does not work as intended; that is the smallest database returned is not actually correct.
This is the code:
#http://izzy.org/scripts/Exchange/Admin/Create-Mailbox.ps1
$DBFilter = "MBX_*" # Limit databases to only those that start with "Primary"
Function Get-SmallestDB {
Try {
$MBXDbs = Get-MailboxDatabase | ? {$_.Identity -like $DBFilter }
$MBXDBCount = $PSSessions.Count
}
Catch {
$MBXDBCount = 0
}
If (!$MBXDbs) {ExitScript "find databases with a name that matches a filter of [$DBFilter]." $False}
# Loop through each of the MBXDbs
ForEach ($MBXDB in $MBXDbs) {
# Get current mailboxes sizes by summing the size of all mailboxes and "Deleted Items" in the database
$TotalItemSize = Get-MailboxStatistics -Database $MBXDB | %{$_.TotalItemSize.Value.ToMB()} | Measure-Object -sum
$TotalDeletedItemSize = Get-MailboxStatistics -Database $MBXDB.DistinguishedName | %{$_.TotalDeletedItemSize.Value.ToMB()} | Measure-Object -sum
$TotalDBSize = $TotalItemSize.Sum + $TotalDeletedItemSize.Sum
Write-Host "$MBXDB $($TotalItemSize.Sum) $($TotalDeletedItemSize.Sum) $TotalDBSize"
# Compare the sizes to find the smallest DB
If (($TotalDBSize -lt $SmallestDBsize) -or ($SmallestDBsize -eq $null)) {
$SmallestDBsize = $DBsize
$SmallestDB = $MBXDB }}
return $SmallestDB }
Basically when i run this in my Exchange environment it returns "MBX_20" as $SmallestDB. But I added some debug code (Write-Host to output values for $($TotalItemSize.Sum, $($TotalDeletedItemSize.Sum) and $TotalDBSize and the results are:
MBX_1 140561 5180 145741
MBX_2 190865 15882 206747
MBX_3 174393 1714 176107
MBX_4 122362 6479 128841
MBX_5 108833 15409 124242
MBX_6 196569 13793 210362
MBX_7 114298 2144 116442
MBX_8 140896 21558 162454
MBX_9 160024 13364 173388
MBX_10 188268 6046 194314
MBX_11 132256 15300 147556
MBX_12 173262 6486 179748
MBX_13 101107 3761 104868
MBX_14 131453 4930 136383
MBX_15 134682 4424 139106
MBX_16 146767 12484 159251
MBX_17 155224 2074 157298
MBX_18 117147 12270 129417
MBX_19 129101 6597 135698
MBX_20 134675 9059 143734
As you can see MBX_20 with 143734 is NOT the smallest db. I am now trying to fix the code but I am not very good with PoSH. Any tips?
Taking from my comment, I think it's a typo and
$SmallestDBsize = $DBsize
should be
$SmallestDBsize = $TotalDBSize

Unable to update a value in msbuild proj file using powershell

I am trying to read a .csproj file using powershell by converting it into xml file to increment WPF app version value. I am able to read the value without any issue and incremented the version value but when I try to save the file with new value, the value doesn't get saved. The code I pasted in this question is to update the QA details.
I am trying to read the below file. How do i update and save file
<Choose>
<When Condition=" '$(BuildEnvironment)' == 'QA' ">
<PropertyGroup>
<ApplicationVersion>1.0.0.1</ApplicationVersion>
<PublishDirectory>C:\TestDirectory</PublishDirectory>
<InstallUrl>http://testurl/testapp</InstallUrl>
<ProductName>Test1.QA</ProductName>
<PublishAssemblyName>Test1.QA</PublishAssemblyName>
</PropertyGroup>
<ItemGroup>
<Tokens Include="ApplicationManifestFileName">
<ReplacementValue>Test1.QA.application</ReplacementValue>
<Visible>false</Visible>
</Tokens>
</ItemGroup>
</When>
<When Condition=" '$(BuildEnvironment)' == 'Production' ">
<PropertyGroup>
<ApplicationVersion>1.0.0.0</ApplicationVersion>
<PublishDirectory>C:\TestDirectory2</PublishDirectory>
<InstallUrl>http://test2url/test2app/</InstallUrl>
<ProductName>Test=2.Prod</ProductName>
<PublishAssemblyName>Test2.Prod</PublishAssemblyName>
</PropertyGroup>
<ItemGroup>
<Tokens Include="ApplicationManifestFileName">
<ReplacementValue>Tes2.Prod.application</ReplacementValue>
<Visible>false</Visible>
</Tokens>
</ItemGroup>
</When>
$Test1QAMSBuildFile = 'C:\Directory\Test.csproj'
[xml]$Test1QABuildVersion = Get-Content $Test1QAMSBuildFile
$CurrentQAVersion= $Test1QABuildVersion.Project.Choose.when.PropertyGroup | ? { $_.ProductName -eq 'Test1.QA' } | Select-Object -Property ApplicationVersion
$PropertyVersion= $CurrentQAVersion.ApplicationVersion
$UpdateVersion= $PropertyVersion.split(".")
$major= [int] ($Updateversion[0])
$minor= [int] ($Updateversion[1])
$patch= [int] ($Updateversion[2])
$revision=[int] ($Updateversion[3])
$newrevisionversion= $revision+1
$newVersion =( [string] $major )+ "."+ ( [string] $minor) +"."+ ([string]$patch ) +"."+ ([string]$newrevisionversion )
$UpdateVersion ="$newVersion"
$TestQABuildVersion.Save("Test1QAMSBuildFile")`
After I added the closing </Choose> I removed .Project from line 3, so you may need to alter what I give you to properly apply to your file.
You never updated $TestQABuildVersion, only some other things that referenced it. What you probably want to do is:
$Test1QAMSBuildFile = 'C:\Directory\Test.csproj'
[xml]$Test1QABuildVersion = Get-Content $Test1QAMSBuildFile
$PropertyVersion = $Test1QABuildVersion.Choose.when.PropertyGroup | ? { $_.ProductName -eq 'Test1.QA' } | Select -Expand ApplicationVersion
$UpdateVersion = $PropertyVersion.split(".")
$UpdateVersion[3] = 1+$UpdateVersion[3]
$newVersion = $UpdateVersion -join "."
$Test1QABuildVersion.Choose.when.PropertyGroup | ? { $_.ProductName -eq 'Test1.QA' } | %{$_.ApplicationVersion = $newVersion}
$TestQABuildVersion.Save($Test1QAMSBuildFile)
Below is code that will work on the example you have given. The main thing you need to keep in mind is that you are dealing with an xml object rather than a powershell object. Selecting the node to be updated requires using SelectSingleNode and specifying an x-path. Using the xml InnerText property allows you to get and set the value. The code below has been tested with the Test.csproj file you provided.
$Test1QAMSBuildFile = 'C:\Directory\Test.csproj'
[xml]$Test1QABuildVersion = Get-Content $Test1QAMSBuildFile
$node = $Test1QABuildVersion.SelectSingleNode("/Choose/When/PropertyGroup/ApplicationVersion[../ProductName = 'Test1.QA']")
$PropertyVersion= $node.InnerText
$UpdateVersion= $PropertyVersion.split(".")
$UpdateVersion[3] = (($UpdateVersion[3] -as [int]) + 1).ToString()
$newVersion = $UpdateVersion -join '.'
$node.InnerText = $newVersion
$Test1QABuildVersion.Save($Test1QAMSBuildFile)
In the case of a real csproj file you will also have to deal with namespaces since the Project element specifies a namespace. I've done bulk modifications to csproj files in the past and it involved quite a learning curve.