search
Categories
Archive
Blogroll

Microsoft PowerShell MVP

Cozumpark Bilisim Portali
AdvancedInstaller
Posted in Virtual Machine Manager, Windows Powershell | 10 Comments | 3,261 views | 04/04/2013 20:25

Hi guys and ladies! :)

Update: v1.4 is here! Thanks for your feedbacks.

Hyper-V VM Migration Script is ready! Now it’s possible to migrate your VMs from Hyper-V v2 to Hyper-V v3 with quick migration capabilities.

It supports following scenarios:

1. Standalone Hyper-V v2 Host
2. Hyper-V v2 Host in trusted domain
3. Hyper-V v2 Host in untrusted domain

Update v1.4:
1. Fixed network configuration issue on different subnets
2. Improved debugging

Update v1.3:
1. Added support for servers on different subnets

Update v1.2:
1. Linux VM migration support
2. Fixed a bug while getting vhd name
3. Advanced debugging switch (use -DebugMode)

So why it supports untrusted domains? Because you may not want to install Windows Server 2012 Cluster into your existing Windows Server 2008 R2 environment. If you have totally different environment for Hyper-V v3, then this script is your best friend.

Advantages:

1. It supports BITS! It’s ready to move large VHD files.
2. It supports “Rollback“. If there will be any problem, this script will undo any changes!!! :)
3. Licensed in GPLv2. You can use this script in your organization without any licensing issues. Totally free!

How to Install?
1. First download Hyper-V VM Migration Script:
Download Script

2. You can use exe or msi file to installation. I’ve just used migration.exe file to installation.

3. Change Powershell path if you have different drive path.

4. Click Install to begin installation.

5. That’s it! You can start using migration script.

6. Go to Powershell and type following to change execution policy as “AllSigned”.

Set-ExecutionPolicy AllSigned

7. Allow my code publishing certificate. This will prevent you to run untrusted scripts.

New-Migration

8. Installation is done! Now we can start migration of virtual machines.

How to use?

Example 1: If want to migrate VM01 from HV001 (10.10.10.2) to your local Hyper-V v3 host, use following:

New-Migration -VMName "VM01" -VMHost "HV001" -VMPath "C:\ClusterStorage\Volume1"

BTW, -VMPath switch is the destination path. Not your current VM path. This script finds VM path automatically.

Example 2: If HV001 (10.10.10.2) is a standalone machine, use following:

New-Migration -VMName "VM01" -VMHost "10.10.10.2" -Username "Administrator" -Password "123456" -VMPath "C:\ClusterStorage\Volume1"

Example 3: If HV001 (10.10.10.2) is a member of a untrusted domain, use following:

New-Migration -VMName "VM01" -VMHost "10.10.10.2" -Username "Domain\Administrator" -Password "123456" -VMPath "C:\ClusterStorage\Volume1"

Example 4: Having trouble with migration? Use debugging switch (-DebugMode) to see what really makes that problem:

New-Migration -VMName "VM01" -VMHost "10.10.10.2" -VMPath "C:\ClusterStorage\Volume1" -DebugMode

Requirements:

1. You should install this script on to your Hyper-V v3 host.

2. This script doesn’t allow you to migrate VMs if they have snapshots. You should remove them first.

3. Requires Powershell v3. (It comes by default on Windows Server 2012)

4. Hyper-V v2 host and Hyper-V v3 host should have same network switch names. If they are different, this script connects first external network to your virtual machine.

Thanks for using Hyper-V VM Migration script!

-Yusuf.


Posted in Virtual Machine Manager | No Comment | 1,338 views | 07/01/2013 21:34

I specified SQL Server 2012 Always On Group name as a database server while SCVMM 2012 SP1 installation.
SCVMM didn’t see instance name and other databases but installed server and console well.
When I checked database of SCVMM, I see that database is not synced as I expected.

SCVMM creates databases with “Simple” recovery model. You should make it “Full” before adding it to Always-On Group.

Take a full backup of SCVMM database.

Now you can add it to Always-On Group.

Our SCVMM database is now in Always-On Group.

Then I made a failover test to see how SCVMM is reacting..

But boom! SCVMM GUI is crashed! I checked service and saw that service is stopped.

I’ve tried to restart SCVMM service but it gave me error:

Because SCVMM creates “Computer Account” only on primary SQL Server.

You should create same user on your failover SQL Server. After that you will be able to start SCVMM service.

Then I tried a failover test again and no problem! SCVMM works without any problem :)


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,847 views | 12/10/2012 11:55

1. How to create RunAs Account?

