VMware Scripts

PowerCLI get list of vMotion IP’s in use



$Array = @()
$Clusters = Get-Cluster | Sort Name
ForEach ($Cluster in $Clusters){
$VmHosts = $Cluster | Get-VmHost | Where {$_.ConnectionState -eq “Connected”} | Sort Name
ForEach ($VmHost in $VmHosts){
$Array += Get-VMHostNetworkAdapter -VMHost $VmHost.Name -VMKernel | Where {$_.VMotionEnabled -eq “True”} | select VmHost,IP
}
}
$Array | Out-GridView

 

Source: http://blog.jgriffiths.org/powercli-get-list-of-vmotion-ips-in-use/


Restart Management Agent on ESXi 6.5

since 6.5 you get a error Message when you try to restart the Management Agent with the command: services.sh restart

-> Errors: Invalid operation requested: This ruleset is required and connot be disabled

 

the new command is:
services.sh restart & tail -f /var/log/jumpstart-stdout.log

Source: https://fabianbrash.com/?p=66


Create / check user on all esxi hosts

If you need to create a aditional user on every vSphere host in your enviroment, you can use the following script:

 


#Vcenter name, can be FQDN
$vsphere = "vcenter"
#User to create
$new_user = "seconduser"
#Password for new user
$new_user_passwd = "password"
#Group to add user too
$new_user_grp = "root"

#local host username with rights to create local users
$root_user = "root"
#Password for local host user with rights to create local users
$root_passwd = "password"

 #Get all of the ESX servers (connect using Windows credentials)
connect-viserver $vsphere
$hosts = Get-View -ViewType HostSystem
disconnect-viserver -confirm:$false

# For each ESX server, connect and see if the new account exists.
# If it does, reset the password and ensure the account is granted shell access.
# If it doesn't, create it and add to the root group (this seems to be necessary to allow ssh login in ESX4.0)
$hosts | %{ $_.name } | %{
 echo $_
 connect-viserver -server $_ -user $root_user -password $root_passwd
 if ($?) {
 if (! (get-vmhostaccount | ?{ $_.id -eq $new_user })) {
 new-vmhostaccount -useraccount -id $new_user -password $new_user_passwd -grantshellaccess
 set-vmhostaccount -groupaccount $new_user_grp -assignusers $new_user
 }
 else {
 set-vmhostaccount -useraccount $new_user -password $new_user_passwd -grantshellaccess $true
 }

disconnect-viserver -confirm:$false "*"
 }
}

 

Source: https://vtote.wordpress.com/2013/03/20/create-user-on-hosts/

Script based vmware “DRS” (Distributed Resource Scheduler)

Recently I found a very interesting script to do something like vmware DRS.

https://ryanmangansitblog.com/2013/03/08/vmware-host-cluster-vm-memory-balancing-script-implementation/

There are some points to improve and the you can use it very well.


Use it only on a certain cluster

change the line 5 from

before
$objHosts = get-vmhost; 

after
$objHosts = get-vmhost | Where-Object {$_.Parent -Like “*Clustername*”} ;

Use random VM to move
(without that, you will face the problem, that you have a lot of small VMs on one host and on the others, you’ll have the larger ones!)

Remark the line 31

# $objVMs = $objVMs | sort “Memory*”

change the percentage of the average memory load
(either set this value to 0 or use an other number that 10%)

change the value in the line 94

if($objHost.PercentMemory -gt ($intAverage + 10)){

 

 

thanks to Scott Warren and Ryan Mangan

How to repair Windows Installer (MSI)

Problem:
Instaling any MSI Setup is not possible.

Solution:

  • Start CMD as Administrator
  • run the following commands

sc config msiserver start= demand
Net stop msiserver

MSIExec /unregister
MSIExec /regserver
regsvr32.exe /s %windir%\system32\msi.dll

Net start msiserver

 

Works on Windows 2012 R2

Keyboard Shortcuts for Windows Server 2012

Windows Key + C – Opens Charms bar
Windows Key + Ctrl + Tab – Cycles through apps
Windows Key + Shift + Tab – Cycles through apps in reverse order
Windows Key + D – Switch to desktop (from start screen)
Windows Key + E – Opens file explorer
Windows Key + F – Search (files and folders)
Windows Key + H – Share
Windows Key + I – Settings
Windows Key + K – Devices
Windows Key + M – Minimizes current windows on desktop
Windows Key + O – Sets device orientation
Windows Key + Pause – System properties
Windows Key + PgDown- Moves current app to right monitor
Windows Key + PgUp- Moves current app to left monitor
Windows Key + PrtScr – Save screenshot
Windows Key + Q – Global search
Windows Key + R – Run command
Windows Key + spacebar – Switch keyboard/input language
Windows Key + TAB – Provides list of running programs
Windows Key + U – Ease of access center
Windows Key + V – Cycles notifications
Windows Key + Shift + V – Cycles notifications in reverse order
Windows Key + Y – Shows desktop screen
Windows Key + W – System settings search
Windows Key + X – Quick access menu
Windows Key + Z – Opens app bar

Outlook 2010 AutoComplete Cache and Suggested Contacts

This is know in Office until Office 2007 as .NK2 file.

The e-mail adresses that you type are stored in the .NK2 file under the following path:
%AppData%\Roaming\Microsoft\Outlook\..

There are all the e-Mail adresses stored, that you enterd in Outlook.

In Outlook 2010 this is discontinued and now in the Exchange Mailbox or .pst file.
(http://office.microsoft.com/en-us/outlook-help/where-does-microsoft-outlook-2010-save-my-information-and-configurations-HP010354943.aspx)

Here is a description, how this works now in Outlook 2010:
http://www.windowsitpro.com/article/outlook/Outlook-2010-AutoComplete-Cache-and-Suggested-Contacts-125525