Watch out, extended OS disk in Azure IaaS VM makes it not bootable

After a week of Azure Ninja course at Microsoft Sweden I wanted to dig a bit deeper into Azure IaaS.

I found that the Update-AzureDisk had a new parameter that looked interesting -ResizedSizeInGB and I wanted to test that one in real action on the OS disk which resulted in a VM that could no longer be started :-(. As described in an earlier post it was a bit more difficult to extend a vhd for a VM in Azure before this powershell way and in those days you had to tear down the VM and throw it away and also the pointer to the blog and after that you could with a tool extend the blob.

Screen Shot 2015-04-23 at 17.22.03

So far it looked good but when I then tried to start the VM I got the error

Screen Shot 2015-04-23 at 18.43.57

This VM was provisioned from the gallery and after reading the blog about the changes in Azure and that the OS disk now could support 1 TB in size i also found this little text saying that it only applied to disks that was migrated to Azure and not the gallery items or already provisioned VM´s…

Screen Shot 2015-04-24 at 14.56.10

So I wanted to test the same thing as above for a migrated vhd, first of all I created a vhd on-premise with 140GB vhd and then used powershell Add-AzureVhd to upload it.

Screen Shot 2015-04-24 at 14.33.45

after that I created a VM and started it with no problems :-)

And then I ran the above resize parameter on this uploaded vhd to extend it to 150GB. With the PowerShell cmdlet I can apply this to a VM that is not running and do not need to remove any relations to the blob or VM´s.

Screen Shot 2015-04-24 at 14.33.22

Started it and as you can see it worked nicely

Screen Shot 2015-04-24 at 14.58.39

Here you can see when looking inside the VM and checking the Disk manager it shows the extra 10 GB

Screen Shot 2015-04-24 at 14.32.34

So watch out if you test to extend your Production VM´s VHD´s depending on where they have come from, although an OS volume does not need to be too large..

I have tested the Update-AzureDisk -ResizedSizeInGB on VM Data disks without any issues no matter if they were created or uploaded so this warning just points at the OS disk!

My Theater Community Session on Ignite – be there or …

Today I was browsing the session catalog on myIgnite and could see that my session “PowerShell Community Jewels” was now added to the list!

Screen Shot 2015-04-22 at 09.21.40

So if you will be going to Chicago and also attending the Microsoft Ignite conference I would love to see you on the Lounge B Theater on Tuesday!

Me self and The Swedish Chef will be there and maybe just maybe there will be a possibility for you to take a selfie with the Chef after the session!

10271304_745037768850455_7817596746289511557_o

(Last year at Teched Houston with Mr PowerShell himself)

 

Playing with the Azure VM agent and changing user on IaaS VM with PowerShell

I am at a Azure training at Microsoft and have been playing a bit with both the portal and PowerShell.

We where talking about the VM agent that is installed on the IaaS VM´s and what functionality it has.

There is a nice and powerful feature that allows you to reset the password for the user from the Azure PowerShell console. The cool part is that you also can change the user on the VM so if you have to take over a Azure IaaS deployment and do not know the username or password for the virtual machines you can change it!

from Keith Mayers blog post I used the PowerShell code and changed both password and username for a user

So first of all in my Windows 2012 R2 I have a user vniklas and I want to change it to Bruno, but as I said above you do not have to know the username that is set inside the VM´s to be able to change it!

Screen Shot 2015-04-20 at 16.33.09

And I use PowerShell to set a credential with username and password:

Screen Shot 2015-04-21 at 10.14.56

And the following change both user and password, updates the VM and then to actually get it to hit on the VM I need to restart the VM:

Screen Shot 2015-04-21 at 10.24.11

And when you then try to use RDP in to the VM you need to use the new password and username and as you can see on the Local Users the account have changed to bruno instead.

Screen Shot 2015-04-20 at 16.21.53

Here is the PowerSHell code to get this to work:

And now as you see that this is so easy you can realize that your Azure subscription account becomes quite important to keep safe and not let anyone get access to it.

May the force be with you!

Hyper-V Powershell module now with 211 cmdlets in build 10041

I have upgraded my windows 10 to the latest build 10041 and activated Hyper-V.

Screen Shot 2015-03-20 at 09.45.22

In this build I can see that there are now 211 cmdlets in the hyper-v PowerShell module:

