Search This Blog

Calculate Annual Rate of Growth

Here is the method to calculate the annual rate of growth over a period of time, e.g. salary or investment. In the following formula, the beginning balance is A, after Y years, the ending balance is B.

  1. Calculate the percentage of change: B / A
  2. Divide one by the number of years: 1 / Y
  3. Calcualte the annul rate of growth: ( B / A ) ^ ( 1 / Y ) - 1
  4. Convert the number in #3 to percentage

For example, the begining balance is 5000, after 10 year, the ending balance is 6000.

The annual rate of growth in 10 years is ( 6000 / 5000 ) ^ ( 1 / 10 ) – 1 = 0.0184 = 1.84%

Downgrade Virtual Machine Hardware Version in vSphere

Each major release of VMware vSphere comes with a newer virtual machine hardware version that provides the latest features. In order to unlock these features in an existing VM, the VM needs to be migrated to the new ESXi host and upgrade its hardware version.

Upgrading a VM’s hardware version is simple: power off the VM; in the vSphere Web client, right-click on the VM and select Compatibility and Upgrade VM Compatibility.

Once its hardware version is upgraded, the VM cannot boot in the older ESXi host any more. To downgrade the hardware version, there are three options according to VMware KB1028019:

  • Revert to a snapshot created before upgrading the VM hardware version
  • Use VMware vCenter Converter Standalone and select the required VM hardware version in the Specify Destination wizard
  • Create a new VM with the required hardware version and attach the existing disk from the VM

I found the third option is the quickest way and provided a little more detail below.

  • (optional) Make a clone of the VM or template, if you want to keep a template for both the existing and previous hardware version
  • Gather the VM’s virtual hardware (CPU, Memory, Hard disks – including the name and location of each VMDK files, Controller Type, Network Adapter’s network and type, Guest OS and Version)
  • Remove the VM from inventory
  • Create a new VM
    • Select the required hardware version in Compatibility
    • VM.Hardware.Version.Downgrade.01
    • Select the guest OS and version to match the original VM
    • VM.Hardware.Version.Downgrade.02
    • Customize the CPU, Memory, Controller, Network Adapter type to match the original VM
    • Add a new existing hard drive and select the VMDK file to match the original VM
    • VM.Hardware.Version.Downgrade.03
  • Once the new VM is created, right-click on the VM and select Edit Settings and remove the first hard disk that is added by default
  • Here are the screenshots to show the hardware version before and after the downgrade
  • VM.Hardware.Version.Downgrade.04VM.Hardware.Version.Downgrade.05

Batch Script for Creating An User and Adding to Member of Local Administrators Group

I built a batch script to create a local user and add it to the local administrators group. The script requires two arguments – one is the user’s login name, another is the user’s full name. The user’s password is hard-coded, but it can be changed to an argument with a small modification.

@echo off
set PASSWORD=XXXXXXXXX

REM add a local user with password
net user %1 %PASSWORD% /add /fullname:%2

REM add a local user to the administrators group
net localgroup administrators %1 /add

One thing I learned is that not all options (e.g. /fullname) are showed when typing “net user /?”. For more other options, see this Technet document.

Using nmap to Test DNS Server Recursion

  1. Download nmap binaries. For Windows OS, download the command-line zipfile is sufficient.
  2. Unzip the zip file, and install Winpcap and Visual C++ Redistributable Package installer included in the zip file
  3. Open command prompt
  4. Run “nmap –sU –p53 –script=dns-recursion <DNS_Server_IP>
  5. If the server allows resursion, it shows “Recursion appears to be enabled”

To prevent the DNS server from being used for DNS amplification attacks, disable DNS recursion on the public facing DNS server. The DNS recursion should be enabled on the DNS server serving the internal client.

On a Windows DNS server, this can be done under the DNS server properties, Advanced tab, Server options, check the checkbox “Disable recursion (also disable forwarders)”

WinDNS.Disable.Recursion

Use Get-FolderItem.ps1 to Fix PathTooLongException

When using Get-ChildItem to list all files in a folder and its subfolders, it returns the “PathTooLongException” error. This happens when the file path is more than 260 characters.

There are several ways to work around this issue. See this Technet Wiki.

Personally, I found the Get-FolderItem.ps1 script is the easiest one.

  1. Download the script from Microsoft Script Center Repository
  2. Right-click on the script and select Properties, then click Unblock
  3. Launch a PowerShell session
  4. Load the Get-FolderItem function into the session by entering “. <path>\Get-FolderItem.ps1”. (make sure there is a space between the “.” and the script)
  5. Enter “Get-FolderItem –Path <path>” to list all files in the folder and its subfolders
  6. Another use case “Get-FolderItem –Path <path> | Where {$_.LastWriteTime –gt “MM/DD/YYYY” } | Select FullName | Ft –autosize | Out-File c:\temp\modified.file.log.txt –width 4096

For more information about the Get-FolderItem.ps1 script, see this.

Prevent PowerShell Out-File Truncating Output

When trying to list the full path of all files in a folder and its subfolders, the Out-File cmdlet truncats the path for files with the long path.

It turns out that Out-File outputs the data with the same width of the PowerShell console (see Using the Out-File Cmdlet).

To work around the issue, include the –width parameter and specify a different line width(e.g. –width 4096). This outputs every line with 4096 characters long (pedding with spaces).

To output line width to match the longest output, add Ft –autosize before Out-File. For example:

Get-ChildItem -File -Recurse -Path Z:\ | where {$_.LastWriteTime -gt "MM/DD/YYYY"} | select FullName | Ft -autosize | Out-File c:\temp\modified.file.txt -Width 4096

vSphere Memory Ballooning

I know nothing about memory ballooning until I read this post – “How does memory ballooing work”.

Here is my understanding of this topic:

What is memory ballooning?

The ballooning driver (part of VMware Tools) frees up the VM guest memory (active memory + free memory) and makes it available to the Hypervisor (so avoid hypervisor swapping).

How does it work? and how does it impact performance?

The ballooning driver will balloon all ram down to the minimum recommended memory for each operating system + Mem.AppBalloonMaxSlack (16 MB by default, it’s adjustabe from 1 MB – 256 MB). The minimum recommended memory value is set by the operating sytem vendor and hard coded by VMware. It cannot be changed.

For example, RHEL 7’s minimum recommended memory is 512 MB. The ballooning driver will balloon all ram down to 528 MB (512 + 16). If an application in the OS requests more than 528 MB memory, it causes the guest operating system to swap/page. This is better than hypervisor swapping, but still a really bad impact for performance.

 How to avoid Ballooning?

  • Avoid over provisiooning server memory (the best option)
  • Make a reservation for server memory (bad idea in most respects)
  • Do not install VMware Tools (bad idea in every respects)

Use WinSCP to Transfer Files in vCSA 6.7

This is a quick update on my previous post “ Use WinSCP to Transfer Files in vCSA 6.5 ”. When I try the same SFTP server setting in vCSA 6.7...