Azure image: How I can create schedule task where users group does not exist for now?

0

I'm creating image in azure and have a schedule task which has to run on any user login.

  1. Image created in sperate environment where domain does not exist
  2. After VM creation it will join domain
  3. We want to allow users in particular group like FutureDomain\Domain Users to be able to 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?

azure
powershell
virtual-machine
asked on Stack Overflow Dec 22, 2020 by Jagdish Idhate

1 Answer

0

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.

answered on Stack Overflow Jan 11, 2021 by Satya V

User contributions licensed under CC BY-SA 3.0