Archive for November, 2014

Powershell Script to transpose rows into columns


A question was posted on Windows Powershell peer support forum that asked if array data can be transposed where a table rows can be transposed into columns:

trans5

I found this to be an interesting question and put this script to answer it. The script can be downloaded from the Microsoft Script Center Repository.

This script will take array input similar to the following which would be the content of .\table1.csv sample input file used in the script:

Server,Property,Value
Srv1,Memory,4GB
Srv1,Processes,135
Srv1,Storage,120GB
Srv2,Memory,8GB
Srv2,Processes,234
Srv2,Storage,120GB
Srv3,Memory,16GB
Srv3,Processes,239
Srv3,Storage,160GB
Srv4,Memory,10GB
Srv4,Processes,219
Srv4,Storage,100GB

trans3

The script will transpose it by “Property”, grouped by “Server”, where intersection of Property X Server = Value. The result will look like:

trans4

trans6

Advertisements

Get-VMMetering script to collect and reset VM Metering data, report to CSV


This script can be downloaded from the Microsoft Script Center Repository. It can be set as a scheduled task on one of the Hyper-V hosts in the environment, not all of them.

Set the schedule of the scheduled task to run as often as you’d like to have the VM metering data collected and reset.

Edit the top 3 lines to match your environment details:

  • $CSV = “d:\sandbox\MeteringReports”
    • Edit this line to enter the path to the folder to save CSV files. This can be a UNC path like “\\server\share\folder”
  • $HVHosts = @(“Host1″,”Host2”)
    • Edit this line to list Hyper-V hosts in your environment
  • $Sort = “AvgCPU”
    • Edit this line to change the report sort order. Options include: AvgCPU, AvgRAM, MaxRAM, MinRAM, TotalDisk, NetworkInbound, NetworkOutbound, VMName, ComputerName

Report data and output will look like:

Metering1


November 2014 update rollup for Windows RT/8/2012 breaks VSS backup – hot fix


November 2014 update rollup for Windows RT, Windows 8, and Windows Server 2012 appears to have some issues that cause VSS based backup to break.

Error messages have been ovserved like:

EventId 12366 – VSS – An unhandled exception was encountered while processing a VSS writer event callback method. The VSS writer infrastructure is in an unstable state.

and

EventId 2034 – MSExchangeRepl – The Microsoft Exchange Replication service VSS Writer when processing the backup completion event.

Microsoft has acknowledged the issue and released hot fix KB2996928.


Veeam Cloud Connect on Azure – take 2


2 Months ago in early September 2014, I tested setting up Veeam Cloud Connect on Azure. That was with Veeam version 8 beta 2. Now that Veeam version 8 general availability was November 6th, 2014, I’m revisiting some of the testing with Veeam v8. I’ve also been testing the same with a number of cloud providers who have their own infrastructure. This is helpful to compare performance, identify bottlenecks, and possible issues that may increase or reduce costs.

Summary of steps:

In Azure Management Portal:

  • Create a Cloud Service
  • Create a Storage Account
  • Create a VM: standard A2 with Windows 2012 R2 DC as the OS. Standard A2 is an Azure VM size that comes with 2 (hyperthreaded) processor cores, 3.5 GB of RAM, and up to 4x 1TB page blob disks @ 500 IOPS each. Prior testing with several providers have shown that cloud connect best features such as WAN accelerator need CPU and IOPS resources at the cloud connect provider end.
  • Added an endpoint for TCP 6180 VMcc01
  • Attached 4x disks to the VM, using max space possible of 1023 GB and RW cache VMcc02

On the VM:

  • I RDP’d to the VM at the port specified under Endpoints/Remote Desktop
  • I ran this small script to create a storage space out of the 4x 1TB disks available:

# Script to create simple disk using all available disks
# This is tailored to use 4 physical disks as a simple space
# Sam Boutros – 11/18/2014 – v1.0

$PoolName = "VeeamRepo1"
$vDiskName = "VeeamvDisk1"
$VolumeLabel = "VeeamRepo1"

