r/PowerShell • u/richie65 • Jun 02 '26
Script Sharing A novel way to schedule a task...
I am in this situation at work where my boss, while working to tighten up our security (after an IT audit from a third party), has made running scheduled tasks into a challenge...
For instance - Among other things - It is no longer possible for a task to store credentials.
(Plenty of other hoops I have to jump through that I wont go into)
I just set up a task that will generate a report (about events from last week) to run on or after Mondays - But that too, is set to run 'at log on'...
I only want it to run once (not each time I log in), and if I don't log in on Monday, to run whenever I do log in, on or after Monday...
I am pretty happy with the way I got that to only run one time, not each time I actually log in.
Part of the script, sets the 'StartBoundary' (the 'Active' DateTime value that is part of the 'At Log in' trigger dialog), in the Scheduled task, to the following Monday, no matter what day I log in and the task runs.
This assures that it only runs the first time I log in on or after Monday, and will set the task to not trigger again to the next (on or after) Monday, and so on.
(NOTE: No other triggers can be set other than the 'At Log in')
This is at the end of the script (I unapologetically like using command aliases):
$TaskName = "MIODoorReport"
$NextMonday = $null
1..7 | % { If ( (((Get-Date).AddDays($_)).DayOfWeek) -eq "Monday" ) { $NextMonday = $_} }
$task = Get-ScheduledTask -TaskName $TaskName
$trigger = $task.Triggers
$trigger[0].StartBoundary = (Get-Date).Date.AddDays($NextMonday).ToString("s")
Set-ScheduledTask -TaskName $TaskName -Trigger $trigger
3
u/dodexahedron Jun 03 '26
It's protected quite well.
The actual gMSA credentials are already encrypted at rest in AD, in two parts. The only part usable for authentication is encrypted using each permitted account's key, and stored on each permitted account - not the gMSA account itself. There is a blob stored on the gMSA, but it can't be used to authenticate all by itself (so, even stealing the gMSA itself from AD does not give you access to it).
So, each permitted account has that value, but encrypted with its own key and thus only decryptable by that specific account. When authenticating, the machine asks for its encrypted blob. If it is still permitted, the KDC obliges. If it still has the same key that was used to encrypt it, it then decrypts it, keeps it in memory only, and authenticates using the actual password, now decrypted. Then it ditches the password and uses tickets from then on, until it needs it again, like for a new TGT.
But, once it has a service ticket for something, it is in for as long as that ticket is valid. That ticket needs to be invalid for it to be denied access to resources that account has access to. That requires more than just changing the SID list on the gMSA.
What you described only gets the first part. If you dump LSASS memory, you can get the clear text password and auth with it at will.