Difference between revisions of "Script Extracts and Examples (PowerCLI)"

Jump to navigation Jump to search
m
→‎Getting Started: Added Syntax Highlighting
m (→‎Performance Stats: Added intro and "Available Metrics")
m (→‎Getting Started: Added Syntax Highlighting)
Line 6: Line 6:


On the first run you need to allow the Toolkit to run properly by running (you need to run this command as an administrator, so if you're using Windows 7, for example, you'll need to start the Powershell console as an administrator, regardless of whether you're currently logged in as an admin)...
On the first run you need to allow the Toolkit to run properly by running (you need to run this command as an administrator, so if you're using Windows 7, for example, you'll need to start the Powershell console as an administrator, regardless of whether you're currently logged in as an admin)...
Set-ExecutionPolicy RemoteSigned
<source lang="powershell"> Set-ExecutionPolicy RemoteSigned </source>


Connect to the Virtual Centre (or ESX) server using the following command using your normal username and password (same as you'd use to log into the VI Client).  You will need access to the servers on TCP 443.
Connect to the Virtual Centre (or ESX) server using the following command using your normal username and password (same as you'd use to log into the VI Client).  You will need access to the servers on TCP 443.
Connect-VIServer -Server <server> -User <user> -Password <pass>
<source lang="powershell"> Connect-VIServer -Server <server> -User <user> -Password <pass> </source>


Once connected you can do real work with the PowerCLI, to see what's available, login to https://server/mob.  This is effectively where you end up once you've completed the <code> Connect-VIServer </code> command.
Once connected you can do real work with the PowerCLI, to see what's available, login to https://server/mob.  This is effectively where you end up once you've completed the <source lang="powershell"> Connect-VIServer </source> command.


Be aware that PowerShell commands generally return objects, rather than text, and that the textual representation of the return object is often abbreviated for simplicity.  To see the entire return for a command, pipe the result into <code>Format-List</code>.  To complicate matters further, some return objects contain further objects, see examples below
Be aware that PowerShell commands generally return objects, rather than text, and that the textual representation of the return object is often abbreviated for simplicity.  To see the entire return for a command, pipe the result into <source lang="powershell">Format-List</source>.  To complicate matters further, some return objects contain further objects, see examples below


<pre>
<source lang="powershell">
[vSphere PowerCLI] E:\> get-vm -name "winstg"
[vSphere PowerCLI] E:\> get-vm -name "winstg"


Line 90: Line 90:
Id              : VirtualMachine-vm-697/4002
Id              : VirtualMachine-vm-697/4002
Name            : Network Adapter 3
Name            : Network Adapter 3
</pre>
</source>


== Useful CmdLets etc ==
== Useful CmdLets etc ==

Navigation menu