search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | 4 Comments | 4,969 views | 22/05/2013 16:59

In this sample script, I use SCVMM 2012 to get virtual machine list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	$VMInfo = Get-VM $Server
	$VMHost = $VMInfo.VMHost
	$VMHostName = $VMHost.Name
	$VMHostGroup = $VMHost.VMHostGroup
 
	if ($VMInfo.PassThroughDisks)
	{
		$PassThroughDisk = "True"
	}
	else
	{
		$PassThroughDisk = "False"
	}
 
	if ($VMHostGroup -like "All Hosts\*")
	{
		Add-Content -Value $Server -Path C:\Servers.txt
		Add-Content -Value $VMHostName -Path C:\VMHosts.txt
		Add-Content -Value $PassThroughDisk -Path C:\PassThroughDisks.txt
	}
}

Also you can filter specific Host Groups like in this sample.


Posted in Exchange Server, Windows Powershell | 2 Comments | 13,179 views | 22/05/2013 16:45

You can get ready and retry queue’s of Exchange Server with this script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$ExchangeHost = "ExCas01"
$ExchangeServer = Get-ExchangeServer -Identity $ExchangeHost
 
# Integers
[int]$ExchangeActiveConnections = 0;
[int]$ExchangeRetryQueue = 0;
[int]$ExchangeMessageQueue = 0;
[int]$ExchangeActiveQueue = 0;
[int]$HostMessageQueue = 0;
[int]$HostRetryQueue = 0;
 
# Get Mail Queue
if ($ExchangeServer.IsHubTransportServer -eq $True)
{
	# Message Queue
	$MessageQueue = Get-Queue -Server $ExchangeHost | Where {$_.Status -eq "Ready" -and $_.MessageCount -gt "0"}
 
	# Sum Message Queue
	Foreach ($Queue in $MessageQueue)
	{
		[int]$HostMessageQueue = [int]$HostMessageQueue + [int]$Queue.MessageCount
	}
 
	# Retry Queue
	$RetryQueue = Get-Queue -Server $ExchangeHost | Where {$_.Status -eq "Retry" -and $_.MessageCount -gt "0"}
 
	# Sum Retry Queue
	Foreach ($Queue in $RetryQueue)
	{
		[int]$HostRetryQueue = [int]$HostRetryQueue + [int]$Queue.MessageCount
	}
 
	# Exchange Queue
	[int]$ExchangeRetryQueue = [int]$ExchangeRetryQueue + [int]$HostRetryQueue
	[int]$ExchangeMessageQueue = [int]$ExchangeMessageQueue + [int]$HostMessageQueue
	[int]$ExchangeActiveQueue = [int]$ExchangeActiveQueue + [int]$HostRetryQueue + [int]$HostMessageQueue
}

You can add multiple Exchange hosts to an array, it’ll just query Hub Transport servers. It only support Exchange Server 2010.


Posted in Windows Powershell | 1 Comment | 17,607 views | 22/05/2013 15:30

In this sample, I’ll show you how to get active Exchange Server CAS connections via PowerShell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ExchangeHost = "ExCas01"
$ExchangeServer = Get-ExchangeServer -Identity $ExchangeHost
 
