I'm creating image in azure and have a schedule task which has to run on any user login.
Now, when I try to create Image script fails with error
$argument = "bla1"
$Action = New-ScheduledTaskAction -Execute "bla-bla.exe" -Argument $argument
$Trigger = New-ScheduledTaskTrigger -AtLogon
$Principal = New-ScheduledTaskPrincipal -GroupId "FutureDomain\Domain Users"
$Setting = New-ScheduledTaskSettingsSet
$TaskObject = New-ScheduledTask -Action $Action -Principal $Principal -Trigger $Trigger -Settings $Setting
Register-ScheduledTask -TaskName "MyFutureTask" -InputObject $TaskObject
HRESULT 0x80070534,Register-ScheduledTask Register-ScheduledTask : No mapping between account names and security IDs was done.
(13,8):GroupId:
Now question is: How I can create schedule task in image where domain users does not exist?
As far as I have researched, I don't think there is a way to create schedule task in image where domain users does not exist.
The alternative I can think of is that :
You can create a scheduled task which checks whether the machine is domain joined - checking the registry for the domain name (for instance) or simple powershell commandlet
if the scheduled script finds a domain - then it can trigger other script which takes care of adding the domain users. (or you can use the "else" part of the above scheduled task.
User contributions licensed under CC BY-SA 3.0