Screen Shot 2015-03-22 at 10.58.57

And comparing it to the PowerShell module that was released in Windows 8.1/2012 R2 you can see the following new cmdlets, although the Windows 10 is in preview and things can change before it is released!

Screen Shot 2015-03-22 at 11.32.16

I will dig into the new preview release and maybe there will be a followup post on my findings!

Hyper-V VM´s BIN files, to be or not to be in clusters

If you create lots of VM´s with large amount of RAM memory assigned to them and start to wonder why you have used some of the storage on the volumes then this is because if you have set up a VM without changing anything you get a bin file in the VM folder that corresponds to the size of the allocated RAM. This file is used to save the VM`s RAM to disk when the VM is going into saved state!

Screen Shot 2015-02-19 at 12.23.41

In an environment where you have all VM´s as clustered resources you will not need to be able to use the saved state when shutdown the host as you will live migrate the VM´s when doing stuff with the HW.

The setting is easily found in Hyper-V Manager for an already deployed VM:

Screen Shot 2015-02-19 at 12.22.06

It is not so easily found in System Center VMM when checking the VM properties, but when deploying a new VM you find it in the wizard:

Screen Shot 2015-02-19 at 12.29.26

If you want to change the setting for your VM´s running in a cluster via VMM you will have to use PowerShell and it is quite easy to do that with a one-liner, first you see the setting with the PowerShell command Get-SCVirtualMachine and then you can configure it with Set-SCVirtualMachine :

Screen Shot 2015-02-19 at 12.40.18
Screen Shot 2015-02-19 at 13.29.46

And now when checking the folder for the VM the BIN file has magically shrunk to 4KB :-)

Screen Shot 2015-02-19 at 13.44.03

VM Storage Migration in VMM 2012 R2 leaves unwanted leftovers

I have been playing around with a case where we have been upgrading and creating a new Windows Server 2012 R2 Hyper-V cluster and adding CSV volumes to it, and when first volume became full we started to storage migrate the VM´s to another volume but for some reason the files where left behind so I created my own PowerShell function to handle that as the built-in does not have that parameter and for some reason leaves leftovers?!

As you can see when I have done a live storage migration within a Hyper-V host with the GUI in VMM it leaves both vhdx and xml of the VM, and that can be troublesome when someone tries to import that VM while the other is already running and also you do not gain that space you thought would be reclaimed because you did a live storage migration.

Screen Shot 2015-02-16 at 15.38.54

No problem to move but as you can see in the volume that I migrated from:

Screen Shot 2015-02-16 at 15.06.32

And the volume that I migrated to:

Screen Shot 2015-02-16 at 15.06.55

I have been reproducing the migration with either just folders or both folders and vhdx/xml files still at the source..

When I run my function it cleans the source if i use the parameter -deletesource

Screen Shot 2015-02-17 at 15.51.08

Here is the PowerShell function for you to try:

Good luck in your automation :-)

Mass-VDI reconfiguration on vSphere with PowerCLI

A colleague asked me if there was an easy way to reconfigure VM´s that was on different hosts with PowerCLI, for some reason the VM´s had been configured with too many vCPU´s and the customer wanted a way to reconfigure the running VM´s.

I made a very easy PowerCLI script to solve this, maybe there is other solutions that might be better/more beautiful but this one solved the issue :-)

You save this as a script and then run it with the starting name of the VM´s you want to configure, and as you can see you have to already have connected to the vcenter with Connect-VIServer before running it:

Screen Shot 2015-02-16 at 10.25.27

happy automating :-)

Handy way to use PowerShell with VMM 2012 R2

After working with a customer and showing them the PowerShell scripts and functions I had made for automating their VMM 2012 R2 environment I realized that I needed a way to actually let them easily get them loaded and ready for use.

As you might know, you can store scripts within your VMM Library and also run them from the same place! So I thought of saving the functions there and making an initiator script that would load the functions that I had created so they could use them right away.

Really easy script that looks in the functions folder and import all functions, and as it is dynamic it will load all functions available in the folder at the time it is executed:

And when you put it in your VMM library it looks like this, I have added some description to make it more clear what it does 😉

Screen Shot 2015-02-06 at 13.24.40


And you can then run it from the console with the Run button and once the PowerShell console is loaded you can see which functions have been loaded and what names they have :-)

Screen Shot 2015-02-06 at 13.50.07


And in the folder I have added the files containing the functions that I made with .psm1 ending ( I am converting some of the scripts that I made earlier to functions and will add them later, that is why it is quite few yet). You will also have to check and edit the permissions on the share and the SCVMM_Library folder so the user trying to run the script will be able to.

Screen Shot 2015-02-06 at 14.53.50


Also, I added the server in trusted sites otherwise I got this digital signed error and I do not at this moment have a cert to sign the scripts

digitalsignederror

So to get around that one you add in Internet Explorer Trusted SItes: *://vmm02.vmmserver.se (or of course what your VMM server FQDN is)

Screen Shot 2015-02-06 at 14.25.07

Last of all, to be able to run some of the functions that need elevation you can start the VMM GUI Console with “Run As Administrator” but you still use your Windows Credentials:

Screen Shot 2015-02-06 at 14.21.05

Happy automating within VMM :-)

And yes SMA has been thought of but right now the customer do not need that extra complexity with WAP,SMA,SPF and runbook workers…..

HyperV local storage available for placement in SCVMM

I have been working with a customer and was going to do an upgrade of one of their Hyper-v clusters to 2012 R2. During my preparations and looking at the particular hosts I found several VM´s that was residing on local storage on the hosts and not on the cluster storage.

The reason for this was two things, first of all that it was allowed to put VM´s on local disks and second that when someone created the VM´s forgot to use the appropriate HW-template that makes them highly available by default. If you create a new VM with a new HW profile make sure that it is configured correctly under the Availability tab.

The Hyper-V hosts have been deployed with Bare-Metal deploy from VMM and that is why they have a D:\

Looking at the properties for a host you can see what storage that is available for placement:

Screen Shot 2015-01-28 at 14.26.28

and as you can see the VM is not configured as highly available and have the virtual disk on local storage:

Screen Shot 2015-01-28 at 14.33.41
Screen Shot 2015-01-28 at 14.20.24

I have made a simple script that configures all hosts within a cluster and set all storage that is not cluster shared to not available for placement.

And now when trying to deploy a VM with a new HW profile that is not set to highly available I cannot deploy it as the local disks have been unchecked as available for placement.

Screen Shot 2015-01-28 at 13.57.04
Screen Shot 2015-01-28 at 13.58.09

The reason for just configuring this for hyper-v nodes that belong to a cluster is that there might be a single hyper-v host that actually should be able to provision the VM to local disks.

Configuring VMM logical switch with bandwidth limit virtual port

I got a question from a customer how they could limit a VM´s bandwidth from VMM as it was too noisy and devoured the bandwidth from the host for the other VM´s. There are both a way to set priority and also bandwidth in Hyper-V 2012 and later.

In Hyper-V Manager you can find the setting on the VM´s configuration and the virtual network adapter tab,

Screen Shot 2015-01-16 at 16.15.32

And here I can enable bandwidth management and set both a minimum and maximum, and in this case I want just a limit

Screen Shot 2015-01-16 at 16.15.13

But how do I accomplish the same in VMM? As you might have noticed there is no possibility to edit this on the VM´s settings on the virtual nic, this is a setting that I configure with a Port profile instead and apply on selected VM/VM´s, and by doing it this way I can easily just configure the same profile for several VM´s instead of configuring each VM. There are some configured by default and I can also add new with the particular setting that I need.

First there is the port classification:

Screen Shot 2015-01-17 at 15.49.49

And then the actual port profiles:

Screen Shot 2015-01-17 at 15.48.26

These two combined is used in the Logical Switch for the virtual port,

Screen Shot 2015-01-19 at 11.45.23

Easiest is to use Powershell to create a new port classification and profile and then update the logical switch to be able to use it for the VM´s that needs it, I have made a function that takes care of all the steps including adding it to the logical switch as a virtual port:

Screen Shot 2015-01-19 at 11.54.28

And also a function for removing, in this I check the VM´s connected and moving them to the default port profile before removing it,

Screen Shot 2015-01-19 at 11.55.18

Probably there will be some updates to this in the future but here you can see and test for your own needs :-)  I will now start to test some bandwidth flooding to see that it actually limits the VM´s