Merge multiple CSV files into single file with PowerShell

Copy all CSV files you wish to merge into same directory ie “c:\temp\csvfiles”

Powershell Code to merge files:

Get-ChildItem -Path c:\temp\csvfles -Filter *.csv | Select-Object -ExpandProperty FullName | Import-Csv | Export-Csv .\combinedcsvs.csv -NoTypeInformation -Append

Uninstall VIBs on ESXi via PowerCLI

I ran across a need to have to uninstall a VIB from ESXI once installed. I Didnt want to login to each ESXi via SSH to preform the ESXCLI command so this is how you can do it via PowerCLI.

the ESXi command line would be:

esxcli software vib remove -n=usbcore-usb --dry-run

PowerCLI Code

$VMhost = "ESXi-Hostname"
$VIBNAME = "usbcore-usb"

$esxcliRemoveVibArgs = $
$esxcli = Get-EsxCli -VMHost $VMhost -V2
$esxcliRemoveVibArgs.dryrun = $true  #Change this to False to actually perform the uninstall)

$vib = $ | where{$_.Name -match $VIBNAME }

$esxcliRemoveVibArgs.vibname = $vib.Name 

Function to Mounting ISO in windows with File-Open Browser-Popup with Powershell

This is very simple function that you can add to your ISE profile that allows a file-open dialog box that looks specifically for ISO files and uses the Mount-DiskImage Command.

Function Mount-ISO {

$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
    InitialDirectory = [Environment]::GetFolderPath('Desktop')
    Filter = 'ISO-Images (*.ISO)|*.iso'

$null = $FileBrowser.ShowDialog()

Mount-DiskImage -ImagePath $FileBrowser.FileName

Merge multiple CVS files into a single CVS file.

This simple powershell script will merge multiple CVS files into a single. Run this script from working directory where the CVS files are located:

$CSVFiles = Get-ChildItem -Filter *.csv | Select-Object -ExpandProperty FullName

$OutputFile = "c:\temp\merged.csv"

$Output = @();
foreach($CSV in $CSVFiles) {
    if(Test-Path $CSV) {
        $FileName = [System.IO.Path]::GetFileName($CSV)
        $temp = Import-CSV -Path $CSV | select *, @{Expression={$FileName};Label="FileName"}
        $Output += $temp
    } else {
        Write-Warning "$CSV : No such file found"

$Output | Export-Csv -Path $OutputFile -NoTypeInformation

vmkping via PowerCLI/ESXCLi

When troubleshooting an ESXi host one of the most common problems is testing connectivity.  A tool that used on the console or ssh session of the ESXi host is vmkping. Use cases are testing connectivity from vmkernel to other servers in cluster like vMotion or vSAN connectivity.

This article from VMware KB article 1003728 shows use case on how to use vmkping.

There are situations where you may not have access to the root account to ssh into the box.  There is way to still troubleshooting vmkernel network connectivity by using PowerCLi and ESXCli.

$esxcli = Get-EsxCli -VMHost (Get-VMHost "testesxihost") -V2
$params = $
$ = ''
$params.interface  = 'vmk0'
$params.size = '1472' #use 1472 for 1500 MTU or 8972 for 9000 MTU (VMware uses these values on MTU pings on ESXi)
$res = $$params)

You will then get output like this:


Duplicated : 0
HostAddr :
PacketLost : 0
Recieved : 3
RoundtripAvg : 49
RoundtripAvgMS : 0
RoundtripMax : 61
RoundtripMaxMS : 0
RoundtripMin : 42
RoundtripMinMS : 0
Transmitted : 3

You can get further script options for ESXCLI for by:

PS C:\> $params

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
host                           Unset, ([string], optional)                                                                                                                                                                                                       
wait                           Unset, ([string], optional)                                                                                                                                                                                                       
df                             Unset, ([boolean], optional)                                                                                                                                                                                                      
interval                       Unset, ([string], optional)                                                                                                                                                                                                       
ttl                            Unset, ([long], optional)                                                                                                                                                                                                         
debug                          Unset, ([boolean], optional)                                                                                                                                                                                                      
nexthop                        Unset, ([string], optional)                                                                                                                                                                                                       
count                          Unset, ([long], optional)                                                                                                                                                                                                         
netstack                       Unset, ([string], optional)                                                                                                                                                                                                       
size                           Unset, ([long], optional)                                                                                                                                                                                                         
ipv4                           Unset, ([boolean], optional)                                                                                                                                                                                                      
ipv6                           Unset, ([boolean], optional)                                                                                                                                                                                                      
interface                      Unset, ([string], optional) 

For help:

PS C:\> $
Send ICMP echo requests to network hosts.
- count           | Specify the number of packets to send.                                                          
- debug           | VMKPing debug mode.                                                                             
- df              | Set DF bit on IPv4 packets.                                                                     
- host            | Specify the host to send packets to. This parameter is required when not executing ping in debug mode (-D)                                                                                      
- interface       | Specify the outgoing interface.                                                                 
- interval        | Set the interval for sending packets in seconds.                                                
- ipv4            | Ping with ICMPv4 echo requests.                                                                 
- ipv6            | Ping with ICMPv6 echo requests.                                                                 
- netstack        | Specify the TCP/IP netstack which the interface resides on                                      
- nexthop         | Override the system's default route selection, in dotted quad notation. (IPv4 only. Requires int
                  | erface option)                                                                                  
- size            | Set the payload size of the packets to send.                                                    
- ttl             | Set IPv4 Time To Live or IPv6 Hop Limit                                                         
- wait            | Set the timeout to wait if no responses are received in seconds.