New-StoragePool -FriendlyName $PoolName -StorageSubsystemFriendlyName “Storage Spaces*” -PhysicalDisks (Get-PhysicalDisk -CanPool $True) |
New-VirtualDisk -FriendlyName $vDiskName -UseMaximumSize -ProvisioningType Fixed -ResiliencySettingName Simple -NumberOfColumns 4 -Interleave 256KB |
Initialize-Disk -PassThru -PartitionStyle GPT |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem NTFS -NewFileSystemLabel $VolumeLabel -AllocationUnitSize 64KB -Confirm:$false

The GUI tools verified successful completion:

VMcc03

VMcc04This storage space was created to provide best possible performance for Veeam Cloud Connect:

  1. Fixed provisioning used instead of thin which is slightly faster
  2. Simple resiliency – no mirroring or parity, provides best performance. Fault Tolerance will be subject of future designs/tests
  3. Number of Columns and Interleave size: Interleave * Number Of Columns ==> the size of one stripe. The settings selected make the stripe size 1MB. This will help align the stripe size to the Block size used by Veeam.
  4. Allocation Unit 64KB for better performance
  • Installed Veeam 8.0.0.817 Backup and Replication, using the default settings which installed SQL 2012 Express SP1, except that I changed default install location to drive f:\ which is the drive created above
  • I ran the SQL script to show the GUI interface as in the prior post (under 11. Initial Veeam Configuration)
  • The default backup Repository was already under f: VMcc05
  • Created a WAN Accelerator – cache size 400GB on drive f: created above
  • Installed the additional Cloud Connect License
  • Added a self-signed certificate similar to step 14 in the prior postVMcc07
  • Added a Cloud Gateway VMcc08 VMcc09
  • Added a user/tenant VMcc10 VMcc11

That’s it. Done setting up Veeam Cloud Connect on the provider side.



Powershell script to merge Hyper-V Virtual Machine disks


In some situations you might find a VM disk to be part of a series of differencing disks. Take this example:

Merge4

If this was the result of VM Checkpoints, the fix would be easy: simply delete the checkpoints which merges the disks. But his is not the case. Hyper-V Manager shows no checkpoints:

Merge9

Powershell confirms (notice no output):

Merge10

This script shuts down the VM and merges its disks. It uses the Get-ParentPath function.

This script can be downloaded from the Microsoft Script Center Repository.

To use this script, download it, run it as administrator, then use the function.

To see help:

Merge11

For example:
Merge-VMDisks -VMName ‘MyVM’
Merge1
This may take some time depending on disk sizes and underlying storage system speed.
Merge3
The script leaves a log file shows the same steps on the console.
This is the picture after the merge is done:
Merge5
Merge6
If the script is run on a VM that has no disks to be merged, no changes are made:
Merge8
The script prompts for confirmation before shutting down the VM:
Merge7
This can be bypassed by using the -Confirm parameter as shown above.
Script help output looks like:
NAME
    Merge-VMDisks
    
SYNOPSIS
    Function to merge VM disks
    
SYNTAX
    Merge-VMDisks [-VMName]  [[-LogFile] ] [-WhatIf] [-Confirm] []
    
DESCRIPTION
    Function/script to merge VM disks. The script will power down the VM in the process.

PARAMETERS
    -VMName 
        Name of the VM whose VHD(x) disks are to be merged
        
        Required?                    true
        Position?                    1
        Default value                
        Accept pipeline input?       true (ByValue, ByPropertyName)
        Accept wildcard characters?  false
        
    -LogFile 
        Name and path of the file where the script will log its steps and progress
        
        Required?                    false
        Position?                    2
        Default value                ".\Merge-VMDisks_$(Get-Date -format yyyyMMdd_hhmmsstt).txt"
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -WhatIf []
        
        Required?                    false
        Position?                    named
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -Confirm []
        
        Required?                    false
        Position?                    named
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 
    
NOTES
    
        Function by Sam Boutros
        v1.0 - 11/01/2014
    
    -------------------------- EXAMPLE 1 --------------------------
    
    C:\PS>Merge-VMDisks -VMName 'v-2012R2-VBR1'
    
RELATED LINKS
    https://superwidgets.wordpress.com/category/powershell/



Powershell script to get parent disk/path tree of VHD(x) file


