Get-IQN script for getting all IQNs of managed ESXi hosts

Because of an error in the past, I wanted to make sure that all IQNs were stored in our CMDB and available at times of disaster.

I created a script for this, which will get the IQNs for all ESXi hosts under your vCenter server and export the information to a CSV file. It can be downloaded from here or you can use the text below and save it as *.ps1 file.

–Update on 9th of May, 2014: Keith (bouldergeek) supplied code that works with PowerCLI 5.5, check it out in the comments. Thanks for your feedback Keith!

#General information
#Date: May 24th, 2013
#Author: Rene Bos
#Script version: 0.1

#Script summary
#Tested on vCenter Server and ESXi 5.1
#This script will retreive the IQNs of all ESXi hosts under your vCenter Server and will export this information in a table-like format to a CSV file.
#You need VMware PowerCLI installed on your machine and an active connection to one or more vCenter servers.

#Please use this script at your own risk and test it out in your testlab first before using it in production
#When using my script, please leave the general information in place. And let me know if my scripts needs improvement!

$CsvPath = "C:TempIQN-Export.csv"

$ESXiHosts = Get-VMHost | Sort-Object

foreach ($ESXiHost in $ESXiHosts)
$h = Get-VMhost $ESXiHost.Name
Write-Host "Getting IQN for $h"
$hostview = Get-View $
$storage = Get-View $hostview.ConfigManager.StorageSystem

$a = [PSCustomObject]@{
Hostname = $h.Name
IQN = $storage.StorageDeviceInfo.HostBusAdapter.iScsiName
$a | Export-CSV -Path $CsvPath -Append
Write-Host "CSV exported to $CsvPath"

Exchange 2013 Management Shell from Windows 8

I’m testing out the new functionalities of Exchange 2013 in my testlab and get familiar with the product as we are probably going to use this in production.

While testing, I was wondering if it would be possible to manage Exchange 2013 remotely from my Windows 8 client.
Ofcourse you can use the ECP (Exchange Control Panel) but managing your environment with Powershell is something ‘more compliant’ with the management ways Microsoft sees it (And it’s cooler).

Installing the Exchange Management Shell on Windows 8 is not going to work (unless you are in the same AD domain as the Exchange server, correct me if I’m wrong).

So here I am, wanting to remotely manage Exchange 2013 and having a Windows 8 client in a workgroup.

Back in the office, my Exchange-guru colleague sees me stumble and mumble and quietly sent me a mail message with a script included. He created it on the fly and was hoping my cranky face would turn into a happy face =)
He succeeded! And that only by using 11 lines of code.. What a boss!

With all credits going to my colleague Jens Giessler, I am posting his created script on my blog, hoping other people’s faces will turn into happy ones.
Replace the bold parts with your own credentials and Exchange server FQDN, and save as a .ps1 file to run it with PowerShell.

Before running the script, you also need to enable Basic Authentication on the PowerShell virtual directory, using the ECP (Servers menu, virtual directories tab).

Oh; as with all my previous and future script postings; use them at your own risk.

Function Query-Credentials
$Global:Cred = Get-Credential -Credential <b>domainuser</b>

Function Connect-Exchange
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://exchangeserverfqdn/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

#Establish connection

Configuring SNMP on multiple ESXi hosts

While talking with my colleague from the networking department, it seemed nice to have our ESXi NICs in Cacti for performance/load logging and troubleshooting.
As apposed to me complaining about a slow network, he can now complain about NIC utilization at my desk =)

Configuring the necessary SNMP parameters for each ESXi host can be a time consuming task.
The PowerCLI command used for this (Set-VMHostSnmp) does not support connecting to vCenter and configuring multiple hosts at one time.

Because of this I created a script which configures these parameters on multiple ESXi hosts, including separate user accounts, passwords and SNMP community strings. I made use of a foreach loop and each host configured in the config.txt file will run through the same set of commands:

Connect to ESXi host
Configure SNMP (Enable and configure SNMP string)
Disconnect ESXi host

For this, the script consists of two files: the script itself and a config.txt file where you can input multiple hosts in CSV format.

Use the script at your own risk! I have used it in my test environment and will try the script tomorrow in our acceptation and production environment.

The script files can be downloaded from here.

Let me know if you have any improvements or want to share your experience with the script!

#General information
#Date: April 24nd, 2013
#Author: Rene Bos
#Script version: 0.1

#Script summary
#This script is created for configuring SNMP on multiple ESXi 5.1 hosts using PowerCLI so your monitoring tool can request SNMP information.
#The environment I had to configure this in, used different root passwords for each ESXi host and required a different approach which resulted in this script.
#Use the supplied config.txt file to enter ESXi hostnames, passwords and SNMP community strings before running the script.
#Each line in this file represents one ESXi host.

#Please use this script at your own risk and test it out in your testlab first before using it in production
#When using my script, please leave the general information in place. And let me know if my scripts needs improvement!

$caption = "This script assumes you have yet filled in the required fiels in the 'config.txt' file."
$message = "Do you want to run this script now?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","This will run the script now based on the data in the config.txt file"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","Do not run this script now"
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)

switch ($answer)
    0 {"The script will execute NOW"; }
    1 {"The script will NOT execute"; Exit}

$ESXiHosts = Import-Csv "config.txt"
foreach ($ESXiHost in $ESXiHosts)
Connect-VIServer $ESXiHost.ESXi_Host -User $ESXiHost.Username -Password $ESXiHost.Password
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$True -ReadOnlyCommunity $ESXiHost.Snmp_String
Disconnect-VIServer -Server * -Force -Confirm:$False