# Start-Job question

**URL:** <https://forums.powershell.org/t/start-job-question/14324>\
**Category:** PowerShell Help\
**Created:** [May 5, 2020, 12:48am UTC](https://forums.powershell.org/t/start-job-question/14324 "2020-05-05T00:48:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![acer4605](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@acer4605](https://forums.powershell.org/u/acer4605)\
**Post date:** [May 5, 2020, 12:48am UTC](https://forums.powershell.org/t/start-job-question/14324/1 "2020-05-05T00:48:59Z")

</div>

Hi,

I’m running several scripts on the AD on prem server and also need to execute a script on our Azure ADServer, the last script can only run after the sync interval of 30 min.

there are in my limited opinion two ways to tackle this

1 run script 1 and 2 then put a sleep for 1 hour and then continue with the Azure AD part.

if I go along this path can I run this particular script asjob and does this job needs to be retrieved after 1 hour?  
Or use the output [pre]Get-MsolCompanyInformation | select lastdirsynctime[/pre] and than start the script that runs on Azure AD  
with the last option I noticed that the last sync is done on 05/05/2020 05h19 while my local time is 07h19  
is there a way to continue with the Azure ad script after last sync + minimal 30 min?

I’m able to get time adjusted so that it matches the time on the server with this  
[pre]Get-MsolCompanyInformation | select lastdirsynctime  
$h = (Get-Date).AddHours(-2).ToString(“dd/MM/yyyy HH:mm:ss”)

[/pre]  
my question is now how do I substract $h from lastdirsynctime?

&nbsp;

---

<div class="post-metadata">

**Author:** ![mitchvh](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mitchvh](https://forums.powershell.org/u/mitchvh)\
**Post date:** [May 5, 2020, 10:32am UTC](https://forums.powershell.org/t/start-job-question/14324/2 "2020-05-05T10:32:54Z")

</div>

```
$LastSync = Get-MsolCompanyInformation | select lastdirsynctime
$DateTime = (Get-Date).AddHours(-2)

$TimeSpan = $LastSync - $DateTime
```

Not sure if that’s really what you are looking for though.

I haven’t had to do something like this before (scheduling tasks on AzureAD from a local source at a dynamic time), however you might look into Azure Runbooks and Automation. I’d assume it would be possible to kick off a Runbook at a specific time.

---

<div class="post-metadata">

**Author:** ![acer4605](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@acer4605](https://forums.powershell.org/u/acer4605)\
**Post date:** [May 5, 2020, 12:01pm UTC](https://forums.powershell.org/t/start-job-question/14324/3 "2020-05-05T12:01:16Z")

</div>

thanks  
this is what I was looking for

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/start-job-question/14324/4 "2024-05-16T20:29:41Z")

</div>


