[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1202
  • Last Modified:

How to run a powerCLI script?

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.

0
gateguard
Asked:
gateguard
  • 2
  • 2
3 Solutions
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
Get a local system command prompt, launch PowerShell and navigat to your script directory.

then .\Listing1.ps1
0
 
Luciano PatrãoICT Senior Infraestructure Engineer Commented:
Hi

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

http://powergui.org/downloads.jspa

Here is VMware documentation and Powershell

http://www.vmware.com/support/developer/PowerCLI/index.html
http://blogs.vmware.com/vipowershell/
http://www.vmware.com/support/pubs/ps_pubs.html

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.

Jail
0
 
bgoeringCommented:
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.
0
 
bgoeringCommented:
See http://technet.microsoft.com/en-us/library/ee692764.aspx for some info on setting up a profile
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
just select start run cmd to get a command prompt

change directory cd to your scripts directory

type powershell

then

C:\scripts>powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\scripts> .\Listing.ps1
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now