Mini-blog: Wait for VM to come online, then execute Powershell direct

During my labbing I’ve noticed I often need to wait for the VM to get online before executing some script or commands, to do that I use the following script:

First we get the VM Name, and enter the credentials for that specific VM:

$VMName = read-host "Please enter the VM-Name"
$VM = get-vm $VMName
$cred = Get-Credential -Message "Please enter credentials for the VM"

By getting the VM status we can use the VM.Heartbeat to check the actual status. We’re currently counting on the VM to be an unmonitored VM so the result we expect is “OkApplicationsUnknown” – This means the OS is up but the hypervisor has no idea if the VM applications are “healthy”.

To wait for the VM to get online we use a while loop to keep checking the heartbeat and if the status changes.

$VM = get-vm $VMName
} while ($vm.Heartbeat -ne "OkApplicationsUnknown")

Directly after the loop we are sure the VM is online, so we can execute our script via PowerShell Direct, here I simply print the hostname. 🙂

invoke-command -vmname $vmname -Credential $cred -ScriptBlock {write-host "My name is $env:COMPUTERNAME"}

Happy scripting!

App-V screenshot

Using App-v to deploy Office 2016 on RDS servers

Hi All!

At my current employeer we have a lot of clients that use RDS servers, in the SMB often you see that applications are installed directly on the RDS server. That means that if you have a Highly Available solution there often is a difference between applications installed.

To prevent this we use Microsoft’s App-V for RDS servers. App-V is included in your RDS Client Access Licenses so in essence its “free”. The cool thing about app-v is that by using application virtualisation you no longer have to install any application but simply publish them to the users or computers you want them to run.

To learn more about app-v you can check this technet page.

Microsoft has really embraced app-v as part of the OS and it is now installed by default on Server 2016 and Windows 10. To start with App-V we will create a package, and publish it on a RDS2016 server without using the rest of the app-v infrastructure. This is called a “Stand-Alone app-v deployment”


  • A preconfigured RDS 2016 server.
  • The Office 2016 Deployment toolkit found here
  • XML file with the features you want in your App-V package from here

First we will configure our RDS2016 to be able to run App-V packages, to do that run the following command as administrator within PowerShell

Set-AppvClientConfiguration -EnablePackageScripts $true

After restarting you can check the app-v status with the following powershell command


With the above commands we do not only enable App-V but also “package Scripting”. Packages with extended functionality such as office require the running on scripts within the app-v packages. The default setting forbids any scripts from running for security reasons.

After you see that App-v is enabled we can move on to creating the app-v package. To move on we download the Office Deployment Toolkit and our XML file to C:\ODT, we rename the XML file to “SETUP.XML” Then we open a CMD.EXE window as administrator and enter the following command:


The setup will now run and create a App-v package out of the selected office components, after the setup completes you can copy C:\ODT\AppvPackage to a location of your choice. I’d advise to collect all of your application packages on a DFS-R share but for the purpose of this lab the location does not truly matter.

After copying the files you execute the following Powershell command to make the package available for the RDS 2016 machine:

Add-AppvClientPackage -Path "<PATH TO YOUR APPV file>" | Publish-AppvClientPackage -Global | Mount-AppvClientPackage -Verbose

To only make the package available to a specific user you can execute the following powershell command as administrator:

Add-AppvClientPackage -Path "<PATH TO YOUR APPV file>" | Publish-AppvClientPackage

And to finish you simply mount the file as the end-user by running:

get-appvclientpackage -all | Mount-AppvClientPackage -Verbose

And tada; you’ve deployed office to the RDS without installing the actual software. You’re currently running Office in a virtual bubble. When running this in production I’d truly suggest looking into an App-V Publishing server to make management much easier. 🙂

Free online powershell training

Hi all!

After a couple of weeks of silence I have some great news; I will be giving free online powershell courses for beginners and intermediates. Hopefully I’ll be able to assist some of you in questions you have about your own scripts, or scripts you’ve used from my blog.

The first course will be August 7 at 19:00 GMT+1. You can join the course by emailing me at Kelvin [at] Limenetworks.nl or via the following Skype for Business URL: Skype for Business Meeting

In the first course I will be focusing on using Powershell in your day-to-day operations and automating minor tasks. It’ll be hands-on as much as possible and not only focus on theory. there will be room for questions during the one hour course.

Hope to see you there!