Monday, November 23, 2015

PowerCLI script to query a multiple network subnets

Here's a script that has a line multiplied 8 times, each to reflect the subnet it's querying and then outputting the results to a specific CSV file with the network subnet it just queried.



get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.6.*"} | export-csv -path c:\tmp\vmware\VM_IP_6_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.7.*"} | export-csv -path c:\tmp\vmware\VM_IP_7_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.8.*"} | export-csv -path c:\tmp\vmware\VM_IP_8_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.10.*"} | export-csv -path c:\tmp\vmware\VM_IP_10_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.11.*"} | export-csv -path c:\tmp\vmware\VM_IP_11_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.12.*"} | export-csv -path c:\tmp\vmware\VM_IP_12_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.13.*"} | export-csv -path c:\tmp\vmware\VM_IP_13_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.14.*"} | export-csv -path c:\tmp\vmware\VM_IP_14_Addresses.csv -notypeinformation


get-vm | select Name,@{N="IPAddress";E={@($_.guest.IPAddress[0])}},@{N="OS";E={@($_.Guest.OSFullName)}} | where {$_.IPAddress -like "192.168.15.*"} | export-csv -path c:\tmp\vmware\VM_IP_15_Addresses.csv -notypeinformation

PowerCLI script to query a VLAN for specific VM members.


Here's a script that will show you all the VMs that belong to a specific VLAN within vCenter. This is handy when you have multiple VLANs created and don't know which VMs belong to which VLAN.

#Production_VLAN is the name of the VLAN you are querying
$vms=get-view -viewtype virtualmachine
foreach($vmview in $vms )
{
$ntwkview=get-view -id $vmview.network
foreach($ntwkentry in $ntwkview){
if ($ntwkentry.name -eq "Production_VLAN")
{
$vmview.name
}
}
}

PowerCLI script to list NIC address information for VM's

Here's a script to find the network information for all the VM's in your Clusters. This will list the VM Name, MACaddress, Network/VLAN, DHCP, IP address, Subnet Mask.


#If you only want a specific VM NIC, change "Get-Cluster | Get-VM" to "Get-VM "VM_Name"

&{foreach($vm in (Get-Cluster | Get-VM)){
    $vm.ExtensionData.Guest.Net | Select @{N="VM";E={$vm.Name}},MacAddress,Network,
    @{N="DHCP";E={$_.IpConfig.Dhcp.Ipv4.Enable}},
    @{N="IP";E={$_.IpAddress[0]}},
    @{N="Subnet Mask";E={
            $dec = [Convert]::ToUInt32($(("1" * $_.IpConfig.IpAddress[0].PrefixLength).PadRight(32, "0")), 2)
            $DottedIP = $( For ($i = 3; $i -gt -1; $i--) {
                    $Remainder = $dec % [Math]::Pow(256, $i)
                    (                        $dec - $Remainder) / [Math]::Pow(256, $i)
                    $dec = $Remainder
                } )
            [String]::Join('.', $DottedIP)
        }}
}}

PowerCLI script to match a rogue IP address to a VM.

Here's a quick way of finding which system has a specified IP address assigned to it. You have a rogue IP address and don't know which VM is assigned to it.


$match_address = "192.168.10.27"
Get-VM | %{
      $vmIPs = $_.Guest.IPAddress
      foreach($ip in $vmIPs) {
          if ($ip -eq $match_address) {
              "Found VM with matching address: {0}" -f $_.Name
          }
      }
  }

PowerCLI script to query VM for SnapShots and sizes.

Here's a simple script to query all your VM's that currently have snapshots. 5 columns are created starting from VM, SnapShotName, Snapshot Description, Size (Snapshot), Date Created.

$Report = Get-VM | Get-Snapshot | Select VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created
If (-not $Report)
{  $Report = New-Object PSObject -Property @{
      VM = "No snapshots found on any VM's controlled by $VIServer"
      Name = ""
      Description = ""
      Size = ""
      Created = ""
   }
}
$Report = $Report | export-csv -path c:\tmp\vmware\snapshotsDAYMONTH.csv



Append "| export-csv -path c:\tmp\vmware\vm_tools_upgrade.csv" to the end of the script for viewing and reporting purposes.


PS > Snapshot.ps1

PowerCLI script to show VM's needing VMware Tools upgraded.

