Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all 16717 articles
Browse latest View live

Basic script help

$
0
0

Hi Everyone,

 

I've not used PowerCLi before (but have previous scripting knowledge).

 

I need to write a script that will tell me which VM's have disks which are thin provisioned. Can anyone help?

 

Thanks.

 

David


How do I convert a VirtualMachine object to a template?

$
0
0

Greetings,

 

I'm trying to set up a script that updates all our templated boxes to the newest patch versions by starting up the boxes, installing the appropriate patches, then converting them back to template. I'm aware of New-Template, but this appears to work by making a copy of the existing VM (along with unneeded disk activity), whereas the "Template->Convert to Template" option within the vSphere Client works for what I need, but is annoyingly manual.

 

Is there a scripting equivalent of the "rclick->Template->Convert to Template" functionality?

 

Thanks,

Me

Find unregistered virtual machines

$
0
0

 

Hi,

 

 

Does anyone know/have a way to find unregistered virtual machines?

 

 

Thanks in advance!

 

 

 

 

 

How do you add an existing rdm to a VM using New-HardDisk?

$
0
0

Hi,

 

   I'm running powercli 5.0.1 build 581491 and i'm trying to write a powercli script to:

 

1) create an RDM

2) assign that RDM to VM1

3) assign the same RDM to VM2

 

I'm able to create the RDM and assign it to VM1, but I'm unable to use "New-HardDisk" to assign it to VM2.  Using the following command i'm able to create the RDM and assign it to VM1.

 

     New-HardDisk -VM VM1 -DiskType RawVirtual -DeviceName /vmfs/devices/disks/naa.60000970000192603729533030353531

 

While trying to assign it to VM2, i'm doing the following:

 

     New-HardDisk -VM VM2 -DiskPath "[san-datastore:1] vm1/vm1_1.vmdk"

 

And i get the following error:

 

     New-HardDisk : 6/6/2012 2:13:19 PM    New-HardDisk        Incompatible device backing specified for device '0'.

 

What i realized is that if i create a regular vmdk file, then use the New-HardDisk using the "-DiskPath" option, then the command works ok.  So my question is, what's the command to add an existing RDM to a VM?

 

Thanks in advance.

Can you modify vmx files on multiple vms in a cluster to allow boot delay setting changes via RCLI or VI Toolkit?

$
0
0

Can you modify vmx files on multiple vms in a cluster to allow boot delay setting changes via RCLI or VI Toolkit? How?

 

SAs desire a boot delay of 10 seconds across virtual enterprise comprising of multiple VCs with multiple datacenters and clusters.

 

 

Known: we can modify .vmx file and add: bios.bootDelay = "10000" this adds a 10000 ms (10 seconds) delay at boot time

 

 

Known: we may have to re-register or some other mechanism to apply the change to boot settings on vms

 

 

Has anyone attempted to do an enterprise wide change to bootDelay on vms? Any help?

vCenter login clarification

$
0
0

Hi techies,

 

i have a doubt, can some one clarify me please, in my environment i have vCenter server, for domain account have some few clusters access, here my doubt is, i can connect to the vCenter server only when i  log in to my system with domain account it works well, but when i log in to any differnt account and try to connect vCenter server  with my user credentials it won't work any guess what would be the cause ?

Use https port for obtaining host firmware?

$
0
0

Hello. Been trying to figure out how to potentially redirect this request with no luck.

 

Im in an environment where I can't get tcp 80 open.  443 is though. Is there some way to tell get-vmhostfirmware to use port 443 instead of 80 to obtain the vmhost configuration?

 

if not what's some other alternatives to grab a copy of the host configuration?  I need to back these hosts up but they're being a highly restricted firewall with no real workstation access behind it.

How to pull VM's on a datastore

$
0
0

I am moving VM's (per datastore) to my new datastore cluster and as I free up a DS I delete it and create it new with VMFS5.  I have just emptied a datastore but when I run the following command it still shows two VM's on that DS even though when I browse the DS it is empty.

 

get-datastore -name "DS_NAME" | get-vm | ft Name

 

How can I see where/how/why these two VMs are showing on the DS when it seems to be empty and I am assuming PowerCLI is my best bet. Obviously I do not want to just delete the DS as that could casue an issue with those VMs.  When I look at the edit settings of each VM they show they are on a separate datastore and not the one I'm trying to delete.

 

Any help is appreciated

 

 

Thanks

 

 

Sean


Trying Get Folder Path for VM in VC...

$
0
0

