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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 2,211 views | 28/02/2014 11:57

If you want to use FCAdapter WMI Class to see Physical and Virtual Port WWPNs, this function will make WWPNs readable.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function ConvertTo-WWPN
{
<#
    .SYNOPSIS
 
        Converts WWPN Integer Array to WWPN
 
    .EXAMPLE
 
        ConvertTo-WWPN -WWPNArray (Get-WmiObject -Namespace "root\wmi" -Class MSFC_FCAdapterHBAAttributes).NodeWWN
 
    .NOTES
 
        Author: Yusuf Ozturk
        Website: http://www.yusufozturk.info
        Email: ysfozy[at]gmail.com
 
#>
 
[CmdletBinding(SupportsShouldProcess = $true)]
param (
 
    [Parameter(
        Mandatory = $true,
        HelpMessage = 'WWPN Array')]
    $WWPNArray,
 
	[Parameter(
        Mandatory = $false,
        HelpMessage = 'Debug Mode')]
    [switch]$DebugMode = $false
)
	# Enable Debug Mode
	if ($DebugMode)
	{
		$DebugPreference = "Continue"
	}
	else
	{
		$ErrorActionPreference = "silentlycontinue"
	}
 
	# Clear Values
	$WWPN = $Null;
	$WWPNInt = $Null;
	$WWPNIntArray = $Null;
	$WWPNObjArray = $Null;
	$CheckWWPNArray = $Null;
 
	# Check WWPN Array
	$CheckWWPNArray = $WWPNArray -as [int[]]
 
	if ($CheckWWPNArray)
	{		
		# Get Length
		$Length = $WWPNArray.Length;
 
		# Create WWPN Object Array
		for ($WWPNInt = 0; $WWPNInt -lt $Length; $WWPNInt++)
		{
			[int[]]$WWPNIntArray = $WWPNIntArray + [int] $WWPNArray[$WWPNInt];
			[Object[]]$WWPNObjArray = $WWPNObjArray + "{0:X}" -f $WWPNIntArray[$WWPNInt];
		}
 
		# Create WWPN Address
		for($WWPNInt = 0; $WWPNInt -lt $Length; $WWPNInt++)
		{
			if ($WWPNObjArray[$WWPNInt].Length -eq 1)
			{
				$WWPN = $WWPN + "0" + $WWPNObjArray[$WWPNInt];
			}
			else 
			{
				$WWPN = $WWPN + $WWPNObjArray[$WWPNInt];
			}
 
			if ($WWPNInt -lt $Length - 1)
			{
				$WWPN = $WWPN + ":"
			}
 
			if ($WWPN.Length -eq "23")
			{
				# Output WWPN
				[String]$WWPN;
			}
			elseif ($WWPN.Length -eq "24")
			{
				# Fix WWPN Value
				$WWPN = $WWPN.Substring(0,23)
 
				# Output WWPN
				[String]$WWPN;
 
				# Clear WWPN
				$WWPN = $Null;
			}
		}
	}
}

You can test this function with following script:

ConvertTo-WWPN -WWPNArray (Get-WmiObject -Namespace "root\wmi" -Class MSFC_FCAdapterHBAAttributes).NodeWWN

As a result, you will see WWPNs of FC Adapters.


Posted in Windows Powershell, Windows Server | 1 Comment | 7,374 views | 23/02/2014 21:33

We can use WMI to get CPU temperature via PowerShell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Target Server
$Server = "localhost"
 
# Get Thermal Information
$ThermalInformation = Get-WmiObject -ComputerName $Server -Namespace "root\wmi" -Class "MSAcpi_ThermalZoneTemperature"
 
# Calculate CPU Temperature
if ($ThermalInformation)
{
	$HostCPUTemperature = [math]::round((($ThermalInformation.CurrentTemperature - 2732) / 10), 0)
}
else
{
	$HostCPUTemperature = "Unknown"
}
 
Write-Host CPU Temp: $HostCPUTemperature °C

In my case, CPU Temp is always 8 °C, I don’t know, Why :)


Posted in Windows Powershell, Windows Server | No Comment | 1,519 views | 19/02/2014 17:44

