Saturday, July 9, 2016

Powershell for VMware - Part II

On part two for PowerCLI cmdlets for handling virtual machine for VMware environment. We will start with some task and command associated with it. It will help to clear your basic handling for virtual machine and you can test some of cmdlets from below on your environment. 

Listing VMs, Hosts, Datastores, And Resource Pools.(Beginner)
Task
Solution
Connect to Virtual Center
Get-VC 10.0.0.2
Obtain a list of all VMs
Get-VM
Obtain a list of all Hosts
Get-VMHost
Obtain a list of all Datastores
Get-Datastore
Obtain a list of all Resource Pools
Get-Resourcepool

Creating a VM.
Task
Solution
Create a VM called “MyFirst_VM” on ESX1. Give the VM 256 MB of RAM and 1GB of disk
Get-VMHost ESX1 | New-VM  -Name ”MyFirst_VM”  -Memorymb 256 –diskmb 1024 –pool  (Get-resourcepool sales-esx1) –location (Get-folder sales)
Create a VM called “MySecond_VM” on ESX2. Give the VM 2 CPUs, and configure it to host Windows 2008 as the guest operating system.
Get-VMHost ESX2 | New-VM –Name “MySecond_VM” –Memorymb 1024 –diskmb 2048 –guestif Win2008ServGuest –pool  (Get-Resourcepool sales-esx2) –location (Get-folder sales)

Basic VM Modification
Task
Solution
Change the number of virtual CPUs configured for “Sales1” from 1 to 2
Get-VM “Sales1”  | Set-VM –numcpu 2
Change the amount of RAM configured for “Sales1” from 256mb to 1024mb
Get-VM “Sales1” | Set-VM –memorymb 1024
Verify that your modifications were successful
Get-VM “Sales1”

Powering VMs ON & OFF
Task
Solution
Determine the power status of all available VMs
Get-VM |ft name,powerstate
Power on the “Server1” virtual machine
Get-VM  “Server1”| Start-VM
Reset the “Server1” virtual machine
Get-VM “Server1” | Stop-VM
Suspend the “Server1” virtual machine
Get-VM “Server1” | Suspend-VM
Resume the “Server1” virtual machine
Get-VM “Server1” | Start-VM
Power off the “Server1” virtual machine
Get-VM “Server1” | Stop-VM


Sunday, July 3, 2016

Powershell for VMware - Part I


Powershell is an interactive command-line interpreter, much like the familiar DOS prompt, or the shell environment in UNIX.

What really sets Powershell apart from other command-line environments is that applications are being  built with Powershell manageability expressly in mind, which means that in the Windows world. Powershell will become increasingly important for managing large numbers of servers and applications.

You can use powershell for managing VMware environments, handling large virtual machines is very tideous task for administrators.

PowerCLI is a Windows PowerShell interface for managing VMware vSphere.

VMware describes PowerCLI as "a powerful command-line tool that lets you automate all aspects of vSphere management, including network, storage, VM, guest OS and more. PowerCLI is distributed as a Windows PowerShell snapin, and includes over 370 PowerShell cmdlets for managing and automating vSphere and vCloud, along with documentation and samples.

In this blog, I will cover some cmdlets

1. Connect-VIServer: To connect to any vSphere connect, you need to use connect-viserver.
    Example: Connect-VIServer -server 10.0.0.2 -User Shanky\admin
    This examples connects to you shell to VI server at 10.0.0.2. You can mention username and               password

2. Get-VIServer: Before you can do any VMware management from
    PowerShell you must first connect to a VC server or ESX host.
    Example: Get-VIServer 10.0.0.2
    This example connected machine is VI server at 10.0.0.2 . In order to complete the
    connection you will be asked for a user name and password.

3. Get-VM: This VMware cmdlet retrieves managed virtual machines.
    Example: Get-VM | select name, memorymb
    This example: displays all VMs in the virtual infrastructure, along with the
    amount of memory allotted to the VM.

4. Get-VMHost: This VMware cmdlet retrieves VM hosts (
    Example: Get-VMHost | select name
    This example creates custom report about all VM hosts that are available in the
    virtual infrastructure.

Friday, July 1, 2016

Creating Users On Windows Server 2012 Using PowerShell


        Scripting user creation in Windows Server is something we’ve long done using LDIF files; however, when building a system that creates users in more of a one-off capacity it’s pretty easy to script the creation process using PowerShell, piping information in from other solutions. To create a user, use the New-ADUser cmdlet.

         I’ve found that we usually need to populate this with a few pieces of information, including the account name (SamAccountName), the password (AccountPassword), the full name (name) enabling the account (enabled), setting the password not to expire (PasswordNeverExpires) and forcing the user to change their password when they log on (ChangePasswordAtLogon). Respectively, the following example would create user cedge with a password of mypassword, a name of Charles Edge, enabling the account, allowing the password to expire and forcing me to change my password the first time I log in:
New-ADUser -SamAccountName cedge -AccountPassword (read-host "Set user password" -mypassword) -name "Shankar Sahu" -enabled $true -PasswordNeverExpires $false -ChangePasswordAtLogon $true

        Once created, the account likely needs to be made a member of some groups. At this point, we’ll need to identify the user by cn (so if the user is in a specific OU, that would need to be included in the -Identity parameter. Because namespace collisions can happen, you’ll need to provide the full CN of both the user (using the Identity parameter) and the group (using the MemberOf parameter). Let’s say I’m going to add that account that I just created, which is in Users of krypted.com to the Enterprise Admins group of the same domain, that would look like this:
Add-ADPrincipalGroupMembership -Identity "CN=Mumbai BR,CN=Users,DC=Shanky,DC=com" -MemberOf "CN=Enterprise Admins,CN=Users,DC=Shanky,DC=com","CN=Domain Admins,CN=Users,DC=Shanky,DC=com"

Overall, it’s pretty easy to call these cmdlets from other scripts, so for example, if you wanted to build a system that allowed an HR professional to enter a username and password for a user then create their account in AD, Google Apps and a few other solutions, this would make for the first step, piping that account name and password into each.


Windows Server 2016 Key Features and License Prospects

If you are planning to move to Windows 2016 and looking for benefits, I have listed down below : Why Windows Server 2016? ·     ...