I have succeeded (thanks to SO) in editing the following xml file (created automatically by the Active Directory GPO feature) with the help of xml linq. However, I would like to achieve the same result by using less code if possible, hence by going with the member-access enumeration available in PowerShell, plus I need to leave untouched the third TaskV2 element named wsus-extraMaintenance. The goal is to amend the date and time in the StartBoundary element.
<?xml version="1.0" encoding="utf-8"?>
<ScheduledTasks clsid="{CC63F200-7309-4ba0-B154-A71CD118DBCC}">
<TaskV2 clsid="{D8896631-B747-47a7-84A6-C155337F3BC8}" name="VBS" image="1" changed="2022-12-01 09:28:19" uid="{6128F739-7B10-4D53-B8B2-4F7D8D518B39}"><Properties action="R" name="VBS" runAs="NT AUTHORITY\System" logonType="S4U"><Task version="1.2"><RegistrationInfo><Author>Username</Author><Description>Text</Description></RegistrationInfo><Principals><Principal id="Author"><UserId>NT AUTHORITY\System</UserId><LogonType>S4U</LogonType><RunLevel>HighestAvailable</RunLevel></Principal></Principals><Settings><IdleSettings><Duration>PT10M</Duration><WaitTimeout>PT1H</WaitTimeout><StopOnIdleEnd>true</StopOnIdleEnd><RestartOnIdle>false</RestartOnIdle></IdleSettings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>true</StopIfGoingOnBatteries><AllowHardTerminate>true</AllowHardTerminate><StartWhenAvailable>false</StartWhenAvailable><RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable><AllowStartOnDemand>true</AllowStartOnDemand><Enabled>true</Enabled><Hidden>false</Hidden><RunOnlyIfIdle>false</RunOnlyIfIdle><WakeToRun>false</WakeToRun><ExecutionTimeLimit>P3D</ExecutionTimeLimit><Priority>7</Priority></Settings><Actions Context="Author"><Exec><Command>%systemroot%\System32\cscript.exe</Command><Arguments>pathToScript</Arguments></Exec>
</Actions><Triggers><CalendarTrigger><StartBoundary>2022-03-27T14:30:00</StartBoundary><Enabled>true</Enabled><ScheduleByMonthDayOfWeek><Weeks><Week>3</Week></Weeks><DaysOfWeek><Wednesday></Wednesday></DaysOfWeek><Months><January></January><February></February><March></March><April></April><May></May><June></June><July></July><August></August><September></September><October></October><November></November><December></December></Months></ScheduleByMonthDayOfWeek><ExecutionTimeLimit>PT4H</ExecutionTimeLimit><Repetition><Interval>PT1H</Interval><Duration>PT1H</Duration><StopAtDurationEnd>false</StopAtDurationEnd></Repetition></CalendarTrigger>
</Triggers></Task></Properties></TaskV2>
<TaskV2 clsid="{D8896631-B747-47a7-84A6-C155337F3BC8}" name="PS" image="1" changed="2022-12-01 09:28:05" uid="{27A6954B-DC81-42CE-ACA3-FB70CD1DDC98}"><Properties action="R" name="PS" runAs="NT AUTHORITY\System" logonType="S4U"><Task version="1.2"><RegistrationInfo><Author>Username</Author><Description>Text</Description></RegistrationInfo><Principals><Principal id="Author"><UserId>NT AUTHORITY\System</UserId><LogonType>S4U</LogonType><RunLevel>HighestAvailable</RunLevel></Principal></Principals><Settings><IdleSettings><Duration>PT10M</Duration><WaitTimeout>PT1H</WaitTimeout><StopOnIdleEnd>true</StopOnIdleEnd><RestartOnIdle>false</RestartOnIdle></IdleSettings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>true</StopIfGoingOnBatteries><AllowHardTerminate>true</AllowHardTerminate><StartWhenAvailable>false</StartWhenAvailable><RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable><AllowStartOnDemand>true</AllowStartOnDemand><Enabled>true</Enabled><Hidden>false</Hidden><RunOnlyIfIdle>false</RunOnlyIfIdle><WakeToRun>false</WakeToRun><ExecutionTimeLimit>P3D</ExecutionTimeLimit><Priority>7</Priority></Settings><Actions Context="Author"><Exec><Command>powershell.exe</Command><Arguments>pathToScript</Arguments></Exec>
</Actions><Triggers><CalendarTrigger><StartBoundary>2022-03-27T14:30:05</StartBoundary><Enabled>true</Enabled><ScheduleByMonthDayOfWeek><Weeks><Week>3</Week></Weeks><DaysOfWeek><Wednesday></Wednesday></DaysOfWeek><Months><January></January><February></February><March></March><April></April><May></May><June></June><July></July><August></August><September></September><October></October><November></November><December></December></Months></ScheduleByMonthDayOfWeek><ExecutionTimeLimit>PT4H</ExecutionTimeLimit><Repetition><Interval>PT1H</Interval><Duration>PT1H</Duration><StopAtDurationEnd>false</StopAtDurationEnd></Repetition></CalendarTrigger>
</Triggers></Task></Properties></TaskV2>
<TaskV2 clsid="{D8896631-B747-47a7-84A6-C155337F3BC8}" name="wsus-extraMaintenance" image="1" changed="2022-05-05 14:10:03" uid="{7C7EAD3B-21AF-49CD-A3FA-65CDD588FAD8}"><Properties action="R" name="wsus-extraMaintenance" runAs="NT AUTHORITY\System" logonType="S4U"><Task version="1.2"><RegistrationInfo><Author>Username</Author><Description>Text</Description></RegistrationInfo><Principals><Principal id="Author"><UserId>NT AUTHORITY\System</UserId><LogonType>S4U</LogonType><RunLevel>HighestAvailable</RunLevel></Principal></Principals><Settings><IdleSettings><Duration>PT10M</Duration><WaitTimeout>PT1H</WaitTimeout><StopOnIdleEnd>true</StopOnIdleEnd><RestartOnIdle>false</RestartOnIdle></IdleSettings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>true</StopIfGoingOnBatteries><AllowHardTerminate>true</AllowHardTerminate><StartWhenAvailable>false</StartWhenAvailable><AllowStartOnDemand>true</AllowStartOnDemand><Enabled>true</Enabled><Hidden>false</Hidden><ExecutionTimeLimit>P3D</ExecutionTimeLimit><Priority>7</Priority></Settings><Triggers><CalendarTrigger><StartBoundary>2022-04-29T07:00:00</StartBoundary><Enabled>true</Enabled><ScheduleByDay><DaysInterval>1</DaysInterval></ScheduleByDay><ExecutionTimeLimit>PT2H</ExecutionTimeLimit></CalendarTrigger>
</Triggers><Actions Context="Author"><Exec><Command>powershell.exe</Command><Arguments>pathToScript</Arguments></Exec></Actions></Task></Properties></TaskV2>
</ScheduledTasks>
However, when I go with
[xml]$report = Get-Content -Path "$((Get-PSDrive 'S').Root)\ScheduledTasks.xml"
$report.ScheduledTasks.TaskV2 | ForEach-Object {
if($_.Name -notlike "wsus*"){
$_.Properties.Triggers.CalendarTrigger.StartBoundary #= Get-Date
}
}
I get nothing in return, and no errors. If I uncomment the Get-Date I get an error saying The property 'StartBoundary' cannot be found on this object.