Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

Linked clones and DatastoreCluster

$
0
0

Hi

I am trying to create new VMs based on a snapshot using the New-VM command.

My "base" image is stored on a dedicated datastore for "base" images, let's call it "template"

I have a Datastore Cluster of several "vms" datastores but it does not include "template".

When I run the command to create the linked clone from "source" and store it into the datastore Cluster :

New-VM -Name toto -vm source -linkedClone -ReferenceSnapshot (Get-Snapshot -vm source -Name Base) -Datastore (Get-DatastoreCluster DataStore4VMs) -ResourcePool (Get-ResourcePool "POOL") -Location (Get-Folder Data)

I have the following error saying The Storage DRS requirements of this VirtualMachine cannot be satisfied. storagePlacement The datastore is not compatible with the virtual machine.

Whereas it works if I add "template" datastore into the Datastore Cluster and it also works if I set the VM Datastore instead of DataStoreCluster directly.

 

Is there any restrictions on the command ? Or has anyone been able to do that ?

Thanks all for your help


scp with powershell - set file permissions

$
0
0

Hello guys,

I have a script for Putty who sending everyday some report from a Win directory to Linux server with scp

 

Not sure if I can manage directly with this script, I would like to set some permissions on files before I sent,

 

The Linux directory have some restrictions, directory 775 (drwxrwxr-x)  but file became from Win server with  (640 -rw-r-----)

 

This is script:

 

$file = Get-ChildItem -Path C:\temp\smart_backup\*.csv |

 

 

 

  Sort-Object -Property LastWriteTime -Descending |

 

 

  select -First 1 -ExpandProperty FullName

 

 

 

 

$sProc = @{

 

 

  FilePath = 'C:\Program Files (x86)\PuTTY\pscp.exe'

 

 

  ArgumentList = "-scp -pw ******* $file smart@1.1.1.1:/data/smart/invoicing/"

 

 

}

 

 

Start-Process @sProc

 

Any suggestion or I should find a way in Linux server directly?

 

Thanks

VMware tools upgrade with no-reboot

$
0
0

Hi All,

 

Can we do VMware tools upgrade for a specific list of VM's without re-boot through power cli automation? Since we are finding a difficult time to get downtime from customer.

 

E.g. C:\Temp\vmlist

 

Get-VM cwv-gasmngr1 | Update-Tools –NoReboot -RunAsync

 

 

thanks

vmk

check ESXI hardware using PowerCLi

$
0
0

i am planning to Pull a report about the current ESXI HARDWARE status in my enviorment using powercli.

HBA/NICs/MEMORY etc

 

How do i accomplish this task ? any guidance ?

Get VMs with Tag Like and export csv just vm name

$
0
0

Hi,

 

I would like to export in csc the list of my vm who have a specific tag.

i can do that but the powercli command extract the vm with all properties,

so i would like just the name of my vms.

i 'm blocked with this powercli command :

Get-VM|where {(Get-TagAssignment-Entity$_|Select-ExpandPropertyTag) -like'tag-1*'} | Export-CSV C:\Scripts\result\vms-tag-1.csv

 

thank you for your help.

Get List of VMs, Datastores and Folder name per Cluster

$
0
0


Hello!!  I'm hoping someone can assist me with a PowerCLI script that can pull the subject info into a txt or csv file.  In an effort to get our environment cleaned up before our next DR exercise with SRM, I want to get a list that shows each VM, the datastore(s) it resides on, and the Folder name within VMs and Templates view.  We keep our VMs organized by creating folder names that correspond to the app running on the VM.  I mention SRM because last year our Protected Groups matched the Rcopy groups from our 3PAR array.  However, we've added over 200 new VMs since that time and my team members basically placed these new VMs on the first available datastore that had enough free space.  Unfortunately, we're not utilizing Storage Profiles...it's scheduled for next year.

 

The extracted info would look similiar to the following:

 

Servername    Datastore   Folder Name

Server1            LUN0           ActiveDirectory

Server2            LUN0           ActiveDirectory

Server3            LUN1           ActiveDirectory

Server4            LUN3           Argo

Server5            LUN7           Argo

Server6            LUN6           Lockbox

Server7            LUN5           Lockbox

