Vagrant with Windows Server 2019 - Check if "Applying computer settings is done"

Hi there,

Wondering if it’s possible to check if “Applying computer settings” is done via vagrant/powershell.

I’m currently trying to install my domain controller and automate the creation of organisational units/users/groups through more scripts.

After the AD install the VM needs a reboot to be able to run those extra scripts.

Is there a way? I’m currently setting a sleep time of aprox 6 minutes to bypass my scripts not waiting for the “Applying computer settings”.

This is the part in my vagrantFile where I need the reboot and the scripts running after it:

# Provision everything on the first run
    cfg.vm.provision "shell" do |s|
      s.path        = "scripts/01_install_ad.ps1"
      s.privileged  = false
      s.args        = [var_domain_name, var_domain_mode, var_public_ip, var_public_dns1, var_default_password]
    end
    
    # reboot server after AD role deploy
    cfg.vm.provision "shell", reboot: true
    cfg.vm.provision "shell", path: "scripts/02_createOU.ps1", privileged: false
    cfg.vm.provision "shell", path: "scripts/03_createUsers.ps1", privileged: false
    cfg.vm.provision "shell", path: "scripts/04_policies.ps1", privileged: false

Bypass the waiting script:

Write-Host "Waiting until system fully booted"
Start-Sleep -s 360
New-ADOrganizationalUnit -Name "IT Administratie" -Path "DC=CORONA,DC=local"
New-ADOrganizationalUnit -Name "Verkoop" -Path "DC=CORONA,DC=local"
New-ADOrganizationalUnit -Name "Administratie" -Path "DC=CORONA,DC=local"
New-ADOrganizationalUnit -Name "Ontwikkeling" -Path "DC=CORONA,DC=local"
New-ADOrganizationalUnit -Name "Directie" -Path "DC=CORONA,DC=local"

Hope someone can help me!

One suggested way around this problem that might work for you is after the reboot, have your script loop and sleep until it can properly pull the AD object for the local machine. Once it has that, the other AD actions should work properly.

I’m new to Powershell automation and Vagrant.
I’ve been looking for a way to get this object but I can’t seem to find how to check if it’s actually a valid object. Are we trying to use the Get-ADObject commandlet to get a valid state?