So here is what I'm trying to do.  I've seen other posts relating to this, but they only seem to get the immediate parent path rather than the full path.  We've basically setup a tree structure like this:

 

DATA_Center\business_service\SLDC\VM (SLDC = Software Development Cycle)

 

 

 

We've set it up this way so it is easier for admins to find systems related to a particular business service.  When a SAN maintenance occurs, we like to inform the business service admins affected by the maintenance.  So we basically build a spreadsheet and find all the LUN's attached to that particular SAN, find the VM's, then lookup folder path the VM lies under to find what what business service is affected.  I've attached a photo of our VC folder setup as an example.

 

 

 

 

 

 

I was wondering if it was possible through powershell to get a VM's associated folder path like what I have above.  I'm able to grab all other information needed, except the folder path.  Here is what I have so far:

 

Get-VM  | % {Get-View $_.ID} |

select name,

@{ Name="Datastore";Expression={(Get-Datastore -VM $_.Name).Name}}

 

 

 

 

 

 

(All VMDK's for a server reside on the same datastore so I have no need to look for or list other datastores for a single VM)

 

 

 

I tried messing w/ the script in the below thread for folder pathing, but I can't seem to get what I'm looking for.

 

 

 

http://communities.vmware.com/thread/170864

vCPU and vRAM capacity in a Cluster

$
0
0

Hello LucD/other helpers,

 

 

I'm trying to prepare a script which gives me the following info in a table...

 

Cluster Name, No.of Hosts, No.of Hosts, Allocated vCPUs, Allocated vRAM, Remaining vCPUs, Remaining vRAM(GB)

 

I've tried using the Capacity Planning script from the vCheck script but  when I compare the output with CapIQ the results are different. Please help me with this as I've prepared most of my health check report and go stuck with this.

 

 

Regards,

VMSavvy

Reporting multipath policy

$
0
0

Hi,

I am using a script to get multipath policy for the hosts. What i just need is a way for it to send me the report once it is completed. The catch is it should report only about those datastores/hosts which are not compliant.

 

Example: (If we are checking for host which have a path policy set as round robin the report should have all those hosts which are againt this rule -fixed/mru)

 

$Hosts = Get-Cluster cluster-name | Get-VMHost| Sort Name

 

ForEach ($VMHost in $Hosts) {

  $ScsiLunsInfo = $VMHost | Get-ScsiLun -LunType disk
    ForEach ($ScsiLun in $ScsiLunsInfo) {
               $PathPolicy =  (Get-ScsiLun -CanonicalName $ScsiLun -VmHost $VMHost).MultipathPolicy

#The logic is required here to display all those hosts which have a path policy of fixed/mru. The CSV file format should have something like "PathPolicy

# of $ScsiLun on $VMHost is $PathPolicy"

               if ($PathPolicy -ne "RoundRobin") {

                         export-csv "C:\somefile.csv"

}}}

 

Thx,
A

Copy-DataStoreItem Query

$
0
0

Hi Guys,

 

Im looking to create a backup/copy of a VM that runs in our production location. The VM(and its files) will then be transferred to our DR location where it can be restarted in the event that the primary site becomes unavailable.  

 

I've had a quick look around and it appears that the best solution is to create a Powershell script that connects to VCenter using the VMware CLi and using the 'copy-datastoreitem' cmdlet copy the files to either the local machine on which the PS script is running or to an available UNC path. The files can then be transferred to the DR location and the VM manually registered with the VCenter running at the site to provide a failover service.

 

The question i have relates to the consistency of the image.

 

Do I need to 'switch off', 'quiesce' or 'snapshot' the VM's before I use the 'copy-datastoreitem' command? Are there any other considerations I need to be aware of? I've seen one article where the chap creates a snapshot before using the 'copy-datastoreitem' command and wasn't quite sure why he did that.

 

Any advice/helpful pointers would be appreciated.

 

Thank you.

 

 

Cossy 

Launch PowerCLI in powershell script

$
0
0

I am new to using PowerCLI.  The goal is to perform a soft shutdown to our VM's and hosts, using our UPS software.

 

I am trying to launch PowerCLI from a .bat that launches powershell using the following code:

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSC
"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c". \
"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""
"C:\Scripts\PowerOffAll.ps1"

 

The .bat, and .ps1 will be launched from a stand alone XP machine that monitors the UPS

 

The .bat launches powershell with PowerCLI, but will not execut any commands in the .ps1 file.  I can manually key in the commands that occurr in the .ps1 file or run the ps1 file directly from PowerCLI, but they will not execute in PowerCLI if called from the .bat file.

 

Any help would be greatly appreciated!

 

Ron

Get-Annotation and export to csv

$
0
0

I am trying to export the custom Annotation fields to a csv file with foreach and having trouble get it to work where I want.

 

1.     Is it possiible to export them with foreach or do I have to use foreach-object?

 

 

$vms = get-vm pt*
foreach ($vm in $vms){
    $vm = Get-View $vm.ID
    $nm = $vm.name
    $hn = $vm.guest.hostname
    $ip = $vm.guest.ipaddress
    $contact = get-vm $vms | Get-Annotation -CustomAttribute "System Contact"|select Value
    $vm | select `
    @{Name = "Name"; E={$nm}},`
    @{Name = "Contact"; E={$contact}},`
    @{Name = "Hostname"; E={$hn}},`
    @{Name = "IP"; E={$ip}}
}format-table -AutoSize -Wrap

 

2.     How can I get rid of the "{@{Value=" in the output??

 

Name                          Contact                       Hostname                      IP
----                          -------                       --------                      --
PT1                      {@{Value=abcd.Serverteam...     pt1.abcd.com              10.0.1.5
PT2                      {@{Value=abcd.Serverteam...     pt2.abcd.com              10.0.1.33

Export-Csv Multiple Files

$
0
0

It's been requested that we list all powered on VMs within a particular cluster for backup purposes.  I'm able to get that information into a single CSV file.  However the backup engineer would like a single file for each proxy server which would use this file to backup those list of VMs. 

 

Is there a simple way of doing this identical to this:

 

 

# Author: Rhys Campbell
# 2009-09-22
# Splitting up csv files
# Path to csv file. Must contain a sequential unique integer id column
$csvFile = "$Env:USERPROFILE\bigcsvFile.csv";
# Slit into how many files?
$split = 10;
# Get the csv file content
$content = Import-Csv $csvFile;
# So we start from Id = 1 in the csv file
$start = 1;
$end = 0;
# calc records per file
$records_per_file = [int][Math]::Ceiling($content.Count / $split);
for($i = 1; $i -le $split; $i++)
{
# Set the end value for selecting records
$end += $records_per_file;
# Need to cast to int or we get an alphabetic comparison when we want a numeric one
$content | Where-Object {[int]$_.Id -ge $start -and [int]$_.Id -le $end} | Export-Csv -Path "$Env:USERPROFILE\file$i.csv" -NoTypeInformation;
# Update start value for selecting records
$start = $end + 1;
}

 

Source Credit:  http://www.youdidwhatwithtsql.com/splitting-csv-files-with-powershell/374


Set-DistributedSwitchPortGroup - Only some settings applied

$
0
0

Hello,

I've noticed the following behaviour from the Set-DistributedSwitchPortGroup module by LucD, when the below command is issued to set the dvportgroup security, and the values for parameters -PromiscuousMode -MacAddressChanges and -ForgedTransmits are set to boolean False only the -PromiscuousMode setting is actually applied.

 

Set-DistributedSwitchPortGroup -Name $dvPortgroup.PG -PromiscuousMode ([bool]::Parse($dvPortgroup.PromiscuousMode)) -MacAddressChanges ([bool]::Parse($dvPortgroup.MACAddressChanges)) -ForgedTransmits ([bool]::Parse($dvPortgroup.ForgedTransmits)) -loadBalancing loadbalance_loadbased |out-null

 

If the command is broken up, and and for example -MacAddressChanges are applied separately as below, this works ok....


Set-DistributedSwitchPortGroup -Name $dvPortgroup.PG -MacAddressChanges ([bool]::Parse($dvPortgroup.MACAddressChanges)) | out-null

 

 

Regards

vKev

Copy-VMGuestFile creates superfluous folders

$
0
0

Hi all,

 

I have had PowerCLI in version 4.1 and I have upgraded it to 5.1 because of new amazing features.

 

In the 4.1 version I was copping files with following command:

Copy-VMGuestFile -LocalToGuest -Source "C:\powcli41.txt" -Destination "C:\Users\unittester\Desktop\powcli41.txt" -VM VMName -GuestUser domain\username -GuestPassword password -HostUser username -HostPassword password -force

and it was working perfect.

 

In the 5.0 and 5.1 versions on the VM I can see extra, unnecessary folder:

C:\Users\unittester\Desktop\powcli41.txt\powcli41.txt

instead of required

C:\Users\unittester\Desktop\powcli41.txt

 

Could You explain how to modify Copy-VMGuestFlie command to avoid getting superfluous powcli41.txt folder?

 

Regards,
Przemyslaw Sech

help on cold migrations to different datacenter, same vcenter

$
0
0

problem defined: trying to cold migrate vms from one datacenter to another datacenter within same vcenter - no matter what code i try to use, i get an error or "half baked" results - i.e. some vms cold migrate, others do not with an error

 

example001:

 

PowerCLI C:\> import-csv c:\maint.csv | %{ get-vm -name $_.ServerName -Location (get-datacenter "dtc001") | move-vm -Datastore (get-datastore -name "DATASTORE_008") -RunAsync -Confirm:$false }

 

maint.csv contents:

 

ServerName

SERVER001

 

error in vcenter:

 

"a specified parameter was not correct. datastore"

 

 

example002 - using Lucd's relocatevm method:

 

foreach($row in (Import-Csv c:\serverlistmigrate.csv -UseCulture)){

 

$vm = ''

$esx = ''

$spec = ''

$spec.datastore = ''

$spec.host = ''

$spec.resourcepool = ''

 

 

CLS

 

$vmname = $row.vmname

$vmhost = $row.vmhost

$datastore = $row.datastore

 

$vm = Get-VM -Name $vmname

 

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

  $spec.datastore = (Get-Datastore -Name $datastore).ExtensionData.MoRef

  $spec.pool = (Get-ResourcePool -Name $resourcepool).ExtensionData.MoRef

  $spec.host = (Get-VMHost -Name $vmhost).ExtensionData.MoRef

  $vmObj = Get-VM -Name $vmname | Get-View

  $vmObj.RelocateVM_Task($spec, "defaultPriority")

 

 

}

c:\serverlistmigrate.csv contents:

 

vmname,vmhost,resourcepool,datastore

"SERVER001,esxhost07,rpl01_High,DATASTORE_008

 

 

error in vcenter:

 

"a specified parameter was not correct. host"

 

 

**** USING above method, I will get some to migrate, but some fail with same error as above.

 

NEEDED:  All I want is to cold migrate multiple vms from one datacenter to another datacenter (different datastore)  within same vcenter with 100% success - I don't care what method is used - I just need solid, reliable, consistent success.

 

Many thanks in advance!!!!

 

 

 

NOTES - POWERCLI VERSION, etc.

 

 

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.1 Release 1 build 793510
---------------
Snapin Versions
---------------
   VMWare AutoDeploy PowerCLI Component 5.1 build 768137
   VMWare ImageBuilder PowerCLI Component 5.1 build 768137
   VMware License PowerCLI Component 5.1 build 669840
   VMware vSphere PowerCLI Component 5.1 build 793489

Script to check Cisco VEM version on ESXi Host

$
0
0

Hallo there,

 

I need help, a script to check and report to a cvs file the Cisco Nexus 1000v VEM version on all ESXi hosts connected to a vCenter.

 

basically, 'vem version -v' but for all the ESXi hosts connected to a vCenter.

 

 

Thanks

 

Joseph

ViError connecting to ESXi server from PowerCLI5.1

$
0
0

Hi, I have been unable to locate anything on searches that fits what im looking for.

I am hoping that this is such a basic and obvious question it will take very little effort to resolve, but apologies if this was documented anywhere.

 

I am using vSphere PowerCLI 5.1 Release 1 to try and connect to an ESXi server.

 

The server is not licensed and is running the free 60 day eval.

ESXi Version 4.1.0,800380

 

As I understand it, all the features should be enabled and the server in write mode for an API's?

 

The problem I have is simply connecting to the server.

 

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Connect-VIServer x.x.x.x

Connect-VIServer : 02/10/2012 14:11:36    Connect-VIServer        The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:17
+ Connect-VIServer <<<<  93.95.12.187
    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], ViError
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_WebException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

 

When using the connect command it pops up asking for credentials which I complete. I know these credentials are correct as they work when using the vSphere client to connect into the GUI.

I have tried the connection command with username and password to no avail.

 

The ESXi server is on the same network with the same gateway as my desktop client which is running Windows7 64bit.

 

Is the reason for the error simply a licensing one? I wanted to test a scripting VMGuest installation before purchasing licenses for the server, the free ESXi License code we have does not allow scripted connections, it operates in read only mode.

Does the standard Product Evaluation Mode allow for the PowerCLi connection?

 

If not then what sort of License would I need just to connect remotely to servers using PowerCLI for scripting installs and management please?

 

Thanks

Viewing all 16717 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>