Server8            LUN9           Citrix

etc...

 

Any help with extracting this info from vCenter would be greatly appreciated.

 

Thanks,

Charles

Sen notification Mail

$
0
0

hi guys I have the following scrip I want that after the sentence "ELSE" is sent a notification email as I can do it?

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------

##Sentencia para verificacion de conexion a VM origen

while($TRUE){

if (Test-Connection -ComputerName $VMIP -Delay 1 -quiet){

    Write-Host "$VMIP is up" -ForegroundColor Green

  }

  else{

Write-Host "$VMIP is down" -ForegroundColor Green

##Coneccion a vCenter

connect-viserver -server $vcenter_server -User $vcenter_user -Password $vcenter_pwd

#Nombre de la VM Origen

$VMorigen= "SRV-SIPSERVER"

#Nombre de la ultima VM clonada

$VMclone= "$($VMorigen)-$((Get-Date).ToString('MMddyyyy'))"

Get-VM -Name SRV-SIPSERVER | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$false -Confirm:$false

GET-VM -Name $VMclone | Start-VM -Confirm:$False

##Desconnexion de vCenter

Disconnect-VIServer -Confirm:$false

##Para sentencia en caso de no tener conexion

break

}

}

Import vCenter Permissions via XML

$
0
0

I am looking at Alan and LucD's import script for permissions in vCenter. I've used it in the past with no issues. I have been attempting to import permissions into my 6.7 vCenter, and have been receiving the following error:

 

Get-View : Cannot validate argument on parameter 'ViewType'. Accepted types: ClusterComputeResource, ComputeResource, Datacenter, Datastore,

DistributedVirtualPortgroup, DistributedVirtualSwitch, Folder, HostSystem, Network, OpaqueNetwork, ResourcePool, StoragePod, VirtualApp, VirtualMachine,

VmwareDistributedVirtualSwitch

At C:\vCenter_Permissions.ps1:231 char:34

+     $entity = Get-View -ViewType $_.EntityType -Filter @{"Name"=("^"  ...

+                                  ~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

 

Which corresponds to this line: $entity = Get-View -ViewType $_.EntityType -Filter @{"Name"=("^" + $EntityName + "$")}


Powercli Script for Getting VMHost Groups and VMHost Group Members

$
0
0

Hi All

 

Is there a way to get the VMhost Group and All vm's in a VMHostGroup using Powercli?

Also, I would like to add multiple VM's to different VMhost Groups. Is it possible via POwercli?

 

Thank you all

Sunny

PowerCLI Script to get only Datastore Cluster Summary

$
0
0

Hi,

 

I would like to get the report via email for only Datastore Cluster summary report like Datastores cluster Name| Total Capacity| Used Space| Free% | .

Datastores cluster Name | Total Capacity | Used Space  | Free%|

 

I tried below script but it is providing all Datastores Space report, i need only DS cluster Summary

 

$report = foreach($vc in $global:DefaultVIServers){

 

 

    Get-Datastore -Server $vc |

 

 

    where {($_.FreeSpaceGB/$_.CapacityGB) -le 0.15} |

 

 

    Select @{N='vCenter';E={$vc.Name}},

 

 

        @{N='Datacenter';E={$_.Datacenter.Name}},

 

 

        @{N='DSC';E={Get-DatastoreCluster -Datastore $_ -Server $vc | Select -ExpandProperty Name}},

 

 

        Name,CapacityGB,

 

 

        @{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},

 

 

        @{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}},

 

 

        @{N='ProvisionedSpaceGB';E={

 

 

        [math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)}},

 

 

        @{N='UnCommittedGB';E={[math]::Round($_.ExtensionData.Summary.Uncommitted/1GB,2)}},

 

 

        @{N='VM';E={$_.ExtensionData.VM.Count}}

 

 

}

$report | Export-Csv report.csv -NoTypeInformation -UseCulture

 

Thanks

Ranjith

change mac address from manual to automatic and remove cloud.uuid in vm advanced setting

$
0
0

I have a set of vms in a csv file which I am trying to modify vm advanced settings and unregister and register back as new name in different resource pool but i am failing to remove cloud.uuid and make the network adapter mac as automatic while reconfigvm ($registernewvravm.ExtensionData.ReconfigVM($vmConfigSpec))

$csvimportvms=Import-Csv -Path C:\Users\vk185112\Desktop\vinvappvcloudvms.csv
foreach($vcloudvmscsv in  $csvimportvms){
$registernewvravm= Get-VM $vcloudvmscsv.OldVMName
$nicName= Get-NetworkAdapter -VM $registernewvravm
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec 
$vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
$vmConfigSpec.extraconfig[0].Key="cloud.uuid" 
$vmConfigSpec.extraconfig[0].Value=$null
$dev.operation = "edit" 
$registernewvravm.ExtensionData.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq $nicName.Name} | %{
 $dev.device = $_        if($dev.device.addressType -eq "manual"){       $dev.device.addressType= 'assigned'        $dev.Device.MacAddress = $null          }        }
$vmConfigSpec.DeviceChange += $dev
$registernewvravm.ExtensionData.ReconfigVM($vmConfigSpec)
Remove-VM -VM $registernewvravm.name -DeleteFromDisk:$false -Confirm:$false -RunAsync
$newVM = New-VM -VMFilePath $registernewvravm.ExtensionData.Config.Files.VmPathName -ResourcePool $vcloudvmscsv.NewResourcePool -Name $vcloudvmscsv.NewVMName
Start-VM -vm $newVM 
Get-VMQuestion -vm $newVM | Set-VMQuestion -Option "button.uuid.movedTheVM" -Confirm:$false 

}

 