1
2
3
$SecurePassword = ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "yusufozturk\Administrator", $SecurePassword
New-SCRunAsAccount -Name "Domain Admin" -Credential $Credential

2. How to get RunAs Account?

1
Get-SCRunAsAccount -Name "Domain Admin"

3. How to remove RunAs Account?

1
Get-SCRunAsAccount -Name "Domain Admin" | Remove-SCRunAsAccount



Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,449 views | 10/10/2012 14:25

Somehow, you have to migrate a new Hyper-V v3 VM back to Hyper-V v2 environment?
Then you may need to follow these steps.

Of course if you need to migrate a VM from Hyper-V v2 to Hyper-V v3, you can use this script for quick migration:

If you export a virtual machine from Hyper-V v3 and try to import Hyper-V v2, Hyper-V gives this error:

Because Hyper-V v3 export is not compatible with old version of Hyper-V.
Hyper-V v3 exports only XML config file, but Hyper-V v2 exports .exp file.

Achieve this problem, you need to use this Powershell export script on Hyper-V v3.

Before exporting virtual machine, do following steps:

1. Remove your all disks file from virtual machines.
2. Change your virtual machine switch as “Not Connected”.

Thanks to Ben, this script exports VM config in Hyper-V v2 style.

Now download EXP template from here:

Open your exported .exp file and template.exp file in the zip file with a text editor.

You will see $Replace1, $Replace2, $Replace3 and $Replace4 in template.exp.
You should change them with your exported .exp file values.

Follow these steps for modification:

1. Replace this one with your virtual machine GUID: $Replace1

2. Replace this one with your virtual machine name: $Replace2

3. Replace this one with your virtual machine MAC address: $Replace3

4. Replace this one with your virtual machine ethernet port GUID: $Replace4

5. Finally, replace template.exp file name with your exported .exp file name.

Now you can import it to Hyper-V v2. After import, you can attach your virtual disks to VM again.
Finally change your virtual machine switch and VLAN configuration. Now you can start your VM.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 829 views | 29/09/2012 07:56

SetLinuxVM v5 is out! It’s the best Linux VM preparation solution for Hyper-V on the market. But what’s changed with SetLinuxVM v5 and how it’s become fastest solution on the market?

1. Executing scripts instead of sending codes

In previous versions of SetLinuxVM, the idea was sending commands to virtual machine via Wmi interface. It was a great idea and nicely worked for 4 great versions of SetLinuxVM. But it took more than 5 minutes for a full preparation and it was a long time. So I made scripts and executing script is just easy and error-free.

Lets see old style of wmi code:

$SendCommand = $VMConsole.TypeText('echo "iface $iface inet static" >>/etc/network/interfaces');

Now I just use that way to execute scripts:

$SendCommand = $VMConsole.TypeText(". $ScriptPrefix-Unattended.sh");

Also now it’s easier to change scripts as your way. Sample timezone configuration script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Change Time Zone Configuration
If ($TimeZone)
{
	$TimeZoneScript = "echo Setting Time Zone.." + "`n"
	$TimeZoneScript += "ln -sf /usr/share/zoneinfo/$TimeZone /etc/localtime" + "`n"
	$TimeZoneScript += "rm -f /etc/sysconfig/clock" + "`n"
	$TimeZoneScript += "echo ZONE=`"$TimeZone`" >>/etc/sysconfig/clock" + "`n"
	$TimeZoneScript += "echo 'UTC=true' >>/etc/sysconfig/clock" + "`n"
	$TimeZoneScript += "echo 'ARC=false' >>/etc/sysconfig/clock" + "`n"
	$TimeZoneScript += "echo End of Time Zone."
 
	# Prepare Time Zone Script
	Add-Content -Value $TimeZoneScript -Path "$UnattendedScriptPath\$ScriptPrefix-Unattended.sh"
}

If you are familiar with Linux Bash scripting, it is very easy to modify these codes for your requirements.

2. Linux Integration Components 3.4

With new Linux integration components, SetLinuxVM is now able to install LIC on CentOS/RHEL 5 and CentOS/RHEL 6.
So how do I know which distro are you using? It’s simple. I’m getting distro name with this command.

distro=$(cat /etc/issue | head -n 2 | tr -d "\n" | tr "[:upper:]" "[:lower:]")

