Monday, November 26, 2018

How to get network statistics on a VM nic from SSH.


If you need to get the network statistics via SSH on a VM nic, run the commands below.

  1. 'esxcli network vm list' to get VM ID.
  2. 'esxcli network vm port list -w <VM ID>' to get port ID number.
  3. 'esxcli network port stats get -p <port ID number>' to get network statistics.
Output:
Packet statistics for port 50332931
   Packets received: 293182742829
   Packets sent: 90336672427
   Bytes received: 305397539251
   Bytes sent: 11805570153
   Broadcast packets received: 135893129
   Broadcast packets sent: 813717
   Multicast packets received: 386654045
   Multicast packets sent: 334554
   Unicast packets received: 292660195655
   Unicast packets sent: 90335524156
   Receive packets dropped: 0
   Transmit packets dropped: 0


Thursday, November 15, 2018

Get Active Directory User's password expiration date.


Most corporation that uses Microsoft's Active Directory has set some password policies for tighter security.  One of them is probably 'Password Expiration' to force users to change their passwords every x amount of days.  I was in a situation where I needed to find a user account password expiration and the first thing that come to my mind is to use Powershell.  Upon Googling on how to do it with Powershell, I found that it is very cumbersome to do it.  You run a get-aduser command and it will output the accountexpires attribute but its not in datetime format.  You'd have to convert it, which didn't work for me.  Then I find that you can use the basic net user command like below.

c:\net user <username> /domain

That's all.


Friday, November 9, 2018

How to reinventory/register a vm from the CLI.


To re-inventory/register a vm from the CLI, do the following from an ssh prompt.

  • vim-cmd vmsvc/getallvms | grep -i <VM Name>  to get the VM ID.
  • vim-cmd vmsvc/reload <VM ID>

Tested on ESX 5.0.x - 5.5.x

Thursday, November 8, 2018

Run a program as admin from command line.


Ever run into a situation where you need to run a program as admin and Windows is not allowing you because you're in a screenshare with someone and UAC is prompting you but not let you type in your administrator credentials?  Give the following a try!

  1. Open a command prompt.
  2. Type in the following command.  
    • runas /user:Administrator cmd
    • type in your Administrator password
  3. Another command prompt will open up but this time, its run under the Adminstrator account.
  4. Navigate to the executable file you want to run, if its not in the environment path and type in the name and hit enter.
  • Note:  for some reason, you can't open the control panel by running control.exe from this.  If anyone knows why, please let me know.

Thursday, August 30, 2018

APC UPS and Powerchute


Today, while trying to set up a static IP for a production UPS, I mistakenly powered off the UPS taking down a network switch that's running off of.  Normally, to configure an IP on a device, I would normally use a console/serial (here's where the confusion lies for me) cable.  I saw a port marked "Serial" and thinking that was the console port when in fact its a port to configure the Powerchute, which is a power down management software from APC that is in most of their UPS devices.  The issue lies in that serial port.  If anything but a Powerchute serial cable that is plugged into that port marked "Serial" on the UPS, once a unrecognized signal is sent to that serial port, Powerchute will shutdown the entire UPS along with the devices that's plugged into it.  Bad.  Why?  I don't know.

Took me about 10 mins to figure out what had happened and went to power the UPS back on.  There is a port labeled "Console" on the back of the UPS but I didn't think too much of it since there was just a little hole next to it.  The little hole is actually for the real console cable in the form of a 2.5mm jack.  I've never seen a console cable like that until now.

What could APC have done?  Well maybe rename the "Serial" port as "Serial for Powerchute" and maybe have some warning if plugging in a non-Powerchute serial will result in UPS shutdown if any unrecognize signal is passed to it.

I digress.  



Thursday, July 12, 2018

How to clear your variables in Powershell.


After running a Powershell command with a variable, the contents in that variable will stay in memory unless its cleared or overwritten to.  The command below is how to clear it from memory.  This helps when you're writing and testing a script to make sure you get accurate results and not results from stale memory in variables.

Remove-Variable * -ErrorAction SilentlyContinue

Power on a batch of VM's using Powershell


If you have a list of vm's and you need it to be powered on, the script below will help you do that.  To give the storage system air to breathe and not cause a boot storm, it powers on a VM every 2 seconds and waits 5 minutes after ever 50 VM is powered on.

Import-Module vmware.vimautomation.core
Remove-Variable * -ErrorAction SilentlyContinue
$vcenter = "hostname of vCenter or ESX host"
connect-viserver $vcenter
$count = 0
$csvfile = import-csv "Path to csv file"
foreach($vm in $csvfile)
{
    $vm_info = Get-VM -Name $vm.VMName   #VMName refers to column header in the  csv file.
    if ($vm_info.PowerState -eq "PoweredOff")
    {
        Write-Host "Powering on "$vm_info.Name
        $poweron = Get-VM $vm_info.Name | Start-VM -Confirm:$false
        Sleep 2             #power on a vm every 2 seconds.
        $count++
        if($count -eq 50)   #powers on 50 vm's then waits for 5 minutes for  storage to breathe.
        {
            Sleep 300
            $count = 0
        }
    }
}

Tuesday, July 10, 2018

Find a file in linux


To find a file in linux called "myfile", use the command below.
    [root@testbox /]# find / -name "myfile"


Tuesday, July 3, 2018

Power on a batch of virtual machines in a csv file using PowerCLI.

Use the following PowerCLI script to power on a list of Virtual Machines from a CSV file.

import-module vmware.vimautomation.core

$vcenter = <my vCenter server>
connect-viserver $vcenter
$allvms = import-csv RVTools_tabvInfo.csv

foreach ($strNewVMName in $allvms)
{   
        #gets all the VM's properties.  We're interested in the PowerState  Property.
        $vmdata = Get-view -ViewType VirtualMachine -Filter @{"name" =  $strNewVMName.vm}  #vm is the column header name in the csv on the first line.
        #if the PowerState is not PoweredOn, then power it on.
        if ($vmdata.Runtime.PowerState -ne "PoweredOn")
        {
            Write-Host "Powering on "$strNewVMName.vm
            Start-VM -VM $strNewVMName.vm
            Sleep 2
        }
}

Monday, July 2, 2018

Speed test on Google GCP instance.

Spun up a GCP instance today and ran a speed test.   No speed issues there.