Showing posts with label virtual machine manager. Show all posts
Showing posts with label virtual machine manager. Show all posts

Tuesday, May 21, 2013

Enabling Network Virtualization using SCVMM Run Script Command

So, if you are in the Fabric node of SCVMM 2012 SP1 you might happen to right click on a Hyper-V Server and notice the option “Run Script Command”.

This is great, it lest me push commands out to my Hyper-V Servers and run them, just like I do with Application Scripts in Service Templates.

I recently ran into a situation where I needed to enable the Network Virtualization binding on all of my Hyper-V Servers (seven of them).  And I had no desire to open a PSSession to each and run my script block that enables it.

Since I discovered this Script Command option in SCVMM, why not use it, I am here.

Like any good SCVMM admin I defined the command and then looked at the PowerShell script behind it.

(The big problem here is that I don’t see a way to save these Script Commands and run them again.  Big fail there.)

I then took that script and made it a bit more useful to me by getting all of my Hyper-V hosts and running my command on all of them at the same time.

And I figured that ‘why not’ this is the one step that all the SCVMM Network Virtualization setup is missing.  Frankly, I would expect SCVMM just to do this for me, but alas SP1 does not.

Here is my execution:

import-module virtualmachinemanager

$scriptSetting = New-SCScriptCommandSetting

Set-SCScriptCommandSetting -ScriptCommandSetting $scriptSetting -WorkingDirectory "" -PersistStandardOutputPath "" -PersistStandardErrorPath "" -MatchStandardOutput "" -MatchStandardError ".+" -MatchExitCode "[1-9][0-9]*" -FailOnMatch -RestartOnRetry $false -AlwaysReboot $false -MatchRebootExitCode "" -RestartScriptOnExitCodeReboot $false

$RunAsAccount = Get-SCRunAsAccount -Name "DomainAdmin"

$VMHosts = Get-SCVMHost | where { $_.VirtualizationPlatform -eq "HyperV" }

$scriptBlock = {

   $vSwitch = Get-VMSwitch -SwitchType External

   ForEach-Object -InputObject $vSwitch {

      if ((Get-NetAdapterBinding -ComponentID "ms_netwnv" -InterfaceDescription $_.NetAdapterInterfaceDescription).Enabled -eq $false){

         Enable-NetAdapterBinding -InterfaceDescription $_.NetAdapterInterfaceDescription -ComponentID "ms_netwnv"

      }

   }

}

ForEach ($VMHost in $VMHosts) {

   Invoke-SCScriptCommand -Executable "%WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe" -TimeoutSeconds 120 -CommandParameters "-ExecutionPolicy RemoteSigned -command $scriptBlock" -VMHost $VMHost -ScriptCommandSetting $scriptSetting -RunAsAccount $RunAsAccount

}

Be sure to have the SCVMM Console installed, and modify your RunAs account name.

That Set-SCScriptCommandSetting line is all about the error handling for the script.  The only non-default setting I have in here is making sure that my hypervisors were not rebooted, no matter what happened.

Monday, March 12, 2012

Monitoring SCVMM New-SCVirtualMachine Jobs

