RSS

Tag Archives: powershell

PS+REST:NSX Central CLI using REST API

As a second part from my previous post, I modified the script to run Central CLI. One thing to note, you need to add “accept”=”text/plain” into the header when running central CLI command or you will get 406 errors (sorry, I found this out in one of the blogs, but couldn’t give the proper credits).

Lastly the request returns a bunch of text and not XML or JSON.

nsxoutput

Read the rest of this entry »

Advertisements
 
Leave a comment

Posted by on February 15, 2018 in powershell, vmware

 

Tags: , , ,

PS:One liner to grab IP from DNS name

Needless to say, it’s not hard to grab IP address from a DNS name. There are at least 2 commands that come to mind:

[System.Net.Dns]::GetHostAddresses($hostname)
Test-Connection $hostname

But what if you want to grab the IP address of a list of host names AND ensure that the command doesn’t skip the output if the host name is unresolved? Read the rest of this entry »

 
Leave a comment

Posted by on January 23, 2018 in powershell

 

Tags: ,

Powershell and splatting: passing switch parameter to another script

I came across the term splatting previously, but never really paid heed to it until recently when I needed to pass a switch parameter as a variable to another script, like this:

param(
[string]$Name,
[string]$Server,
[switch]$SkipHost
)
if ($SkipHost) {$s = "-SkipHost"} else {$SkipHost = ""}
.\script1.ps1 -Name $name $s
.\script2.ps1 -Name $name -Server $server

The line at script1.ps1 obviously don’t work and will cause an error when executed.

Some folks may ask: “why do I need to do this?” Well, splatting is most useful when you have a main script which calls other external scripts. This is where splatting comes in, its the ability to pass parameters into a script using variables. I don’t need to explain the mechanics about it as there are many posts elsewhere devoted to this already. Suffice to say, despite all the fancy ways in which various authors had devoted their time to describe the use of @PSBoundParameter, they are only useful if you are passing ALL the parameters at one go. If one need to pass only one or two of the parameters, @PSBoundParameter probably makes the script more complex.

One way to make this work without @PSBoundParameter is via the Powershell version 1 method:

param(
[string]$Name,
[string]$Server,
[switch]$SkipHost
)
.\script1.ps1 -Name $name -SkipHost:$SkipHost
.\script2.ps1 -Name $name -Server $server
 
Leave a comment

Posted by on September 21, 2015 in powershell, Scripts

 

Tags:

PS1: Mashing UCS host to MAC address via vlookup

This post is more a note to self, but is useful for folks using Cisco UCS enclosure when you need to general a list of hosts against its MAC address on eth0 NIC.

Cisco UCS is notoriously flexible yet complex. If you want a list of physical host names against its MAC address, there is no direct means of exporting that list. You need to get the source from two exports, one from the server export and one from the MAC Identity Management tab in the LAN tab. Then you need perform a vlookup to match each host to its MAC address using “Assigned To” field in th MAC export and “Name” field in the server export. Read the rest of this entry »

 
Leave a comment

Posted by on September 21, 2015 in powershell, Scripts

 

Tags: ,

PowerShell: Setting JVM heap sizes for vCenter server 5.x

One of the changes from vCenter 5.0 to 5.1 that affect java memory allocation is vFabric tomcat server. This server effective decouples the java heap size memory management to the various vCenter server components, when this used to be a single setting in the tomcat configuration. An effect of this is that you many need to adjust the JVM heap size of your vCenter after upgrading (or even fresh install), even though you have specific the correct sizing during install.

From my experience, since we had upgraded vCenter from 5.0 to 5.5, the JVM heap size may not be sized correctly after the upgrade. Especially the Inventory servces, which can impact performance is set too low. Read the rest of this entry »

 
Leave a comment

Posted by on July 10, 2015 in powershell, Scripts, vmware

 

Tags: , ,

Powershell: Batch update of DNS server list in ESXi hosts

A quick one-liner to update the DNS serer list of all ESXi hosts in a cluster.

get-vmhost -location "MyVMClusterName |
get-vmhostnetwork |
set-vmhostnetwork -dnsaddress "1.1.1.1","2.2.2.2"

 
Leave a comment

Posted by on June 28, 2013 in powershell, Scripts, vmware

 

Tags: , , ,

Powershell: Batch removing datastores from ESXi hosts (4.1)

We have to repurpose a bunch of 10 ESXi host for another purpose and I need to remove all the 12 datastores already mounted on the hosts. Here is a one-liner which I used to remove datastores quickly using vsphere powershell CLI commands. Note hosts.txt and ds.txt contains a list of hosts and datastores which you want to remove. Broke down into paragraphs for readability, this should be a one-liner. This is for 4.1 hosts. 5.0 host and beyond may require a different command due to storage I/O controls.

get-content c:\scripts\hosts.txt |

% { $h = $_ ; get-content c:\scripts\ds.txt |

%{ "Host="+$h+" : Removing Datastore... "+$_ ;

remove-datastore -Datastore $_ -VMhost $h -confirm:$false}}

 
Leave a comment

Posted by on June 27, 2013 in powershell, Scripts, vmware

 

Tags: , ,