Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
VMware
»
GetVI-VMList
GetVI-VMList
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Clone
Compare Clusters
Connect
Datastores
Disconnect
Disk Usage
Get-Stat
Guests
Healthcheck
Host Models
Host Version
Hosts
Load Balance
LUN
Measure-Object
Monitor
Snapshot Count
Thin-Provisioned
VI Toolkit
Virtual Disks
VM
VM List
VM's details of Data Center
VMware
vNIC
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
Richard Giles
10-06-2008
Downloads: 410
File size: 3kB
Views: 1,841
Embed
GetVI-VMList
## =====================================================================
## Title
: GetVI-VMList
## Description : Retrieve VMware VMs
## Author
: Idera
## Date
: 9/11/2008
## Input
: -VIserver : Virtual Infrastructure server
##
-verbose -debug
## Output
: VMs
## Usage
: PS> . GetVI-VMList myVIserver -v -d
## Notes
:
## Tag
: PowerShell, VMware
## =====================================================================
param
(
[
string
]
$VIserver
,
[
switch
]
$verbose
,
[
switch
]
$debug
)
function
main()
{
if
(
$verbose
) {
$VerbosePreference
=
"Continue"
}
if
(
$debug
) {
$DebugPreference
=
"Continue"
}
CheckVIToolKit
GetVI-VMList
$VIserver
}
function
GetVI-VMList
([
string
]
$VIserver
=
""
)
{
## Clear Screen.
Clear-Host
## Warn user they must be logged on with an account that has connection rights to the VI server.
$answer
=
Read-Host
"`n`n`n`tNOTE: You must be logged on with an account that has connection rights to the VI server. Press <X> to exit, <C> to continue if you have a connection to a VI Server already or <Enter> to continue. "
if
(
$answer
-eq
"x"
)
{
break
}
else
{
if
(
$VIserver
-eq
""
)
{
Write-Host
"`n`n`n`tERROR- A VI server must be specified!`n`n"
-foregroundcolor
red
Read-Host
"`n`t Press <Enter> to continue "
break
}
else
{
if
(
$answer
-eq
"C"
)
{
## do nothing as we have a connection we can use already..
}
else
{
Connect-VIServer
$VIserver
Write-Host
"`n`n`t You have connected to Server: $VIserver.Name with a SessionID of: $VIserver.SessionID ."
Read-Host
"`n`t Press <Enter> to continue "
}
}
## Clear Screen.
Clear-Host
## List the servers
$answer
=
Read-Host
"`n`n`t Enter (S) to specify a VM or (L) to display a list of all VM's "
if
(
$answer
-eq
"S"
)
{
$answer
=
Read-Host
"`n`n`t Enter the name of VM to display "
Get-VM
$answer
|
Format-Table
-autosize
Read-Host
"`n`n`t Press <Enter> to continue "
}
elseif
(
$answer
-eq
"L"
)
{
Get-VM
|
Format-Table
| more
Read-Host
"`n`n`t Press <Enter> to continue "
}
else
{
Read-Host
"`n`n`t Invalid option entered, Press <Enter> to continue "
break
}
}
}
## EOF: ConnectVI-Server()
function
CheckVIToolKit()
{
## Before we do anything we must check to see if the user has the VI toolkit installed.
## If user does not then we prompt the user and exit.
$Error
.
Clear
()
Get-PSSnapin
vmware
*
if
(
$Error
.
Count
-ne
0)
{
Clear-Host
Write-Host
"`n`n`t`t ERROR - To run this script, the VI Toolkit must be installed and registered with Powershell. If the VI Tollkit is installed,"
-foregroundcolor
red
-backgroundColor
yellow
Write-Host
"`t`t go to the Settings menu in Powershell Plus and click on Manage Snapins."
-foregroundcolor
red
-backgroundColor
yellow
Read-Host
"`n`n`t Press <Enter> to continue."
Clear-Host
break
}
}
## EOF: CheckVIToolKit()
## Run Main
main
Filed under:
VMware
,
VI Toolkit
,
VM List
Retrieve VM List from a Virtual Infrastructure Server using VI Toolkit PowerShell snapin.
Copyright 2011 PowerShell.com. All rights reserved.