# Get Connections
if ($ExchangeServer.IsClientAccessServer -eq $True)
{
	# OWA Connections
	$HostOWAConnections = (Get-Counter "\MSExchange OWA\Current Unique Users"  -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
 
	# RPC Connections
	$HostRPCConnections = (Get-Counter "\MSExchange RpcClientAccess\User Count"  -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
 
	# POP3 Connections
	$HostPOP3Connections = (Get-Counter "\MSExchangePop3(1)\Connections Current"  -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
 
	# IMAP Connections
	$HostIMAPConnections = (Get-Counter "\MSExchangeImap4(1)\Current Connections"  -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
 
	# Exchange Connections
	[int]$ExchangeActiveConnections = [int]$HostOWAConnections + [int]$HostRPCConnections + [int]$HostPOP3Connections + [int]$HostIMAPConnections
}

You can loop this script to get real time connection statistics.


Posted in Windows Powershell | No Comment | 2,543 views | 22/05/2013 14:17

This is an example script for PoSHServer to query cluster names via HTTP get request.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Check Remote PowerShell Session
$CheckPSSession = Get-PSSession -ComputerName S0134CloudVMM04
if (!$CheckPSSession)
{
	#$SecurePassword = ConvertTo-SecureString "Password_Here" -AsPlainText -Force
	#$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "Domain\Username", $SecurePassword
	#$Session = New-PSSession -Computername VMMHost2012 -Credential $Credentials
	$Session = New-PSSession -Computername VMMHost2012
}
else
{
	$Session = $CheckPSSession
}
 
# Get Virtual Machine Name
$VMName = $PoSHQuery.VM
 
# Get Virtual Machine Details Function
Function Get-InterVMDetails
{
Param ($Session, $VMName)
 
	Invoke-Command -Session $Session -ArgumentList $VMName -ScriptBlock {
	param($VMName)
	$CheckModule = Get-Module -Name virtualmachinemanager -EA SilentlyContinue
	if (!$CheckModule)
	{
		Import-Module -Name virtualmachinemanager -EA SilentlyContinue
	}
	$VMDetails = Get-SCVirtualMachine "$VMName"
	$VMHost = $VMDetails.VMHost
	$VMHostDetails = Get-SCVMHost "$VMHost"
	$VMHostCluster = $VMHostDetails.HostCluster
	$VMHostCluster.Name
	}
}
 
# Get VM Details
if ($VMName)
{
	$VMDetails = Get-InterVMDetails -VMName $VMName -Session $Session
 
}
 
# Output Web Interface
@"
$($VMDetails)
"@

Save this script as “getclustername.ps1”. Put it into PoSHServer homedirectory. After that you can query like this:

http://localhost:8080/getclustername.ps1?vmname=My_VM_Name

You can query any information like this via PowerShell remoting.


Posted in Windows Powershell | 1 Comment | 3,497 views | 23/04/2013 16:55

Hello,

PoSHStats for Exchange Server v2.2 is almost ready!
I’m releasing latest version for tests. Please let me know if you find any bugs etc.

Main Screenshot:

poshstats-for-exchange

Example of Exchange Host Reporting:

host

Example of Mailbox Database Reporting:

db_reports

Example of User Mailbox Reporting:

mailbox

It has a nice limit information bar :)

limit

Also you can see service status of Exchange hosts:

services

This is not the final version of PoSHStats.
There will be more features for Exchange but I think this version is enough for many enterprises.

Tested with 3000 mailboxes, everything seems ok. First time setup will take about 5-10 minutes depends on your environment.

First download setup:

Install setup.exe. After installation, open PowerShell and:

1
2
Import-Module PoSHStats
Start-PoSHStats

Give your hostname (like reports.poshstats.net or 192.168.2.1) and port number, then you are free to go.

Thanks for using PoSHStats.

Yusuf.


Posted in Virtual Machine Manager, Windows Powershell | 10 Comments | 16,291 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 Windows Powershell | 4 Comments | 23,111 views | 27/03/2013 11:03

When you remove an Exchange Mailbox from DAG or your environment, msExchHomeServerName attribute remains same. You may get problem when you try to update user mailbox due to non exist Mailbox Server. In order to achieve this problem, you should get affected mailboxes first, then you should update them with correct mailbox server name.

First get all affected mailboxes:

$Mailboxes = Get-Mailbox -ResultSize Unlimited | where {$_.Servername -eq "Old_Mailbox_Name"}

Update them with this:

1
2
3
4
5
6
7
foreach ($Mailbox in $Mailboxes)
{
Write-Host $Mailbox.Name
$MBX = $null;
$MBX = Get-Mailbox -Identity $Mailbox
Set-Mailbox $MBX -Database $MBX.Database -Confirm:$false -Force -Verbose
}

After that process, all msExchHomeServerName will be corrected.