Getting Started with VMware vSphere PowerCLI

VMware are providing vSphere PowerCLI to make it possible to administer vSphere and vCloud Director using PowerShell.

A good startingpoint is the VMware vSphere PowerCLI Documentation page that is available at: https://www.vmware.com/support/pubs/ps_pubs.html

If you´re in a hurry you could follow my quick starting guide below:

Step 1. Download and install VMware vShere PowerCLI:
VMware vSphere PowerCLI is available for download from http://www.vmware.com/support/developer/PowerCLI/index.html
Select the release you want to download from the drop-down list and click on the download-link.
Double-click on the downloaded installation-package and follow the instructions to install PowerCLI.

Step 2. Start PowerCLI and connect to a vCenter Server:
Double-click on the “VMware PowerCLI” icon to start PowerCLI.

PowerCLI
PowerCLI

Use the CmdLet ‘Connect-VIServer’ as shown below to connect to the vCenter Server:

Connect-VIServer -Server <server-IP> -Protocol https -Username '<Username>' -Password '<Password>'

Now you are ready to explore and manage the VMware vCenter environment using PowerShell. Start by executing the following CmdLet to list all available commands.

Get-VICommand

PowerShell Remoting

First of all Powershell Remoting must be enabled on the machine you are going to manage. The command ‘Enable-PSRemoting -Force’ starts the WinRM service, changes its startup mode to automatic and creates a firewall-rule that allows incoming connections.

You can test the connection by entering the following Powershell command from an remote computer:
Test-WsMan

The result should look something like in the following example:
PS C:\Users\TestUser> Test-WsMan TESTCOMPUTER

wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor : Microsoft Corporation
ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

To create a remote session, enter the following command:
Enter-PSSession -Computername -Credential <domain\username>

References:
https://technet.microsoft.com/en-us/library/hh849694(v=wps.620).aspx
https://technet.microsoft.com/en-us/library/hh849873(v=wps.620).aspx
https://technet.microsoft.com/en-us/library/hh849707(v=wps.620).aspx

Initialize, partition and format disks using PowerShell

I ran into this good blogpost about using PowerShell to Initialize Raw Disks, and to Partition and Format Volumes.
http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/29/use-powershell-to-initialize-raw-disks-and-partition-and-format-volumes.aspx

To summarize, you can initialize raw disks and partition and format volumes using the following simple PowerShell “script”:
Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel “disk2” -Confirm:$false

FREE Microsoft eBooks

Microsoft Senior Sales Excellence Manager – Eric Ligman posted a list of almost 300 FREE Microsoft eBooks. You can download them all from hos blog at the following address:
http://blogs.msdn.com/b/mssmallbiz/archive/2014/07/07/largest-collection-of-free-microsoft-ebooks-ever-including-windows-8-1-windows-8-windows-7-office-2013-office-365-office-2010-sharepoint-2013-dynamics-crm-powershell-exchange-server-lync-2013-system-center-azure-cloud-sql.aspx

Use PowerShell to Find Service Accounts

I was looking for a way to find service accounts using PowerShell and found the following post on the “Hey, Scripting Guy! Blog”:

http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/15/the-scripting-wife-uses-powershell-to-find-service-accounts.aspx

To summarize, you can use the Get-WmiObject cmdlet to retrieve information about service accounts as in the following example:

Get-WmiObject win32_service | format-table Name, StartName

The broken Operations Manager Shell

I have a management server with the Operations Manager Console installed. When I tried to start the Operations Manager Shell it failed with the following errormessage:
Import-Module : The specified module ‘OperationsManager’ was not loaded because
no valid module file was found in any module directory.
At line:1 char:14
+ Import-Module <<<< OperationsManager; .\OperationsManager\Functions.ps1; .\O perationsManager\Startup.ps1
     + CategoryInfo : ResourceUnavailable: (OperationsManager:String)
        [Import-Module], FileNotFoundException
       + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
        ands.ImportModuleCommand

The term ‘Start-OperationsManagerClientShell’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\System Center 2012\Operations Manager\Powershell\OperationsManager\Startup.ps1:26 char:35
+ Start-OperationsManagerClientShell <<<< -ManagementServerName: “” -PersistConnection: $true -Interactive: $true;
         + CategoryInfo : ObjectNotFound: (Start-OperationsManagerClientShell:String) [], CommandNotFoundException
         + FullyQualifiedErrorId : CommandNotFoundException

The reason for this was that the path to “C:\Program Files\System Center 2012\Operations Manager\Powershell\” was missing in the envorinmental variable PSModulePath. Once completed and logged out and back in to the system everything worked as espected.