I see this question frequently in the SCVMM forum. 
A job was started and I attempted to perform some action and the VM is not ready.  One way SCVMM lets you handle things like this is through JobGroups.  But not all cmdlets support JobGroups and instead you ( as the coder ) must ‘do the right thing.’
In the forums I have made a feeble attempt to relate monitoring WMI / CIM job status to monitoring the SCVMM job progress.
Well, I had a need to write a VM deployment script, so I thought that I would tackle this topic once and for all.  As it is different than WMI jobs.
In the WMI / CIM world you send off a command and get a response back.  Usually within that is the ReturnValue.  If this is ‘0’ then the task is done, if this is ‘4096’ then the task is running, if it is anything else something went wrong.
In PowerShell we are so very used to getting an object back that we rarely take the time to actually look at it, or the process behind it.  We get the object back and we move on.
And this is not always a good thing to be doing.  There are cases where need to make sure that whatever we asked to happen actually finished before we move on.
Using the New-SCVirtualMachine cmdlet will pretty quickly give you a VM object back.  But if you then turn to the Job console in the GUI you will see that there is a bunch of stuff happening.  How do you know when this is complete?
$vm = New-SCVirtualMachine <…>
Well, lets take a look at that object we get back from New-SCVirtualMachine.
VMCPath                             : C:\Users\Public\VMs\ViewRds1\Virtual Machines\FD4E85BB-A9EC-4E20-9A45-7BC94B2189D5.xml
MarkedAsTemplate                    : False
OwnerSid                            :
VMId                                : FD4E85BB-A9EC-4E20-9A45-7BC94B2189D5
VMResourceGroup                     :
VMConfigResource                    :
VMConfigResourceStatus              : ClusterResourceStateUnknown
VMResource                          :
VMResourceStatus                    : ClusterResourceStateUnknown
DiskResources                       : {}
UnsupportedReason                   : Success (0)
RefresherErrors                     : {}
VirtualMachineState                 : PowerOff
HostGroupPath                       : All Hosts\ViewRds1
TotalSize                           : 8497528832
MemoryAssignedMB                    : 1024
MemoryAvailablePercentage           :
DynamicMemoryDemandMB               :
DynamicMemoryStatus                 :
AllocatedGPU                        :
HasPassthroughDisk                  : False
Status                              : UnderCreation
HasSavedState                       : False
StatusString                        : Creating...
StartAction                         : NeverAutoTurnOnVM
StopAction                          : SaveVM
RunGuestAccount                     :
DelayStart                          : 0
CPUUtilization                      : 0
PerfCPUUtilization                  : 0
PerfMemory                          : 0
PerfDiskBytesRead                   : 0
PerfDiskBytesWrite                  : 0
PerfNetworkBytesRead                : 0
PerfNetworkBytesWrite               : 0
VirtualizationPlatform              : HyperV
ComputerNameString                  : ViewRds1.pvs.brianeh.local
CreationSource                      : ViewRdsHost
IsUndergoingLiveMigration           : False
SourceObjectType                    : VM Template
OperatingSystemShutdownEnabled      : True
TimeSynchronizationEnabled          : True
DataExchangeEnabled                 : True
HeartbeatEnabled                    : True
BackupEnabled                       : True
ExcludeFromPRO                      : False
FailedJobID                         : 875de483-5160-4e66-8884-ec29885a2ebb
CheckpointLocation                  :
SelfServiceUserRole                 :
PassThroughDisks                    : {}
ComputerTier                        :
UpgradeDomain                       :
SCApplications                      : {}
LastRestoredVMCheckpoint            :
ComplianceStatus                    :
IsFaultTolerant                     : False
DeploymentErrorInfo                 :
ServiceDeploymentErrorMessage       :
DeploymentState                     : Undeployed
TieredPerfData                      : e26928de-370b-4751-9c7e-020b09647bc1
Location                            : C:\Users\Public\VMs\ViewRds1
CreationTime                        : 2/15/2012 11:08:55 AM
OperatingSystem                     : 64-bit edition of Windows Server 2008 R2 Enterprise
HasVMAdditions                      : False
VMAddition                          : Not Detected
NumLockEnabled                      : False
CPUCount                            : 2
IsHighlyAvailable                   : False
LimitCPUFunctionality               : False
LimitCPUForMigration                : False
Memory                              : 1024
DynamicMemoryEnabled                : True
DynamicMemoryMaximumMB              : 8096
DynamicMemoryBufferPercentage       : 20
MemoryWeight                        : 5000
VirtualVideoAdapterEnabled          : False
MonitorMaximumCount                 :
MonitorResolutionMaximum            :
BootOrder                           : {CD, IdeHardDrive, PxeBoot, Floppy}
ComputerName                        : ViewRds1.pvs.brianeh.local
UseHardwareAssistedVirtualization   : False
SANStatus                           : {DeployVMMultipleVolumeOnVMDisk (1212)}
CostCenter                          :
QuotaPoint                          : 1
IsTagEmpty                          : False
Tag                                 : (none)
CustomProperties                    : {, , , ...}
CustomProperty                      : {}
UndoDisksEnabled                    : False
CPUType                             : 3.60 GHz Xeon (2 MB L2 cache)
ExpectedCPUUtilization              : 20
DiskIO                              : 0
NetworkUtilization                  : 0
RelativeWeight                      : 100
CPUReserve                          : 0
CPUMax                              : 100
VirtualDVDDrives                    : {ViewRds1}
VirtualHardDisks                    : {ViewRdsTempl.vhd}
VirtualDiskDrives                   : {ViewRds1}
ShareSCSIBus                        : False
VirtualNetworkAdapters              : {ViewRds1}
VirtualFloppyDrive                  : ViewRds1
VirtualCOMPorts                     : {COM1, COM2}
VirtualSCSIAdapters                 : {ViewRds1}
CapabilityProfile                   :
CapabilityProfileCompatibilityState : Compatible
VMCheckpoints                       : {}
HostId                              : fa18d24c-7cbb-4244-999b-1dd26d7d2969
HostType                            : VMHost
HostName                            : threel6.pvs.brianeh.local
VMHost                              : threel6.pvs.brianeh.local
LibraryServer                       :
Cloud                               :
LibraryGroup                        :
GrantedToList                       : {}
UserRoleID                          : 75700cd5-893e-4f68-ada7-50ef4668acc6
UserRole                            : Administrator
Owner                               : PVS\Administrator
ObjectType                          : VM
Accessibility                       : Public
Name                                : ViewRds1
IsViewOnly                          : False
Description                         :
AddedTime                           : 2/15/2012 11:08:55 AM
ModifiedTime                        : 2/15/2012 11:15:12 AM
Enabled                             : True
MostRecentTask                      : Create virtual machine
ServerConnection                    : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection
ID                                  : e269288b-370b-4751-9c7e-020b09647bc1
MarkedForDeletion                   : False
IsFullyCached                       : True
ServicingWindows                    : {}
I highlighted a couple items that are important to avoiding sending a command before an existing one is finished.
Now, it gives us this MostRecentTask, lets look at that.
Name                 : Create virtual machine
Description          : Create virtual machine
Progress             : 32 %
Status               : Running
CmdletName           : New-SCVirtualMachine
ErrorInfo            : Success (0)
StartTime            : 2/15/2012 11:08:54 AM
EndTime              :
Owner                : PVS\Administrator
ErrorInfo            : Success (0)
AdditionalMessages   : {}
ResultName           : ViewRds1
ResultObjectTypeName : Virtual Machine
IsStoppable          : True
IsRestartable        : False
If you notice, this is the actual Create Virtual Machine job.  This gives you a quick link direct to the current long running task.
You also have the cmdlet that invoked the job. 
One thing to be aware of is that this MostRecentTask reference has a life to it.  At some point in the future, this reference will be NULL as the last job has aged and there is no reason to keep the reference any longer.
Now, you could monitor that MostRecentTask for completion.  Or you could monitor the status of the VM itself.
$vm.MostRecentTask.Status = Completed
or cast it to a new object to get the job itself and then query the job;
$job = $vm.MostRecentTask
Get-SCJob $job
As a recent forum user put it:
A simple line of:
ifelse { [string]($vm.MostRecentTask | select "Status") -match "Running" {
  "Skip this VM, it is already running a job"
}

Should handle what I need.

Tuesday, March 6, 2012

Applying SCVMM 2012 Logical network assignment with PowerShell

This is a little script that I needed to write in order to quickly set up a test environment of mine.

One thing that I am going to do here is contrast what I did with what the SCVMM view script gave me.

The known issues at hand:

I have a logical network.  I have a large number of hosts that all need to be associated with this logical network.  I have to find the correct NIC (as a logical network is associated with the hardware NIC, not with a virtual network, so it is always an External Virtual Network).

Here is what I have:

$vmHost = Get-SCVMHost

foreach ($e in $vmHost) {
    $vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -VMHost $e | where {$_.IPAddresses -match "10.233.40"}

    $logicalNetwork = Get-SCLogicalNetwork -Name "Shared"
   
    $JobGroupID = [System.Guid]::NewGuid().ToString()

    Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -JobGroup $JobGroupID

    Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AvailableForPlacement $true  -JobGroup $JobGroupID

    Set-SCVMHost -VMHost $e -JobGroup $JobGroupID -RunAsynchronously
}

Breaking it down:

  • I get the all the host objects.
  • I query for the physical NIC, selecting on the IP address that it has (I want the logical network in this IP range).
  • I get the logical network object. (previously created manually)
  • Then I assign the Logical network to the NIC.
  • I also enable placement.

I could have selected on different parameters to find the proper NIC of the Hyper-V Server to create the Logical Network on.

A particular SCVMHostNetworkAdapter has the following properties:

Name                           : Intel(R) 82579LM Gigabit Network Connection
IPAddresses                    : {10.233.40.156, fe80::b428:524d:463:3ce0}
DHCPEnabled                    : True
IPSubnets                      : {10.233.40.0/21, fe80::/64}
DefaultIPGateways              : {10.233.40.1}
MacAddress                     : 18:03:73:D2:53:4C
PhysicalAddress                : 18:03:73:D2:53:4C
NetworkLocation                : Shared
VirtualNetwork                 : Shared
VLanTags                       : {0}
UsableVLanTags                 : {0}
VLanMode                       : Access
DesiredVLanMode                : Access
VLanEnabled                    : False
ConnectionState                : Connected
ConnectionName                 : Local Area Connection 3
Description                    :
PrimaryDNSSuffix               :
MaxBandwidth                   : 1000
VMHost                         : threel5.pvs.brianeh.local
LogicalNetworkMap              : {[Shared, System.Collections.Generic.List`1[Microsoft.SystemCenter.VirtualMachineManager.SubnetVLan]]}
UsableVlanMode                 : Access
ModelAccessibleSubnetVLans     : {[Shared, System.Collections.Generic.List`1[Microsoft.SystemCenter.VirtualMachineManager.SubnetVLan]]}
LogicalNetworks                : {Shared}
SubnetVLans                    : {10.233.40.0/24}
UnassignedVLans                : {}
AvailableForPlacement          : True
UsedForManagement              : True
LogicalNetworkCompliance       : Compliant
LogicalNetworkComplianceErrors : {}
BDFLocationInformation         : PCI bus 0, device 25, function 0
ServerConnection               : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection
ID                             : fcb44659-06ca-44e8-9932-c9488897437a
IsViewOnly                     : False
ObjectType                     : VMHostNetworkAdapter
MarkedForDeletion              : False
IsFullyCached                  : True

For me it made sense to select on the following:

IPAddresses : {10.233.40.156, fe80::b428:524d:463:3ce0}

or

IPSubnets : {10.233.40.0/21, fe80::/64}

But you could select on any of the properties of the object.  A bit of background;

In SCVMM the Logical Network is associated with a physical NIC. For the same reason that I selected on the IP. It is a way to tie the VM to the physical topology of your network. So you always end up on the same subnet.

This gets around historic Windows behavior of not always ordering the NICs the same as they are in the chassis. You never can guarantee a relationship between the physical and the ordering in the OS.

I mentioned at the top that I would also look at what the SCVMM View Script button in the wizard gave me.  I have always been critical of how verbose the View Script option is of SCVMM wizards and this is no exception.  The primary reason that I am critical is that it is hard to consume and turn into something universal, especially if you are not familiar with PowerShell.

The thing to pay attention to is where you are setting parameters of an object that already has these settings applied.  In other words, wasting cycles re-setting the exact same value.

Here is what SCVMM gave me with ‘View Script’:

$vmHost = Get-SCVMHost -ID "dcbcaa95-7627-45a1-afbe-69ff970e40ea" -ComputerName "threeb1"

$vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -Name "Intel(R) 82579LM Gigabit Network Connection" -VMHost $vmHost

# Shared
$logicalNetwork = Get-SCLogicalNetwork -ID "cee53020-cece-48f4-afea-496030292466"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -JobGroup "b5856f43-6539-4d68-9a0f-5ebe1241499a"

Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -Description "" -JobGroup "b5856f43-6539-4d68-9a0f-5ebe1241499a" -VLanMode "Access" -AvailableForPlacement $true -UsedForManagement $true


Set-SCVMHost -VMHost $vmHost -JobGroup "b5856f43-6539-4d68-9a0f-5ebe1241499a" -RunAsynchronously

Breaking it down:

  • The host (hypervisor) is selected using its ID - this is the only way to guarantee you get the right host, and only one host. And is commonly used in this precise way.
  • The host network adapter is selected by name - if you spell out the entire adapter name this works, if you rename your adapters this works. Considering that there is no correlation between the NIC and the patch panel I am going with the IP range or subnet.
  • The Logical network is queried.
  • The Host network adapter is modified to apply the setting of the logical network, then it is again set to apply a description, set the vlan mode and enable for placement.
  • In my case I had already set the VLAN mode and the placement flag was on, why set them again..
  • Then the entire change job is applied to the host.
  • You will notice a JobGroup in here. A JobGroup in SCVMM is an array of commands that are executed in order from 0 to the end. Some cmdlets support it, some do not, no you need to check your cmdlets.

Wednesday, February 22, 2012

Uninstalling the SCVMM Agent from Server Core

Okay, I admit it, I screwed up.

In testing the various releases of SCVMM 2012 I dorked up my environment.  I tossed away my database when moving between builds. 

And then when I wen to re-add my Hyper-V Servers I got an error that an unsupported version of the agent is installed.

Okay, fine - I thought.  I will simply uninstall it.  Um..  But this is Server Core I am using.  There is no Control Panel, Uninstall a program.

This article is more about doing something on Server Core than fixing my SCVMM 2012 situation.

Okay.  Well, um.  Regedit works on Server Core.  Okay fire that up.  But I don’t want to manually clean the registry, there must be something useful there though.  And a bit of searching pointed me where I need to be:

HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall

This is where all the good programs go that use Windows Installer.

Under here I found the Virtual Machine Manager Agent.  And under that I found a very useful Registry Key:  “UninstallString”

The UninstallString key is a string value.  It is the command line option that is invoked when uninstall is performed.  How super handy (I think I might use this all the time).

At your command prompt, run the string you find there and you will be ready to finish repair.

Tuesday, February 7, 2012

Grouping and averaging time to execute execute SCVMM 2012 Jobs with PowerShell

In my previous post I ended with a large array of System Center Job Objects.

I need to now determine how long each job took to execute.  And since these are many jobs over time, I want to see if the time to execute changes over time.

So, I need to sort.  I have my array from the previous post.  To sort I do this:

$vhdConvertJobs = $vhdConvertJobs | Sort StartTime

This will sort all Job objects in the Array ( $vhdConvertJobs )using the StartTime property of the Job object. 

Nice and conveniently each job has a StartTime and EndTime, so I just need to subtract those.  The subtraction part is easy:

Foreach ($job in $vhdConvertJobs) {
    ($job.EndTime - $job.StartTime).seconds
}

Now the interesting part.  I have a huge list of numbers.  Great.  I could graph them. No.

I had this great idea to group them into groups of ten and then average them.  So my averages are the first ten, then the second ten, and so on.  That is a bit easier to look at.

$i = $vhdConvertJobs.Count
$arrayTick = 0

While ($arrayTick -lt $i){
    $loopTick = 0
    While ($loopTick -ne 10){
        $timeToConvert = $timeToConvert + ($vhdConvertJobs[$arrayTick].EndTime - $vhdConvertJobs[$arrayTick].StartTime).seconds
        $loopTick++
        $arrayTick++
        if ($arrayTick -eq $i){break}
    }
    "Average of " + $loopTick + " jobs: " + ($timeToConvert / $loopTick) + " seconds"
    $TimeToConvert = 0
}

Put this all together and it looks like this:

<#
.SYNOPSIS
   This script is dump the time to convert VHDs form Dynamic to Fixed from SCVMM 2012
.DESCRIPTION
   It first finds the VMs using the name match pattern (or you can leave that commented to simply get all VMs)
   Then It finds the virtual disk and the latest job on the virtual disks.
   The jobs are sorted from first started to last started.
   The different from StartTime to EndTime is output.
   Then the Jobs are averaged as groups of 10 and groups of 100 from first started to last started.
.AUTHOR
    Brian Ehlert, MSFT VM MVP

.KNOWN ISSUES
   In SCVMM Jobs age and the last job on an object changes.  So there is a timeliness to running this script.  If you
   wait too long you will get an incorrect number of jobs back.
#>


Import-Module VirtualMachineManager

$vhdConvertJobs = @()

$scVMs = Get-SCVirtualMachine | where {$_.Name -match "Xd1K"}

Foreach ($scVM in $scVMs){
    $vhdConvertJobs += [Microsoft.SystemCenter.VirtualMachineManager.Task]( Get-SCVirtualDiskDrive -VM $scVM | where {$_.MostRecentTask -match "convert"} ).MostRecentTask
}

$vhdConvertJobs = $vhdConvertJobs | Sort StartTime

""
"Disk Conversion Jobs"
"Listed first are the jobs started earlier, listed last are the jobs started later"

Foreach ($job in $vhdConvertJobs) {
    ($job.EndTime - $job.StartTime).seconds
}

""
# Break the sorted list of jobs into groups of 10, Average the seconds to convert per group
"Disk Conversion Job Average per 10 conversions"
"Sorted by StartTime.  First are the first jobs started, last are the later jobs started"

$i = $vhdConvertJobs.Count
$arrayTick = 0

While ($arrayTick -lt $i){
    $loopTick = 0
    While ($loopTick -ne 10){
        $timeToConvert = $timeToConvert + ($vhdConvertJobs[$arrayTick].EndTime - $vhdConvertJobs[$arrayTick].StartTime).seconds
        $loopTick++
        $arrayTick++
        if ($arrayTick -eq $i){break}
    }
    "Average of " + $loopTick + " jobs: " + ($timeToConvert / $loopTick) + " seconds"
    $TimeToConvert = 0
}


""
# Break the sorted list of jobs into groups of 100, Average the seconds to convert per group
"Disk Conversion Job Average per 100 conversions"
"Sorted by StartTime.  First are the first jobs started, last are the later jobs started"

$i = $vhdConvertJobs.Count
$arrayTick = 0

While ($arrayTick -lt $i){
    $loopTick = 0
    While ($loopTick -ne 100){
        $timeToConvert = $timeToConvert + ($vhdConvertJobs[$arrayTick].EndTime - $vhdConvertJobs[$arrayTick].StartTime).seconds
        $loopTick++
        $arrayTick++
        if ($arrayTick -eq $i){break}
    }
    "Average of " + $loopTick + " jobs: " + ($timeToConvert / $loopTick) + " seconds"
    $TimeToConvert = 0
}

Monday, January 30, 2012

Getting convert VHD jobs per VM from SCVMM 2012

I have been running some tests recently and one of the things that was brought into question is if a disk conversion job is taking longer to run as the number of VMs increases in the environment.

Now, you might think this is relatively easy.  Just issue a query with Get-SCJob and filter.

Well, I did begin that way, thinking I would get just what I wanted.

Get-SCJob | where { $_.Name -eq "convert virtual hard disk" } | where { $_.Status -eq "Completed" }

But I never got the right number of VHD conversion jobs returned back.  This obviously needed more complex scripting.

So, I tried using Get-SCVirtualDiskDrive   That cmdlet requires a VM object to be tossed in, I can’t just get a list of all the VHD like I could through a CIM call to a hypervisor.

Now I have to go to the VM level.  I have to query for the VMs, then find each virtual disk, then get the most recent job object on that virtual disk.

$scVMs = Get-SCVirtualMachine | where {$_.Name -match "Xd1K"}

In a long hand way that looks like this:

Foreach ($scVM in $scVMs){
    $vmVhd = Get-SCVirtualDiskDrive -VM $scVM | where {$_.MostRecentTask -match "convert"} 
    $vhdJob = $vmVhd.MostRecentTask
    $vhdConvertJobs += [Microsoft.SystemCenter.VirtualMachineManager.Task]$vhdJob
}

Take notice of that object cast; [Microsoft.SystemCenter.VirtualMachineManager.Task].  If you don’t do this you get an error that the Task cannot be converted to int32.  Don’t ask me why PowerShell is trying to convert the Task object into an integer, but that is what the default is trying to do.

In a nice tight shorthand way it looks like this:

Foreach ($scVM in $scVMs){
    $vhdConvertJobs += [Microsoft.SystemCenter.VirtualMachineManager.Task]( Get-SCVirtualDiskDrive -VM $scVM | where {$_.MostRecentTask -match "convert"} ).MostRecentTask
}

Next time, calculating the average time to execute the jobs, and making it useful to quickly check.

Wednesday, February 2, 2011

Tuning SCVMM for VDI deployments - Vishwa Kumbalimutt's blog

 

Tuning SCVMM for VDI deployments - Vishwa Kumbalimutt's blog - Site Home - TechNet Blogs

I have only re-blogged articles a very, very few times – but this is one that I feel is really important to any folks who are using SCVMM in a VDI scenario.

Many of these tweaks I have know about for a few years but have been asked to not share them.  Now that a MSFT person has spilled the beans you all can benefit.

I am not going to go into the details, but all of the tweaks are highly useful.  The one I have found most useful in my work (when moving into scales of over 400 VMs) is the tune for Windows Communication Framework.

Don’t get me wrong, all of these tweaks are golden to any deployment of XenDesktop that uses SCVMM.

Friday, July 11, 2008

Unable to template Server 2008 virtual machine with SCVMM or deployment fails unable to customize

I struggled with this myself, and it is an issue that an administrator rarely has to deal with anymore.

Any administrator that has had to set domain password secirity levels and enforcements, knows what I am talking about. Password security policy.

Let's back up and talk about VMM first.
My references are going to be specific to SCVMM 2008 (since that is what is new and improved - this can apply to VMM 2007 in some cases).

In VMM there are two ways to create VM templates.

One is to select the Library view, Click the New Template action to launch the wizard. Select the button to use an existing virtual machine.
After you finish the wizard, the VM is prepared to be a template. One of these steps involves using the local administrator credentials that you provided and actually modifying the VM with a blank local administrator password and running sysprep. This way, on deployment of the template, there is a blank administrator password that allows the injection of the OS Profile (sysprep answer file - sysprep.inf or unattend.xml) to finish the deployment.

The other way to create a template is from an existing VHD that is already stored in the Library. Following the process above - VMM expects that the VHD has been prepared by the administrator with a blank local administrator password and sysprep has been run.

(This is all in the documentation BTW - no secrets are being revealed).

Now, why does the tempolating process fail? Especially with Server 2008? - this is where the machine local security policy comes in.

Start -> Administration Tools -> Local Security Policy (this is within the VM - just to make sure that you were following along)
Account Policies -> Password Policy

Minimum Password Length must be 0 (this is a blank password that we are trying to accept)
Password must meet complexity requirements must be disabled.

Wait a minute...I just tried changing these settings in my VM and I can't...what's up?

Most likely, your VM is joined to a Domain and the Domain security policy is overriding the local security policy - you remember, strictest and/or last applied wins.

Unjoin your VM from the Domain, set the local security password policy, shutdown the VM - return to the VMM New Template wizard and prepare your VM as a template.

This will get you past the security bug when you create templates.

In the case of VHDs that have been used to create templates - If you did not set the local administrator password to blank then the deployment of the VM will fail, not the template creation.

It is a different step in the process, and a different failure, but the same cause.

BTW - just to clarify. When I said the local administrator password needed to be blank I didn't mean the letters b.l.a.n.k or the word 'blank' - I meant (in programmer terms) empty string - null - nothing.