SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Sponsor:

Would you like to sponsor this site?
Or buy me a beer?:


Recently Changed Pages:

View All Pages
View All Q Pages


View All Tags


Sign up for Q to post comments.





WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Terms And Conditions for Q users


Pages with comments

PageDateDiscussionTags
2019/05/01 14:08 2 Comments
2019/03/15 16:02 1 Comment
2019/03/15 16:02 1 Comment
2019/03/15 16:02 3 Comments
2017/04/20 15:28 1 Comment
2017/04/20 15:23 1 Comment
2017/04/19 14:44 1 Comment
2017/04/17 20:10 1 Comment
2017/04/17 20:07 1 Comment
2017/04/17 19:58 1 Comment
2017/04/17 19:52 1 Comment

View All Comments

hypervgethost

Hyper-V Get Host for VM

Use the following script to schedule a daily report to get the host for a particulat VM. The email functionality is imported from a default functions script as explained in AD Controls.

Note that the script uses the SCCM Hyper-V commandlets, which are available after you install the Virtual Machine Manager (VMM) management server

# Script Variables
$scriptname = [System.IO.Path]::GetFilenameWithoutExtension($MyInvocation.MyCommand.Path.ToString())
$scriptlocation = Split-Path $myinvocation.mycommand.path
 
# Start transcript for full logging capabilities
start-transcript -path "$scriptlocation\logtranscript.txt"
 
# Date & Time Variables
$timestamp = Get-Date -format "yyyyMMdd-HH.mm"
$readdate = Get-Date -format "d MMM yyyy"
$weekdate = Get-Date -uformat %V
$monthdate = Get-Date -format "MMMM-yyyy"
 
# Reporting Variables
### Email Variables
$mailserver = "smtp1"
$toemail = "s.hooft_getshifting.com"
$ccmail = "s.hooft_getshifting.com"
$fromemail = "$scriptname_getshifting.com"
 
# Management Domain Variables
$shiftuser = 'shift\sjoerd'
$shiftpass =  Get-Content "$scriptlocation\..\ICTscripts\shiftcreds.txt" | ConvertTo-SecureString
$shiftcreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $shiftuser,$shiftpass
 
# Hyper-V Variables
$vmmserver = "vmm.shift.com"
$mqvm = "mqserver"
$gb = 1073741824
 
### Start Functions ###
# Import functions from global function file
. "$scriptlocation\..\ICTscripts\Functions.ps1"
 
# Connect to SCCM Virtual Machine Manager
Get-SCVMMServer $vmmserver -Credential $shiftcreds
 
# Get Host and hardware info where MQ VM is running
$mqhost = Get-VMHost | where {$_.VMs -contains "$mqvm"} | select name,CPUManufacturer,CPUArchitecture,CPUModel,PhysicalCPUCount,CoresPerCPU,CPUSpeed,@{N="TotalMemoryInGB";E={[Math]::Round(($_.TotalMemory/$gb) ,2)}}
 
$mqhost
 
$hostname = $mqhost.name
$hostcpuman = $mqhost.CPUManufacturer
$hostcpumodel = $mqhost.cpumodel
$hostpcpu = $mqhost.PhysicalCPUCount
$hostcores = $mqhost.CoresPerCPU
$hostspeed = $mqhost.CPUSpeed
$hostram = $mqhost.TotalMemoryInGB 
 
# Setup email
$info = "Dear $toemail , <br>"
$info += "<br>"
$info += "The server $mqvm is running on host $hostname <br>"
$info += "$hostname has $hostpcpu $hostcpuman $hostcpumodel processors with each $hostcores cores with a speed of $hostspeed Mhz<br>"
$info += "$hostname has $hostram GB memory <br>"
 
# Set the subject and combine the email body collecting all information 
$subject = "MQ License Check for $readdate"
 
# Send email
Send-Email $subject $info
 
# Stop Logging
stop-transcript 
You could leave a comment if you were logged in.
hypervgethost.txt · Last modified: 2019/03/20 14:52 by sjoerd