This is a simple Telnet Function for switch management purposes.

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
# Telnet Function
Function Get-Telnet
{   param (
        [Parameter(ValueFromPipeline=$true)]
        [String[]]$Commands,
        [string]$RemoteHost,
        [string]$Port = "23",
        [int]$WaitTime = 1000
    )
 
	# Attach to the remote device, setup streaming requirements
    $Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Port)
    if ($Socket)
    {   $Stream = $Socket.GetStream()
        $Writer = New-Object System.IO.StreamWriter($Stream)
        $Buffer = New-Object System.Byte[] 1024 
        $Encoding = New-Object System.Text.AsciiEncoding
 
        # Now start issuing the commands
        foreach ($Command in $Commands)
        {   $Writer.WriteLine($Command) 
            $Writer.Flush()
            Start-Sleep -Milliseconds $WaitTime
        }
 
		# All commands issued, but since the last command is usually going to be
        # the longest let's wait a little longer for it to finish
        Start-Sleep -Milliseconds ($WaitTime * 4)
        $Result = ""
 
		# Save all the results
        while($Stream.DataAvailable) 
        {   $Read = $Stream.Read($Buffer, 0, 1024) 
            $Result += ($Encoding.GetString($Buffer, 0, $Read))
        }
    }
    else     
    {   $Result = "Unable to connect to host: $($RemoteHost):$Port"
    }
 
	# Done
    $Result
}

I got the source code from this web page:

Modified a few parts to use in my environment.


Posted in Windows Powershell, Windows Server | No Comment | 998 views | 14/02/2014 18:37

You can use following script to see if remote host has cluster service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	try
	{
		$State = (Get-WmiObject -ComputerName $Server -Class Win32_service | Where Name -like *clu*).State
	}
	catch
	{
	}
 
 
	if ($State)
	{
		Write-Warning $Server
		Add-Content -Value $Server -Path C:\ClusterResults.txt
	}
	else
	{
		Write-Host $Server
	}
}

Script will output all results into C:\ClusterResults.txt.


Posted in Windows Powershell, Windows Server | No Comment | 1,258 views | 14/02/2014 17:39

You can get QLogic Driver Versions of HP Servers with following script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$Clusters = Get-Content C:\Clusters.txt
 
foreach ($Cluster in $Clusters)
{
	$Servers = (Get-Cluster $Cluster | Get-ClusterNode).Name
	foreach ($Server in $Servers)
	{
		try
		{
			$ProductVersion = $Null;
			$ProductVersion = (Get-Item \\$Server\C$\Windows\System32\Drivers\ql2300.sys).VersionInfo.ProductVersion
		}
		catch
		{
		}
 
		$Value = $Server + ";" + $ProductVersion
		Add-Content -Value $Value -Path C:\Results.txt
	}
}

Script will output all results into C:\Results.txt.


Posted in Windows Powershell, Windows Server | No Comment | 1,209 views | 14/02/2014 10:10

You can type your servers into C:\Servers.txt and check WBEM status.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	try
	{
		$TestWBEM = (Get-Item "\\$Server\C$\Program Files\HPWBEM\Tools\HPWbemTestEvent.exe" -ErrorAction SilentlyContinue).Exists
	}
	catch
	{
	}
 
	if ($TestWBEM -eq $True) { $TestWBEM = "True"; } else { $TestWBEM = "False"; }
 
	$Value = $Server + ";" + $TestWBEM
	Add-Content -Value $Value -Path C:\Results.txt
}

That will export all data into C:\Results.txt.


Posted in Windows Powershell, Windows Server | 2 Comments | 2,171 views | 13/02/2014 10:51

You can get memory usage of Hyper-V clusters with following 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
$Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
	[int]$TotalFreeMemory = 0;
	[int]$TotalMemory = 0;
	[int]$NodeCount = 0;
	$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
	foreach ($ClusterNode in $ClusterNodes)
	{
		[int]$FreeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0)
		[int]$TotalFreeMemory = [int]$TotalFreeMemory + [int]$FreeMemory
		[int]$NodeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0)
		[int]$TotalMemory = [int]$TotalMemory + [int]$NodeMemory
		[int]$NodeCount = [int]$NodeCount + 1
	}
	[int]$TotalAvailableMemory = [int]$TotalFreeMemory - [int]$NodeMemory
 
	Write-Host "Cluster: $Cluster"
	Write-Host "Total Memory: $TotalMemory"
	Write-Host "Total Free Memory: $TotalFreeMemory"
	Write-Host "Total Available Memory: $TotalAvailableMemory"
	Write-Host "Node Count: $NodeCount"
 
	Write-Host " "
 
	$Value = $Cluster + ";" + $TotalMemory + ";" + $TotalFreeMemory + ";" + $TotalAvailableMemory + ";" + $NodeCount + ";" + $NodeMemory
	Add-Content -Value $Value -Path Memory.txt
}

You will see detailed memory usage information of your Hyper-V clusters.