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

Badges
MCSE
Community

Cozumpark Bilisim Portali
How to get host reports with PowerShell
Posted in Windows Powershell, Windows Server | No Comment | 1,798 views | 31/07/2014 11:30

You can get host reports 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$Servers = "Server01","Server02"
 
foreach ($Server in $Servers)
{
	# Get Local Disks
	$Disks = (Get-WmiObject -ComputerName $Server -Class Win32_LogicalDisk)
 
	# Clear Variables
	$TotalSize = 0;
	$TotalUsedSize = 0;
 
	foreach ($Disk in $Disks)
	{
		# Get Disk Space
		$Size = $Disk.Size
		$FreeSpace = $Disk.FreeSpace
 
		# Calculate Used Size
		[int64]$UsedSize = [int64]$Size - [int64]$FreeSpace
 
		# Calculate Total Size
		$TotalSize = $TotalSize + $Size;
		$TotalUsedSize = $TotalUsedSize + $UsedSize;
	}
 
	# Convert Total Size to MB
	[int64]$TotalUsedSize = [math]::round(($TotalUsedSize / 1MB), 0)
	[int64]$TotalSize = [math]::round(($TotalSize / 1MB), 0)
	[int64]$TotalFreeSpace = $TotalSize-$TotalUsedSize
 
	# Get OS and CPU Info
	$OSInformation = Get-WmiObject -ComputerName $Server -Class "Win32_OperatingSystem"
	$CPUInformation = (Get-WmiObject -ComputerName $Server -Class "Win32_Processor").Count
 
	# Calculate Memory
	$HostTotalMemory = ([math]::round(($OSInformation.TotalVisibleMemorySize / 1MB), 0)) * 1024
	$HostFreeMemory = ([math]::round(($OSInformation.FreePhysicalMemory / 1MB), 0)) * 1024
	$HostUsedMemory = $HostTotalMemory-$HostFreeMemory
 
	# Output Results
	$Value = $Server + ";" + $CPUInformation + ";" + $HostTotalMemory + ";" + $HostUsedMemory + ";" + $HostFreeMemory + ";" + $TotalSize + ";" + $TotalUsedSize + ";" + $TotalFreeSpace
	$Value
}

You can export all results to Excel to parse values.



Leave a Reply