Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Run scheduled task and loop check if task is done

$
0
0

Hi guys,

I made a script to automate the process of creating an AD user, but it does not sync with our online environment until we run a manual scheduled task.

I have a Windows Server 'SRVAD90' that has a scheduled task to synchronize Azure AD with local AD to complete creation of AD users. I've looked through the forum but couldn't find a lot that's related to this problem and I hope you have some time to give me a little assistance.

Windows Server 'SRVMG90' has a scheduled task 'Azure AD Sync Scheduler';

This task will be run manually by the use of Start-ScheduledTask;

The script needs to loop check every few seconds if the Scheduled Task is completed;

If the Scheduled Task is completed it will make the e-mail account of the user in the Office Portal due to synchronizing, the script needs to loop check if the user is created in the Office Portal;

The Office License needs to be added to the user

The things I have:

Starting the scheduled task

Start-ScheduledTask -Task "Azure AD Sync Scheduler" -TaskPath D:\path\azureadsync.exe


Office License activation

Import-Module MSOnline Connect-MsolService $HomeDrive = Import-Csv \\path\UserInfo.csv ForEach ($HomeDrive in $HomeDrive) { $User = $Homedrive.UserPrincipalName Set-MsolUser -UserPrincipalName $User -UsageLocation NL Set-MsolUserLicense -UserPrincipalName $User -AddLicenses "company:ENTERPRISEPACK" }



The things I'm missing:

Loop check for scheduled task completion

Loop check for created user 
(I have the users in a UserInfo.csv with $_.SamAccountName, $_.name, $_.userPrincipalName, etc. to find the user)











Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>