I have been tasked at work to automate the monthly maintenance. Basically I need to edit the date values in an xmla file to the next month.
This is the relevant section in the XMLA file:
<Process xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Type>ProcessFull</Type>
<Object>
<DatabaseID>OLAPQA</DatabaseID>
<CubeID>Model</CubeID>
<MeasureGroupID>TRANSACTIONS</MeasureGroupID>
<PartitionID>TRANSACTIONS 201410</PartitionID>
</Object>
</Process>
<Process xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Type>ProcessFull</Type>
<Object>
<DatabaseID>OLAPQA</DatabaseID>
<CubeID>Model</CubeID>
<MeasureGroupID>TRANSACTIONS</MeasureGroupID>
<PartitionID>TRANSACTIONS 201411</PartitionID>
</Object>
</Process>
<Process xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Type>ProcessFull</Type>
<Object>
<DatabaseID>OLAPQA</DatabaseID>
<CubeID>Model</CubeID>
<MeasureGroupID>TRANSACTIONS</MeasureGroupID>
<PartitionID>TRANSACTIONS 201412</PartitionID>
</Object>
</Process>
I need to write a windows powershell script with the following logic:
- Get current date and verify if it’s the first day of the month
- If yes, then calculate the previous day (in order to calculate previous 2 year/month values )
- Search XMLA file to replace previous year/month combinations with new values
I have solved number 1 and 2 but I am having some trouble with number 3.
This is my code:
$con = Get-Content .\Process2Periods.xmla
$con | % { $_.Replace("((Get-Date).AddMonths(-2) | Get-Date -Format "yyyyMM")", ("((Get-Date).AddMonths(-1) | Get-Date -Format "yyyyMM")") } | Set-Content .\Process2Periods.xmla
How I got to this was running the following code which worked unlike the code above:
$con = Get-Content .\Process2Periods.xmla
$con | % { $_.Replace("201410", "201411") } | Set-Content .\Process2Periods.xmla
My question is how to make this dynamic instead of hard coding the values into the script. I will need this to change the three tags every month. The code works with the string values but how do I take the output of some code as the string value? Should I use variables?
Thanks in advance.