error:

 

csv file

Bulk vms rename

$
0
0

I am trying to rename multiple virtualmachines(Poweredoff) in a cluster by unregistering and reregistering with a new name  but in order to change vmx,vmdk,any snapshot file and vmfoldername to the newly changed name (vsphere display) I need to do storage vmotion.

Here are the few challenges while this activity:

1. Bulk migrations to different luns taking time.

2.Low storage space. (If the vm size is more then the free space available in other datastores I need to spread vmdks across multiple datastores.

 

Is there any better way to perform this activity please suggest.

My thought is like (get the virtual machine folder before unregistering the vm and keep that in a variable and rename all the vm related files to newname along with the folder and register back to the cluster)

Unable to Set IPAddress of a Static Nic Mapping in Customization Spec

$
0
0

I am trying to set the IPAddress of an existing Nic Mapping in Customization Spec using below command, but it is throwing error.

Command

Get-OSCustomizationSpec ClientSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpAddress 10.10.0.6

Existing NIC Mapping

C:\Users\administrator> Get-OSCustomizationSpec ClientSpec | Get-OSCustomizationNicMapping | select *

Dns                   : {192.168.50.90}

Wins                  : 

SpecId                : 718ebb47-31d3-4ba0-b11f-96c1af797cde

Spec                  : ClientSpec

SpecType              : NonPersistent

NetworkAdapterMac     : 

Position              : 1

IPMode                : UseStaticIP

IPAddress             : 10.10.0.5

SubnetMask            : 255.255.255.0

DefaultGateway        : 10.10.0.1

AlternateGateway      : 10.10.0.1

VCApplicationArgument : 

Id                    : /Local=/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-ClientSpec-NonPersistent-1/

Uid                   : /Local=/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-ClientSpec-NonPersistent-1/

ExtensionData         : VMware.Vim.CustomizationAdapterMapping

Client                : 

Version               : 1

 

Error:

Set-OSCustomizationNicMapping : 2/14/2019 2:45:03 PM    Set-OSCustomizationNicMapping        If the IpMode parameter is set to "UseDhcp" you must not specify the parameters that configure values loaded by the DHCP server.    

At line:1 char:70

+ Get-OSCustomizationSpec ClientSpec | Get-OSCustomizationNicMapping | Set-OSCusto ...

+                                                                      ~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Set-OSCustomizationNicMapping], ViError

    + FullyQualifiedErrorId : Core_NicMappingCmdletBase_ValidateParameters_DhcpConflictingParameters,VMware.VimAutomation.ViCore.Cmdlets.Commands. 

   SetOSCustomizationNicMapping

