How to run a powerCLI script?

Posted on 2011-05-06
Last Modified: 2012-06-27
I have this script that I got from a website:

Connect-VIServer -Server myserver -User root -Password apple777
$vm1 = Get-VM
for($i = 0;$i -lt $vm1.Count; $i++)
$Vmname = $vm1.SyncRoot[$i].Name
Write-output “VM name - $Vmname”
$VMhost = $vm1.SyncRoot[$i].Host.Name
Write-output “VM host - $VMhost”
$datastore = Get-Datastore -VM (Get-VM -Name $vm1.SyncRoot[$i].Name)
$VMdatastore = $datastore.Name
Write-output “VM datastore - $VMdatastore”
$vm2 = Get-VM -Name $vm1.SyncRoot[$i].Name |Get-View
$VMsize = $vm2.Summary.Storage.Committed
Write-output “VM size - $VMsize ”
Write-Output ############################

I name it Listing1.ps1

But I don't see how I run it on a machine with PowerCLI installed.

Question by:gateguard
    LVL 116

    Accepted Solution

    Get a local system command prompt, launch PowerShell and navigat to your script directory.

    then .\Listing1.ps1
    LVL 21

    Assisted Solution

    by:Luciano Patrão

    You need to run this in the PowerShell console, or with the PowerGui Editor

    You can use the PowerGui is a good solution.

    Here have some videos, and documentation how works

    Here is VMware documentation and Powershell

    To run in the in the console, just run the PowerShell Cli console.

    To run using the Editor, just right mouse click on the script(with ps1 extension) and open, Then you can run using the Gui editor

    Hope this can help.

    LVL 28

    Assisted Solution

    There should be a file association for .ps1 files to powershell so that you can just double click the file or issue a command "start scriptname.ps1"

    You will probably want to create a powershell profile to load up the extensions you want (VI Toolkit, AD, etc.) each time you run a script.
    LVL 28

    Expert Comment

    See for some info on setting up a profile
    LVL 116

    Expert Comment

    by:Andrew Hancock (VMware vExpert / EE MVE)
    just select start run cmd to get a command prompt

    change directory cd to your scripts directory

    type powershell


    Windows PowerShell
    Copyright (C) 2009 Microsoft Corporation. All rights reserved.

    PS C:\scripts> .\Listing.ps1

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    vSphere 4.1 includes a self-signed SSL certificate upon installation.  In some situations, especially in larger environments with an existing PKI infrastructure, you may need to replace this with a valid SSL certificate for your environment.  VMware…
    The original payload size or maximum transmission unit (MTU) of an ethernet frame is 1500 bytes. A jumbo frame has an ethernet frame size of 9000 bytes or over. Common Jumbo Frame sizes are 9000, 9216 bytes (example - HP switches). Enabling Jumb…
    Teach the user how to configure vSphere clusters to support the VMware FT feature Open vSphere Web Client: Verify vSphere HA is enabled: Verify netowrking for vMotion and FT Logging is in place or create it: Turn On FT for a virtual machine: Verify …
    Advanced tutorial on how to run the esxtop command to capture a batch file in csv format in order to export the file and use it for performance analysis. He demonstrates how to download the file using a vSphere web client (or vSphere client) and exp…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now