Get started Bring yourself up to speed with our introductory content.

The top 10 PowerCLI scripts for vSphere administrators

1/12

PowerShell functions help smite difficult tasks

Source:  Thinkstock

No matter the size of the data center environment, systems administrators armed with PowerShell scripting knowledge can save time and increase their value to the business.

Many administrators who manage vSphere have adopted PowerShell as their scripting option over the past few years due to its simplicity and straightforward language.

Perhaps one of biggest advantages of PowerShell is its extensibility and third-party integrations. The VMware PowerCLI is a PowerShell snap-in that allows vSphere administrators to automate and report on almost all products and features that VMware offers. PowerCLI has been around for more than six years now and there are a number of useful scripts that can help an administrator tackle various tasks.

View All Photo Stories

Join the conversation

3 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

I would leave a more informative and worthwhile comment if you just put the 10 scripts into one article for the user to read.

As you have spread them over 10 pages I'll not bother. I don't have the time for messing about waiting for pages to load. Always make it a rule never to read past the first page when articles delivered like this.

It's a practice that is almost as bad as popups on every page that you have to close first!
Cancel
check out vSOM, VROI, VR Ops? these products most often solves most of these problems on a predictive basis. Many times there's no need for scripting, but I understand that people need their fun
Cancel

Can someone please review the code I have added below and let me know whether this would successfully take down and then start up a VM. And will it use the person who is running it's account details in the audit log for both take own and re-start. I ask because I have an issue whereby the audit log appears to indicate that the re-start wwas performed by  a system account (no name). Hope thi smakes sense here is the code


###################################################


#                                                 #


# Shutdown and Restart Redundant Exchange Servers #


# Created: SW                      23/09/2016              #


#                                                 #


###################################################


 


 


$UserCredential=IMPORT-CLIXML "C:ScriptsCredentialsCoreSecureCredentials.xml"


 


Connect-VIServer VS162 -Credential $UserCredential


 


 


Function Get-ViSession {


<#


.SYNOPSIS


Lists vCenter Sessions.


 


.DESCRIPTION


Lists all connected vCenter Sessions.


 


.EXAMPLE


PS C:> Get-VISession


 


.EXAMPLE


PS C:> Get-VISession | Where { $_.IdleMinutes -gt 5 }


#>


$SessionMgr = Get-View $DefaultViserver.ExtensionData.Client.ServiceContent.SessionManager


$AllSessions = @()


$SessionMgr.SessionList | Foreach {


$Session = New-Object -TypeName PSObject -Property @{


Key = $_.Key


UserName = $_.UserName


FullName = $_.FullName


LoginTime = ($_.LoginTime).ToLocalTime()


LastActiveTime = ($_.LastActiveTime).ToLocalTime()


 


}


If ($_.Key -eq $SessionMgr.CurrentSession.Key) {


$Session | Add-Member -MemberType NoteProperty -Name Status -Value “Current Session”


} Else {


$Session | Add-Member -MemberType NoteProperty -Name Status -Value “Idle”


}


$Session | Add-Member -MemberType NoteProperty -Name IdleMinutes -Value ([Math]::Round(((Get-Date) – ($_.LastActiveTime).ToLocalTime()).TotalMinutes))


$AllSessions += $Session


}


$AllSessions


}


 


 


 


$Connections = get-vm | get-snapshot | format-list


 


$Sessions = Get-ViSession


 


$vmserver rs=Get-VM VS153-EXCH-CAS-1


 


 


if (get-VIAccount !()) {


 


            #$vmserver| Shutdown-VMGuest -Confirm:$false


 


            Sleep 500


 


            Start-VM -VM $vmserver


 


}


 


 


$vmserver rs=Get-VM VS154-EXCH-CAS-2


 


if (get-VIAccount !()) {


 


            #$vmserver| Shutdown-VMGuest -Confirm:$false


 


            Sleep 500


 


            Start-VM -VM $vmserver


 


}


Cancel

-ADS BY GOOGLE

SearchServerVirtualization

SearchVirtualDesktop

SearchDataCenter

SearchCloudComputing

Close