In some situations you might find a VM disk to be part of a series of differencing disks. Take this example:

PPath1

If this was the result of VM Checkpoints, the fix would be easy: simply delete the checkpoints which merges the disks. But his is not the case. Hyper-V Manager shows no checkpoints:

PPath2

Powershell confirms (notice no output):

PPath3

This script is the first step to a fix. It lists the disk parent tree. The script can be downloaded from the Microsoft Script Center Repository.

To use this script, download it, run it as administrator, then use the function. To see help:

PPath5

You will see output like:

NAME
 Get-ParentPath
 
SYNOPSIS
 Function to get parent disk/path tree of VHD(x) file
 
SYNTAX
 Get-ParentPath [-VHDPath] <String> [[-ComputerName] <String>] [-WhatIf] [-Confirm] 
[<CommonParameters>]
 
DESCRIPTION
 Function to get parent disk/path tree of VHD(x) file
 
PARAMETERS
 -VHDPath <String>
 Full path to the VHD(x) file.
 For example: 
"I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_55DB25B0-EFA9-415F-A5D1-738A62742B4E.avhdx"
 
 Required? true
 Position? 1
 Default value 
 Accept pipeline input? true (ByValue, ByPropertyName)
 Accept wildcard characters? false
 
 -ComputerName <String>
 Name of Hyper-V host where the VHD(x) file resides
 If absent, defaults to localhost
 
 Required? false
 Position? 2
 Default value .
 Accept pipeline input? false
 Accept wildcard characters? false
 
 -WhatIf [<SwitchParameter>]
 
 Required? false
 Position? named
 Default value 
 Accept pipeline input? false
 Accept wildcard characters? false
 
 -Confirm [<SwitchParameter>]
 
 Required? false
 Position? named
 Default value 
 Accept pipeline input? false
 Accept wildcard characters? false
 
 <CommonParameters>
 This cmdlet supports the common parameters: Verbose, Debug,
 ErrorAction, ErrorVariable, WarningAction, WarningVariable,
 OutBuffer, PipelineVariable, and OutVariable. For more information, see 
 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 
 
INPUTS
 
OUTPUTS
 
NOTES
 Function by Sam Boutros
 v1.0 - 11/01/2014
 
 -------------------------- EXAMPLE 1 --------------------------
 
 Get-ParentPath -VHDPath 
"I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_55DB25B0-EFA9-415F-A5D1-738A62742B4E.avhdx" 
-ComputerName "xhost16"
 
 Retunrs an array of the disk path and all its parents paths
 
 -------------------------- EXAMPLE 2 --------------------------
 
 $VMName = "v-2012R2-G2a"
 $HVName = "xHost16"
 $VMDisks=Invoke-Command -ComputerName $HVName -ArgumentList $VMName -ScriptBlock { 
     Param($VMName)
     Get-VMHardDiskDrive -VMName $VMName
 }
 ($VMDisks.Path | Where { $_ -match ":" }) | % {
     Get-ParentPath -VHDPath $_ -ComputerName $HVName
 }
 
 Retunrs an array for each disk attached to the VM $VMName, containing the disk tree.

 Sample output:
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_55DB25B0-EFA9-415F-A5D1-738A62742B4E.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_0020A6D3-0371-48E3-B67D-DE2ADF0BEDF1.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_C2BA8DE5-8FE6-49AD-B12B-789853306524.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_79E7AFEB-F867-4068-A3DA-6BF64F49E819.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C_232D8FD8-5855-4518-800C-2659385521FA.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-C.VHDX
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-D_C492420D-011D-42F4-862A-A04A7222B7FC.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-D_7B0A54C4-36E5-4229-9746-49566B0566AF.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-D_460EDAAF-F30A-4744-8396-87449EAF1A8C.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-D_9D3805B2-79F5-4E5F-865D-D69620E31B6A.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-D_F37513BE-AD00-41FD-B24E-CBB3E0BDEFC4.avhdx
 I:\VMs\v-2012R2-G2a\v-2012R2-G2a-D.vhdx
 
RELATED LINKS
 https://superwidgets.wordpress.com/category/powershell/