This gives the distro name. I use if/else statement to install it on your distro.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$InstallLICScript += 'if [[ $distro == *6.0* ]] || [[ $distro == *6.1* ]] || [[ $distro == *6.2* ]]; then' + "`n"
$InstallLICScript += "cd RHEL6012" + "`n"
$InstallLICScript += "./install.sh" + "`n"
$InstallLICScript += 'elif [[ $distro == *6.3* ]]; then' + "`n"
$InstallLICScript += "cd RHEL63" + "`n"
$InstallLICScript += "./install.sh" + "`n"		
$InstallLICScript += 'elif [[ $distro == *5.7* ]]; then' + "`n"
$InstallLICScript += "cd RHEL57" + "`n"
$InstallLICScript += "./install-rhel57.sh" + "`n"
$InstallLICScript += 'elif [[ $distro == *5.8* ]]; then' + "`n"
$InstallLICScript += "cd RHEL58" + "`n"
$InstallLICScript += "./install-rhel58.sh" + "`n"
$InstallLICScript += "else" + "`n"
$InstallLICScript += "echo Current distribution is not supported." + "`n"
$InstallLICScript += "fi" + "`n"

I talked about technical details of SetLinuxVM v5. I hope you enjoyed it. Thanks for using SetLinuxVM!


Posted in Virtual Machine Manager, Windows Server | No Comment | 1,172 views | 15/09/2012 21:45

Hyper-V üzerinde çalışan Linux sanal makineler için olan Linux Integration Services’in 3.4 versiyonu yayınlandı. Yeni sürüm ile birlikte artık Linux sanal sunucularda 4 vCPU’dan fazla vCPU kullanabilmek mümkün hale geldi.

Artık Linux için bir limit bulunmuyor, sanal vCPU limitini artık Hyper-V limitleri belirliyor. Windows Server 2012 ve Hyper-V Server 2012 ile birlikte Linux sanal sunucularınıza 64 vCPU verebilirsiniz. Ayrıca bu sürüm ile birlikte mouse/fare kullanımına tam destek geliyor.

Linux Integration Services v3.4 ile desteklenen Linux dağıtımları:

  • Red Hat Enterprise Linux 5.7, 5.8, 6.0-6.3 x86 ve x64
  • CentOS 5.7, 5.8, 6.0-6.3 x86 ve x64

Ayrıca IC ile elde edebileceğiniz diğer önemli destekler:

  • Hot Add Disk (SCSI Controller üzerinden)
  • Time Sync – Saat eşitleme Sentetik Network Adaptörü
  • Integrated Shutdown (Sunucu kapatma)
  • VLAN tagging (Sentetik network adaptörü üzerinden)
  • Live Migration desteği
  • Jumbo Frames (1500 bytes üzeri artık kullanılabilir)

Bu sürüm ile hala gelmeyen özellikler:

  • Integration services: Volume Snapshot Backup
  • Networking: TCP Offload

Hyper-V Linux Integration Services v3.4′ü indirmek için bu linki kullanabilirsiniz.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | 1 Comment | 1,340 views | 25/08/2012 22:01

I’m re-coding PoSHStats for Cluster support. Currently it just supports standalone hosts, but i have to extend that support for cluster environments. So while i’m playing with Powershell, I want to add some of my codes.

Getting Hyper-V hostname:

$Hostname = gc env:computername

Getting Cluster name of your Hyper-V host:

$ClusterName = (Get-Cluster | Get-ClusterNode | where Name -eq $Hostname).Cluster.Name

Even better one for Hyper-V specifically:

$ClusterName = (@(Get-Cluster | Get-ClusterNode | where Name -eq $Hostname | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name

Also I see that this doesn’t work as expected on PowerShell v3, so don’t use something like this:

$ClusterName = @(Get-Cluster | Get-ClusterNode | where Name -eq $Hostname | Get-ClusterGroup | where GroupType -eq "VirtualMachine").Cluster.Name[0]

Getting all clustered virtual machines:

$VMs = Get-Cluster $ClusterName | Get-ClusterGroup | Where GroupType -eq "VirtualMachine" | Get-VM

Also you can extend your query for resource monitoring:

$VMs = Get-Cluster -Name $ClusterName | Get-ClusterGroup | Where GroupType -eq "VirtualMachine" | Get-VM | where ResourceMeteringEnabled -eq $True | Measure-VM

Getting free space of Cluster Shared Volume:

1
2
3
$CSVVolume = "Volume1"
$CSVDisk = Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Where FriendlyVolumeName -match "$CSVVolume"					
[int]$HostDiskDriveFreeSpace = ([math]::round((($CSVDisk | Select -Expand Partition).FreeSpace / 1GB), 0))

Getting total disk space of Cluster Shared Volume:

1
2
3
$CSVVolume = "Volume1"
$CSVDisk = Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Where FriendlyVolumeName -match "$CSVVolume"					
[int]$HostDiskSpace = ([math]::round((($CSVDisk | Select -Expand Partition).Size / 1GB), 0))

I’ll share more next days, keep watching..




Powered by DorukNet