Start a Conversation

Unsolved

This post is more than 5 years old

R

7134

February 10th, 2011 13:00

Help with powershell PNTools upgrade script

Could someone help me with a powershell script to update all our VDI machines to the latest PNtools?

What I'm looking for is the following:

A script that can be launched at night.

It should upgrade max. 10 virtual machines (or any number we specify).

It should only upgrade VM's that are turned off, or suspended, or running without someone logged in.

The steps would probably look like this:

Power on VM

uninstall PNtools

reboot

install PNtools

shutdown

Another problem is that I can't include a password to the powershell. You can specify a username to execute the script, but you have to type the password yourself. This way we can never automate this. Any tips?

Any help would be very welcome.

15 Posts

February 10th, 2011 14:00

Hey René,

Did you have a look at the blog post regarding this topic? If not have a gander at this.

If you still have questions after reading please let me know. As for the password issue you can do something like this:

Function Get-ConsoleCredential([String] $username, [String] $password)

{

        New-Object Management.Automation.PSCredential $username, (ConvertTo-SecureString $password -AsPlainText -Force)

}

This will return a PScredential object with the proper username and password set.

1 Rookie

 • 

74 Posts

February 14th, 2011 07:00

Hello Adam,

That script looks very nice, but we don't have any powershell guru's in house.

I would be very happy if the following functionality could be added to the script:

Only upgrade machines that are currently powered off.

AND / OR

Only upgrade machines that are specified in a list or txt file.

This way we have more control and can inform a group of users that their machines will be upgraded tonight or something.

15 Posts

February 14th, 2011 14:00

Hey René,

I've included an updated script that will query for all VMs that do not have the current PNTools version installed and are currently Powered Down. If you look in the script you will see CurrentState = 1, which indicates that a machine is Powered Down.

If you have a text file of machines you could do something like:

Get-Content "Machines.txt" | Invoke-QVWCommand -Action UninstallMSI -MSIPackage "PNTools"

Get-Content "Machines.txt" | Invoke-QVWCommand -Action InstallMSI -MSIPackage "PNTools"

This would queue up an uninstall and then an install for all the machines in the text file. The file would have to have one machine per line. If it is more convient to have a comma seperated list you could also do something like this:

Get-Content "Machines.txt" | ForEach-Object { $_.Split(',') } | Invoke-QVWCommand -Action UninstallMSI -MSIPackage "PNTools"

Get-Content "Machines.txt" | ForEach-Object { $_.Split(',') } | Invoke-QVWCommand -Action InstallMSI -MSIPackage "PNTools"

Hope this helps!

1 Rookie

 • 

74 Posts

February 22nd, 2011 12:00

Thanks, but this isn't working very well.

First the VM is powered up, but then the next pending task that should uninstall pntools fails:

Virtialization Management Server reported no IP Adress for computer.

Then it tries to install pntools and fails again because it wasn't uninstalled in the first place.

It takes some time before the ip adress is being reported by vmware esx. Too bad it times out so quickly.

173 Posts

February 22nd, 2011 13:00

Hmmm... I think a check of the powerstate would do the trick.... mayabe Adam knows :-)

101 Posts

February 22nd, 2011 14:00

I would also check by manually powering on a VM in the vWorkspace console that it does report a IP address.  It might be a timing issue with the script or something else, for example the VMs really are not getting a IP address.

15 Posts

February 22nd, 2011 18:00

Here is an updated script that calls the Invoke-QVWComputerAction -Action PowerOn command. Then the script will wait for the machine to report an IPAddress. Once this happens it will begin the installation. Alternatively, I've included the below script using the text files I mentioned in previous posts.

Get-Content "Machines.txt" | ForEach-Object { $_.Split(',') } | Invoke-QVWCommand -Action PowerOn

Start-Sleep 150

Get-Content "Machines.txt" | ForEach-Object { $_.Split(',') } | Invoke-QVWCommand -Action UninstallMSI -MSIPackage "PNTools"

Get-Content "Machines.txt" | ForEach-Object { $_.Split(',') } | Invoke-QVWCommand -Action InstallMSI -MSIPackage "PNTools"

Hope this helps!

1 Rookie

 • 

74 Posts

February 23rd, 2011 07:00

The script is very neat, but I'm a bit scared to use it on our production environment

The other 'easy' script is perfect. Using a timeout will do the trick. Might not be the most elegant way but it works and that is what counts.

This is what I'm using now:


get-content "upgrade.txt" | Set-QVWComputer -Enabled false -farm "vWorkspace Database"
Start-Sleep -Seconds 5
get-content "upgrade.txt" | Invoke-QVWComputerAction -Action PowerOn -farm "vWorkspace Database"
Start-Sleep -Seconds 120
get-content "upgrade.txt" | Invoke-QVWComputerAction -Action UninstallMSI -MSIPackage "PNTools" -farm "vWorkspace Database"
Start-Sleep -Seconds 300
get-content "upgrade.txt" | Invoke-QVWComputerAction -Action InstallMSI -MSIPackage "PNTools" -farm "vWorkspace Database"
Start-Sleep -Seconds 300
get-content "upgrade.txt" | Invoke-QVWComputerAction -Action InstallMSI -MSIPackage "NWGina" -farm "vWorkspace Database"
Start-Sleep -Seconds 60
get-content "upgrade.txt" | Invoke-QVWComputerAction -Action ShutdownOS -farm "vWorkspace Database"
Start-Sleep -Seconds 5
get-content "upgrade.txt" | Set-QVWComputer -Enabled default -farm "vWorkspace Database"

It takes about 15 minutes to upgrade a client. To prevent users from logging in during the upgrade, the script disables the VM before the upgrade and enables it when it's done.

Thanks all!

15 Posts

February 23rd, 2011 11:00

Great! I'm glad that you got it to work.

No Events found!

Top