I started looking for a way to inventory all of our VM's currently running within our 6-7 clusters.
Most of our VM's had the latest version of VMware tools but there were plenty that were out of compliance. I didn't want to take the time to individually check each VM (500+ VM's) so after some searching I found a script that showed me the tools version on the VM's that were out of compliance.


# Select Cluster you wish to scan "User VMs"#
PS > get-view -ViewType virtualmachine -SearchRoot (get-cluster "User VMs").id -Filter @{'Summary.Guest.ToolsVersionStatus'='guestToolsNeedUpgrade'} | Select Name,@{N='VMware Tools Version';E={$_.Config.Tools.ToolsVersion}},@{N='Tools Status';E={$_.Summary.Guest.ToolsVersionStatus}}


Append "| export-csv -path c:\tmp\vmware\vm_tools_upgrade.csv" for viewing and reporting purposes.

The output would show:

Name                                                   VMware Tools Version   Tools Status
VM_1                                                                                 8394  guestToolsNeedUpgrade
VM_2                                                                                 9344  guestToolsUpgrade

PowerCLI script to collect "Computers that have a specific OS installed"

I started looking for a way to inventory all of our VM's currently running within our 6-7 clusters. There was such a variety of OS's running that I didn't want to take the time to individually check the setting on each VM (500+ VM's). So after looking at different scripts, I took a combination of two or three and after trail and error I was able to filter my search results for exactly what I was looking for. In the end the script basically spits out the version of OS currently installed and IP Address of the VM. The IP address was critical in my search because we are running several different subnets and I needed to know exactly where the VM resided.

I then exported the results to my local C: drive in CSV format for viewing and reporting purposes.

# The *Cent* is changed to reflect what flavor of OS you may be looking for. *Red Hat*, *Server*, *Workstation*,etc..#
PS > get-vm | get-view | where {$_.Guest.GuestFullName -like "*Cent*"} | select Name,@{N="OS";E={@($_.Guest.GuestFullName)}},@{N="IP";E={@($_.Guest.IPAddress)}} | export-csv -path c:\tmp\vmware\CentOS.csv

Tuesday, November 17, 2015

VMWare View Windows 7 Optimization Install

 

Preparing a new virtual machine

1. Create New Virtual Machine – FILE > NEW > VIRTUAL MACHINE (CTRL+N)
2. Under Configuration select CUSTOM.
3. Select a Name, Folder, Host, Cluster, and Storage.
4. Virtual Machine Version: vmx-10
5. Under Guest Operating System: Windows
a. Version: Windows 7 64bit
6. Number of virtual sockets: 1
a. Number of cores per virtual socket: 1
b. Total number of cores: 1
7. Memory Configuration 4GB
8. Select which Network (VLAN) and under Adapter select VMXNET 3.
9. SCSI Controller: LSI Logic SAS
10. Disk: Create a new virtual disk
a. Configure disk size to 32GB THIN provisioned.
11. Advanced Options keep defaults
12. Check “Edit the virtual machine settings before completion” and then Continue
13. Video Card: Do not “Auto detect” , set to 2 displays and 128 MB video memory Video Card: Enable 3D support
14. Remove Floppy Drive 1.
15. Go to Boot Options and check "The next time the virtual machine boots, force entry into the BIOS setup screen.
16. Click Finish
17. Power on virtual machine and open Console – virtual machine should be loaded into the BIOS screen.

BIOS.

1. Under MAIN, Legacy Diskette A: change to Disabled.
2. Keyboard Features: change Numlock to ON.
3. Under ADVANCED, I/O Device Configuration: disable all Serial, and Parallel ports, as well as Floppy Controller.
4. Exit and Save Changes.
5. After Reboot Power Off and Enter Edit settings again.
6. CD/DVD: Device Type Datastore ISO File
a. Select the WIN764bit ISO
b. Check Connect at Power On
7. Click on OPTIONS tab and then General, UN-Check "Enable logging".
8. Finish
9. Power On


Installing Windows 7

1. Boot from your Windows 7 installation media.
2. Click the "Next" button.
3. Click the "Install now" button.
4. Accept the terms and click the "Next" button.
5. Choose "Custom: Install (advanced)."
6. At “Where do you want to install Windows” screen, press Shift + F10 to open a command prompt.
7. At the command prompt, enter following commands:
a. Diskpart
b. Select disk 0
c. Create Partition Primary
d. assign
e. Exit
f. Exit
8. Click Refresh
9. Select "Disk 0 Partition 1"
10. Complete the install on the disk formatted with the 8192 allocation size.

Installing VMWare Tools

1. Right click on virtual machine and select GUEST > Install/Upgrade VMware Tools.
2. Don’t Restart instead Shutdown virtual machine.
3. Enter Edit Settings once again and remove ISO on CD and then Remove CD/DVD Drive

Windows 7 Optimization

