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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | 1 Comment | 3,420 views | 18/06/2013 13:39

This is an example to show you how to get hardware information of AD clients via PowerShell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$Servers = Get-ADComputer -Filter {Name -like "C*"}
Foreach ($Server in $Servers)
{
	$Hostname = $Server.Name
	$ServerInfo = (Get-WmiObject -Computername $Hostname Win32_ComputerSystem)
	$Manufacturer = $ServerInfo.Manufacturer
	$Model = $ServerInfo.Model
	Write-Host "Name: $Hostname"
	Write-Host "Manufacturer: $Manufacturer"
	Write-Host "Model: $Model"
	Write-Host " "
	$Content = "$Hostname;$Manufacturer;$Model"
	Add-Content -Value $Content -Path "C:\ServerInfo.txt"
}

I’ve used filter to get specific computers.


Posted in Windows Powershell, Windows Server | No Comment | 1,485 views | 18/06/2013 10:10

You can get your VMs list, Hyper-V hostname, clustername and csv paths like this:

1
2
3
4
5
6
7
8
9
10
11
$VMs = Get-VM
foreach ($VM in $VMs)
{
	$VMName = $VM.Name
	$VMHostname = $VM.ComputerName
	$VMHostCluster = (Get-Cluster).Name
	$VMHardDisk = $VM.ConfigurationLocation
	$VMHardDiskLocation = $VMHardDisk.Split("\")[2]
	$Value = $VMName + "," + $VMHostname + "," + $VMHostCluster + "," + $VMHardDiskLocation
	Add-Content -Value $Value -Path "VMList.txt"
}

You need to run this script on all Hyper-V hosts.


Posted in Windows Powershell | No Comment | 2,808 views | 18/06/2013 09:35

This is an example to show you how to fetch data from Sharepoint.
You need to send your domain credetials to log in Sharepoint server.

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
$Webclient = New-Object System.Net.WebClient
$Webclient.Credentials = Get-Credential
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	$AsyPortalURL = "http://sharepoint/_layouts/srchrss.aspx?k=" + $Server
	$Webpage = $Webclient.DownloadString($AsyPortalURL)
	$URL = "$WebPage" -match '<link>(.*?)</link>'
	$ServerID = $Matches[1]
	$ServerID = $ServerID.Split("ID=")[-1]
	$ServerListesi = "http://sharepoint/Lists/Server Listesi/DispForm.aspx?ID=" + $ServerID
	$Webpage = $Webclient.DownloadString($ServerListesi)
	$Webpage = $Webpage | ? {$_.trim() -ne ""}
	$Webpage = $Webpage -replace '\s+', ' '
	$IPField = "$Webpage" -match '<!-- FieldName="IP" FieldInternalName="IP" FieldType="SPFieldText" --> (.*?) </td>'
	$IPAddress = $Matches[1]
 
	$TestCon = Test-Connection $IPAddress
 
	if (!$TestCon)
	{
		$Value = $Server + "," + $IPAddress
		Add-Content -Value $Value -Path C:\pingtest.txt
	}
}

As you see that, I’m getting ip addresses of servers. After that doing test-network check for that servers.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,848 views | 17/06/2013 14:57

You can get your prod VMs list, Hyper-V hostname, clustername and csv paths like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
$VMs = Get-SCVirtualMachine | where {$_.HostGroupPath -like "All Hosts\*Prod*"}
foreach ($VM in $VMs)
{
	$VMName = $VM.Name
	$VMHostname = $VM.Hostname
	$VMHasPassthroughDisk = $VM.HasPassthroughDisk
	$VMHost = Get-SCVMHost $VMHostname
	$VMHostCluster = $VMHost.HostCluster
	$VMHardDisk = @($VM | Get-VirtualHardDisk)[0].Location
	$VMHardDiskLocation = $VMHardDisk.Split("\")[2]
	$Value = $VMName + "," + $VMHostname + "," + $VMHostCluster + "," + $VMHardDiskLocation
	Add-Content -Value $Value -Path "VMList.txt"
}

If you need to get all vms, just try “All Hosts\*” for all host groups.


Posted in Windows Powershell, Windows Server | No Comment | 5,046 views | 05/06/2013 11:20

You can export HP’s IML logs via PowerShell. Execute PowerShell console with Administrative privileges and run:

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
$Hostname = $env:COMPUTERNAME
&"C:\Program Files\Compaq\Cpqimlv\cpqimlv.exe" /export:C:\test.iml /m:$Hostname
$Logs = Get-Content "C:\test.iml" | Select-String Critical,Caution
Foreach ($Log in $Logs)
{
	$ErrorDesc = $Log.Line.Split('"')[1]
	if ($ErrorDesc)
	{
		$ErrorType = $Log.Line.Split(",")[-4]
		$ErrorDate = $Log.Line.Split(",")[-1]
	}
 
	if ($ErrorType -eq "Critical")
	{
		Write-Host "Description: $ErrorDesc" -ForegroundColor Red
		Write-Host "Type: $ErrorType" -ForegroundColor Red
		Write-Host "Date: $ErrorDate" -ForegroundColor Red
		Write-Host " "
	}
	else
	{
		Write-Host "Description: $ErrorDesc" -ForegroundColor Yellow
		Write-Host "Type: $ErrorType" -ForegroundColor Yellow
		Write-Host "Date: $ErrorDate" -ForegroundColor Yellow
		Write-Host " "
	}
}

You can also write them into event viewer after parsing. If you need to get specific date, change script like this:

1
2
3
4
5
6
7
$Date = Get-Date
$Day = $Date.Day
$Month = $Date.Month
$Year = $Date.Year
$Hostname = $env:COMPUTERNAME
&"C:\Program Files\Compaq\Cpqimlv\cpqimlv.exe" /export:C:\test.iml /m:$Hostname
$Logs = Get-Content "C:\test.iml" | Select-String Critical,Caution | Select-String $Month/$Day/$Year

So you can always get new Critical and Caution logs.


Posted in Windows Server | 2 Comments | 2,784 views | 03/06/2013 10:21

You can get parent Hyper-V hostname in virtual machine with this registery key:

HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters

You can also see other parameters like:

HostName
PhysicalHostName
PhysicalHostNameFullyQualified
VirtualMachineName

Registery keys may not be updated after host changes in cluster. You may need to restart VM.