C:\Users\administrator.SA> Get-OSCustomizationSpec ClientSpec | Get-OSCustomizationNicMapping | select *
 
 
Dns                   : {192.168.50.90}
Wins                  : 
SpecId                : 718ebb47-31d3-4ba0-b11f-96c1af797cde
Spec                  : ClientSpec
SpecType              : NonPersistent
NetworkAdapterMac     : 
Position              : 1
IPMode                : UseStaticIP
IPAddress             : 10.10.0.5
SubnetMask            : 255.255.255.0
DefaultGateway        : 10.10.0.1
AlternateGateway      : 10.10.0.1
VCApplicationArgument : 
Id                    : /Local=/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-ClientSpec-NonPersistent-1/
Uid                   : /Local=/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-ClientSpec-NonPersistent-1/
ExtensionData         : VMware.Vim.CustomizationAdapterMapping
Client                : 
Version               : 1

PowerCLI to show Guest VM disk space capacity not working ?

$
0
0

Hi,

 

Can anyone here please assist me in fixing the script that was created by LucD a few years ago to show the actual Guest OS disk space usage?

 

$report = @()
foreach($vm in Get-VM){    Get-HardDisk -VM $vm | ForEach-Object {        $HardDisk = $_        $row = "" | Select Hostname, VM, GuestName, Datastore, VMXpath, HardDisk, DiskType, CapacityGB, DiskFreespace, TotalVMFSConsumed, ProvisionType                    $row.Hostname = $vm.VMHost.Name                    $row.VM = $VM.Name                    $row.GuestName = $vm.Guest.HostName                    $row.Datastore = $HardDisk.Filename.Split("]")[0].TrimStart("[")                    $row.VMXpath = $HardDisk.FileName                    $row.HardDisk = $HardDisk.Name                    $row.CapacityGB = ("{0:f1}" -f ($HardDisk.CapacityKB/1MB))
$row.DiskFreespace = $row.CapacityGB - ($_.Guest.Disks | Measure-Object FreeSpaceGB -Sum | Select -ExpandProperty Sum)
$row.DiskType = $HardDisk.get_DiskType()
$row.TotalVMFSConsumed = $vm.get_UsedSpaceGB()
$row.ProvisionType = $HardDisk.StorageFormat                    $report += $row  }
}
$report | Export-Csv -Path C:\VMDisk-CapacityReport.csv -NoTypeInformation -UseCulture

 

The Line #13 is somehow not showing the actual guest disk space consumption correctly.

 

Thanks in advance.

PowerCLI VM Disk Usage

$
0
0

I have this script that I borrowed from another post.   I would like to add what Cluster the VMs reside in as well....Having a hard time since I'm fairly new to this

 

$report = @() 

foreach($vm in Get-VM){ 

    Get-HardDisk -VM $vm | ForEach-Object { 

        $HardDisk = $_ 

        $row = "" | Select Hostname, VM, GuestName, Datastore, VMXpath, HardDisk, DiskType, CapacityGB, DiskFreespace, TotalVMFSConsumed, ProvisionType 

                    $row.Hostname = $vm.VMHost.Name 

                    $row.VM = $VM.Name 

                    $row.GuestName = $vm.Guest.HostName 

                    $row.Datastore = $HardDisk.Filename.Split("]")[0].TrimStart("[") 

                    $row.VMXpath = $HardDisk.FileName 

                    $row.HardDisk = $HardDisk.Name 

                    $row.CapacityGB = ("{0:f1}" -f ($HardDisk.CapacityKB/1MB)) 

            $row.DiskFreespace = $vm.Guest.Disks | Measure-Object FreeSpaceGB -Sum | Select -ExpandProperty Sum 

$row.DiskType = $HardDisk.get_DiskType() 

$row.TotalVMFSConsumed = $vm.get_UsedSpaceGB() 

$row.ProvisionType = $HardDisk.StorageFormat 

                    $report += $row 

  } 

$report | Export-Csv -Path C:\VMDisk-CapacityReport.csv -NoTypeInformation -UseCulture 

 

Thank you all very much for your assistance


show parent object from get-view -ViewType HostSystem

$
0
0

I would like to modify the code snippet below (http://kb.vmware.com/kb/1012514) to include the parent object.

 

get-view -ViewType HostSystem -Property Name, Config.Product | select Name,{$_.Config.Product.FullName},{$_.Config.Product.Build} | ft -auto

 

When I run the modified version I get "ComputeResource-domain-sNNNN" or "ClusterComputeResource-domain-cNNN" in the Parent column. If I do a

 

Get-Cluster ClusterComputeResource-domain-cNNN

 

I get the name of one of our clusters. So I tried variations of the following and I still can't get a proper Parent name.

 

PowerCLI C:\> get-view -ViewType HostSystem -Property Name, Config.Product, Parent | select Name,{$_.Config.Product.FullName},{$_.Config.Product.Build}, ( $_.Parent | get-cluster  ) | sort -property name | ft -auto

select : Cannot convert System.Object[] to one of the following types {System.String, System.Management.Automation.ScriptBlock}.

At line:1 char:72

+ get-view -ViewType HostSystem -Property Name, Config.Product, Parent | select Na ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException

    + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand

PowerCLI C:\>

 

I realize that it doesn't help that in some cases Parent will be a cluster object and other cases it will be a Folder or Data Center object. I have also tried

 

.... $( if ( $_.Parent) {get-cluster -id $_.Parent} )

.... ( if ( $_.Parent) {get-cluster -id $_.Parent} )

.... ( get-cluster -name ($_.Parent).Name )

.... ( get-cluster -name [string]($_.Parent).Name )

 

 

1) If I only care about hosts with cluster parents, is there a way to ignore all others?

2) How do I get the name of the parent cluster?

