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-VM
GetVI-VM
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: 393
File size: 1.9kB
Views: 1,506
Embed
GetVI-VM
## =====================================================================
## Title
: GetVI-VM
## Description : Retrieve VMware VMs
## Author
: Idera
## Date
: 9/11/2008
## Input
: -VIserver : Virtual Infrastructure server
##
-vm : VM server to get server information, blank for all
##
-verbose -debug
## Output
: VMs
## Usage
: PS> . GetVI-VM myVIserver -v -d
## Notes
:
## Tag
: PowerShell, VMware
## =====================================================================
param
(
[
string
]
$VIserver
=
"myVIserver"
,
[
string
]
$vm
,
[
switch
]
$verbose
,
[
switch
]
$debug
)
function
main()
{
if
(
$verbose
) {
$VerbosePreference
=
"Continue"
}
if
(
$debug
) {
$DebugPreference
=
"Continue"
}
GetVI-VM
$VIserver
$vm
}
function
GetVI-VM
([
string
]
$VIserver
, [
string
]
$vm
)
{
$Error
.
Clear
()
Get-PSSnapin
vmware
*
if
(
$Error
.
Count
-ne
0)
{
$Err
=
"ERROR"
+
"`nTo run this script, the VI Toolkity must be installed and registered with Powershell."
+
"`nIf the VI Tollkit is installed, go to the Settings menu in PowershellPlus console, "
+
"`n
click on Manage Snapins and check the VMware snapin to load it."
Write-Host
$Err
-foregroundcolor
red
-backgroundColor
yellow
break
}
else
{
if
(
$VIserver
-ne
$null
)
{
$viSrv
=
Connect-VIServer
$VIserver
Write-Debug
"You have connected to Server: $viSrv.Name with a SessionID of: $viSrv.SessionID ."
if
(
$vm
-eq
""
)
{
Get-VM
|
Sort-Object
-property
Name
}
else
{
Get-VM
$vm
|
Sort-Object
-property
Name
}
Disconnect-VIServer
-Server
$DefaultVIServer
}
else
{
Write-Host
"You must supply a valid host name"
}
}
}
main
Filed under:
VMware
,
VI Toolkit
,
VM
Retrieve VMware VMs from a Virtual Instructure Server using VI Toolkit PowerShell snapin.
Copyright 2011 PowerShell.com. All rights reserved.