Wednesday, August 6, 2014

Which Hyper-V Host is hosting this VM

Last night I was working on resolving a Veeam backup failure and needed to know which Hyper-V server was hosting the VM I was currently logged onto. As I do with everything server related alert I thought to myself -- hmm how can I retrieve this with PowerShell. The answer is simple, you just need to know where to look and in this case it was in the registry and I guarantee that running the below code in an Administrative PowerShell prompt is much more efficient than opening regedit and navigating to "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters". But to each their own, that is how some may prefer to gather their information...

Oh and one more thing; If the hostname returned is a mix of letters and numbers about 10 characters long its hosted in Azure.

001
002
003
004
005
006
007
008
009
010
011
# Retieves $env:COMPUTERNAME's Hyper-V Host Server Name

Function Get-VMHostname

{

     (Get-Item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")

}

Get-VMHostname

Friday, July 25, 2014

Happy Sys Admin Day!

Star Wars Theme Song with PowerShell


In celebration of Sys Admin Day I bring to you the Star Wars theme song via PowerShell!

Enjoy!


[console]::beep(440,500)       
[console]::beep(440,500) 
[console]::beep(440,500)        
[console]::beep(349,350)        
[console]::beep(523,150)        
[console]::beep(440,500)        
[console]::beep(349,350)        
[console]::beep(523,150)        
[console]::beep(440,1000) 
[console]::beep(659,500)        
[console]::beep(659,500)        
[console]::beep(659,500)        
[console]::beep(698,350)        
[console]::beep(523,150)        
[console]::beep(415,500)        
[console]::beep(349,350)        
[console]::beep(523,150)        
[console]::beep(440,1000)



Oh and don't forget to buy your Sys Admin a beer.



All Sys Admins Like beer! 

Tuesday, July 8, 2014

Super Mario Theme Song with PowerShell

Here's a little PowerShell script that plays the Super Mario Theme Song!!
I hope you enjoy this as much as I enjoyed making it!!
<##Super Mario Intro ##>
$i = 1
do {$i++
        [console]::beep(659,250) ## E
        [console]::beep(659,250) ## E
        [console]::beep(659,300) ## E
        [console]::beep(523,250) ## C
        [console]::beep(659,250) ## E
        [console]::beep(784,300) ## G
        [console]::beep(392,300) ## G
        [console]::beep(523,275) ## C
        [console]::beep(392,275) ## G
        [console]::beep(330,275) ## E
        [console]::beep(440,250) ## A
        [console]::beep(494,250) ## B
        [console]::beep(466,275) ## A
        [console]::beep(440,275) ## A
        [console]::beep(392,275) ## G
        [console]::beep(659,250) ## E
        [console]::beep(784,250) ## G
        [console]::beep(880,275) ## A
        [console]::beep(698,275) ## F
        [console]::beep(784,225) ## G
        [console]::beep(659,250) ## E
        [console]::beep(523,250) ## C
        [console]::beep(587,225) ## D
        [console]::beep(494,225) ## B
   }until ($i -gt 1)