Thursday, June 27, 2019

Run Powershell commands remotely with PSSession.


Here's a way to run Powershell commands on a remote machine.  It saves the hassle of RDP'ing into the remote machine, wait for Windows to load your profile, run startup scripts, apply GPO settings, load your desktop, etc...  That can be time consuming if you're always logging into to remote machine to verify something.

  1. Create a remote session
    • new-pssession <computer hostname>
  2. Get the ID of the remote session.
    • get-pssession
  3. Connect to that remote session using the ID.
    • enter-pssession <ID>
  4. Once connected, you should see the computer hostname in brackets like below.
    • [computername]: PS C:\users\guest
  5. Execute your Powershell command like so.
    • [computername]: PS C:\users\guest> get-volume
  6. To exit the session, just type the following.
    • exit or exit-pssession
  7. After exiting of the session, you would want to remove/close the session from your computer.
    • remove-pssession <id>
      • Leave me a comment if you know of a way to remove 'all' the sessions at once without looping it in a script.

Hope this helps.

Tuesday, June 25, 2019

Rubrik: Backup, Replication and Disaster Recovery.


Just started looking into Rubrik to backup and DR my work's VM.  In short, Rubrik is a hardware appliance that does VM snapshot backup, replication and DR.  It's fairly straight forward to use and the web console is easy to navigate.  It does replication to a second Rubrik cluster for DR.  So if you want to do replication, you will need 2 appliances. One of their selling point is the Live Mount Recovery feature.  If you're in a scenario to recover a corrupted production VM, Live Mount Recover can mount the Rubrik device as a datastore on your ESX host and power on the VM directly.  This will provided you with minimal downtime from the traditional VM restore.  It also backs up physical machines granted you install their agent.  The agent will allow you to pick and choose what files you want to back up, but the downside to that is this agent backs up on a file level.  So no System State backups or bare metal restores.  Rubrik uses a SLA policy driven to do backups and archive.  You can create as many SLA policies you want and within each of those policies, you can specify when to do snapshots, how often to do it and how many snapshots to retain.   It's very granular in terms of snapshot flexibility.  Since Rubrik is a bit new to the scene, there are some functionality that it does not provide.  I'm hoping they are working on adding these features in for future releases.   Below are some of the pro's and con's.  Note that some of the current missing feature sets mentioned here might be available on the latest release or by the time you've read this.  But my recommendations before you jump into Rubrik is to also look at their direct competitor.

Rubrik Hardware
Rubrik device mounted on the rack.  This 2U 'Brik' has 4 nodes.








Rubrik Hardware
Front Bezel Removed.







Pros
  •    Live mount recovery/Instant Recovery.  Can automatically mount the Rubrik device as a datastore in ESX and run VM's off it.
  •     VM backups and replication
  •     SQL db backups (with an agent installed)
  •     Very granular SLA's and retention
  •     Archive to cloud from SLA's
  •     Granular file/search and recovery within a VM
  •     Scalable.  You can add more nodes to the cluster for more space capacity.
  •     End to end encryption (at rest and in transit)
  •     Good granular reporting.
  •     RBAC permissions.
  •     Hardware and Software solution.  Nothing else you need to buy.
  •     Deduplication

Cons

  •      No active directory object level backups
  •      No system state backups.
  •     Web console difficult to navigate.  We found its difficult to see if a job has failed without doing a report.  They tend to want you to search by VM to determine if a VM has failed to back up.
  •      Weak audit logging.  No way to tell if someone modified a job.  
  •     Pricey compared to its competitors, maybe 2x pricey.  Mostly software and maintenance cost.
  •      vSphere level snapshot backups.  Can be problematic if you have a vm with a large virtual disk as large snapshots can take time creating snapshot and cleaning up snapshots.



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"