1. Go to Control panel and turn off all Action Center Settings and User Account Controls
2. Run Windows updates
3. After updates run Command.bat as Administrator found in the VMView Windows 7 Optimization http://www.vmware.com/resources/techresources/10157. I have also included it as an attachment.
4. Turn off Drive Indexing
a. Open the Start Menu
b. Click Computer
c. Right click C: drive and select Properties and uncheck drive indexing
d. Click apply changes to drive C:\, subfolders and files (ignore all when comes up)
5. Shrink Page File
a. Open the Start Menu
b. Right click Computer
c. Click Properties
d. Click Advanced System Settings (it’s on the left side)
e. Under performance click Settings
f. Go to the Advanced tab
g. Under Virtual memory click Change
h. Uncheck the "Automatically manage paging file" box at the top
i. Select the C: drive
j. Click "Custom size"; initial size 512MB, maximum size 2048MB
k. Click "Set"
l. Click OK
m. Click OK
n. Start closing Open Windows and it will ask to restart.
6. RESTART Virtual Machine
7. Change Power Options
a. Open the Start Menu, in the search line, type Power Options and press Enter
b. Select the "High performance" power plan
c. Click "change plan settings"
d. Click "change advanced power settings"
e. Expand the Hard disk option and change setting to "never"
f. Expand the Sleep option and change setting to "never"
g. Click OK
8. Uninstall Tablet PC, Windows Gadgets, and Media Center
a. Open Control Panel > Programs and Features > Turn Windows features on or off.
b. Uncheck Media Center, Tablet PC, and Windows Gadgets.
9. Disable Windows Themes
a. Control Panel > Personalization > Select Windows Classic.
10. Set Run for Best Performance
a. Right click on Computer and select Properties
b. Select Advanced system settings
c. Under the Advanced Tab, click Settings next to Performance
d. Select "Adjust for best performance"
11. Disable System Maintenance
a. Control Panel > Troubleshooting > Change Settings and select OFF under Computer Maintenance.
12. Disable Screensaver 1.Control Panel > Personalization > Screen Saver and change to NONE.
13. Disable Windows Sounds 1.Control Panel > Personalization > Sounds > and change Sound Scheme to No Sounds.
14. Speed up the Menu Show delay time
a. Open Regedit
b. Go to: HKEY_CURRENT_USER\Control Panel\Desktop
c. Modify MenuShowDelay from 400 to 1
15. Disable Un-needed Services
a. Telephony
b. Volume Shadow Copy Service – Not needed since System Restore is disabled.
16. Startup and Recovery
a. Open the Start Menu
b. Right click Computer
c. Click Properties
d. Click Advanced System Settings (it’s on the left side)
e. Under Startup and Recovery click Settings
f. Set the “Time to display list of operating systems” to 1
g. Disable “Write an event to the system log”
h. Click OK
i. Click OK
17. Boot GUI
a. Run msconfig
b. Under Boot tab Enable “No GUI boot” and “Base Video”
18. Restart

GPO Changes

19. Disable success logins
a. Computer Configuration > Policies > Windows Settings > Security Settings > Local Policies > Audit Policy
b. Under Audit account logon events settings Properties select the Security Policy Setting tab.
c. Select the Failure checkbox.
20. Set maximum Event Log size
a. Computer Configuration > Administrative Templates > Event Log Service > Specific Event Log
b. Maximum application, security, and system log size = 1024
21. Empty IE temp files
a. User Configuration > Administrative Templates > Windows Components > Internet Explorer > Internet Control Panel > Advanced Page
b. Empty Temporary Internet Files folder when browser is closed = Enabled
22. Disabled IE First Run Customize Wizard
a. User Configuration > Administrative Templates > Windows Components > Internet Explorer
b. Prevent performance of First Run Customize settings – Enabled
23. Disable RSS Feeds
a. User Configuration > Administrative Templates > Windows Components > RSS Feeds
b. Turn off background sync feeds and web slices = Enabled
24. Disable Windows Slideshow
a. User Configuration > Administrative Templates > Windows Components >Windows Slideshow
b. Turn off Windows Slideshow = Enabled
25. Turn off Build-to-Lossless feature
a. Computer Configuration > Administrative Templates > Classic Administrative Templates (ADM) > PCoIP Session Variables
b. Turn off Build-to-Lossless feature = Enabled
26. Limit audio bandwidth
a. Computer Configuration > Administrative Templates > Classic Administrative Templates (ADM) > PCoIP Session Variables
b. Change Configure the PCoIP session audio bandwidth limit to 100
27. Set PCoIP frame rate and image quality
a. Computer Configuration > Administrative Templates > Classic Administrative Templates (ADM) > PCoIP Session Variables
b. Maximum Initial image quality = 70
c. Minimum Image Quality = Leave default
d. Maximum Frame Rate = 15

Friday, November 13, 2015

PowerCLI script to collect "Computers that have not logged on since specified date"

I needed to collect and Inventory all VM's that have not logged on since a specified date. In my case I was looking for systems that hadn't logged on in the past 90 days. Substitute the "$DaysInactive" with what suits your case.

# Gets time stamps for all computers in the domain that have NOT logged in since after specified date   
$domain = "YouDomain.Name" 
$DaysInactive = 90 
$time = (Get-Date).Adddays(-($DaysInactive))
 
# Get all AD computers with lastLogonTimestamp less than our time
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp |
 
# Output hostname and lastLogonTimestamp into CSV
select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv -path c:\tmp\vmware\LastLogon_90_Days.csv -notypeinformation