Using Get-EsxTop to get NetWorld CPU

$
0
0

Hi All,

 

Currently I use ESXTOP via ssh and use the expand function using the GID of a VM the get the individual worlds that make up a VM, I'm interested is capturing the %USED CPU of the 4 NetWorld processed as this VM has 4 NICs

 

I'd like to know if I could use Get-EsxTop to capture CPU %USED on the NetWorld of a VM?

VMnic details of VDSwicth

$
0
0

Hi,

 

I would like to find out the vmnics connected to a distributed vswitch using powercli.

 

Please help.

Upgraded from PowerCLI 6.5 to 11.1 and now getting prompted for credentials

$
0
0

I uninstalled my old PowerCLI 6.5, rebooted then installed 11.1 as described in below link by running powershell "Run as administrator"...

PowerShell Gallery | VMware.PowerCLI 11.1.0.11289667

 

Now every time I do a Connect-VIServer I get prompted for credentials aka no passthrough authentication.....

NOTE: I do not have any cached credentials.

Here are the my versions of powershell and powercli....

 

PS C:\Windows\system32> $PSVersionTable

 

Name                           Value                                                                                                                                                                              

----                           -----                                                                                                                                                                              

PSVersion                      5.1.14393.1944                                                                                                                                                                     

PSEdition                      Desktop                                                                                                                                                                            

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                            

BuildVersion                   10.0.14393.1944                                                                                                                                                                    

CLRVersion                     4.0.30319.42000                                                                                                                                                                    

WSManStackVersion              3.0                                                                                                                                                                                

PSRemotingProtocolVersion      2.3                                                                                                                                                                                

SerializationVersion           1.1.0.1                                                                                                                                                                            

 

 

PS C:\Windows\system32> get-module -name VMware*

 

ModuleType Version    Name                                ExportedCommands                                                                                                                                        

---------- -------    ----                                ----------------                                                                                                                                        

Script     6.7.0.1... VMware.Vim                                                                                                                                                                                  

Script     11.0.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}                                                                                               

Script     11.0.0.... VMware.VimAutomation.Common                                                                                                                                                                 

Script     11.0.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...}                                                    

Script     11.0.0.... VMware.VimAutomation.Sdk            {Get-ErrorReport, Get-InstallPath, Get-PSVersion}                                                                                                       

 

 

 

Anyone know the fix?

Get VM Generation ID from powershell

$
0
0

I need to monitor a vm for id changes that can break a license server for a software call tableau we use. I am already checking the uuid and mac address, but they say they also look at the VM-generation id,in the vmx file its vm.genid I believe

 

 

does anyone know what property this is.

Viewing all 14549 articles
Browse latest View live


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