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

Can MOVE-VM validate resources on destination prior to move?

$
0
0

Want to migrate a bunch of VMs to specific hosts in cluster.   All VMs in cluster use full memory reservations.   Consequently if I migrate VMs using MOVE-VM  I end up with some vMotions failing due to lack of resources on destination (the destination will eventually have enough room for VMs,  but due to order of migrations may not have enough at time move attempted). 

Just ordering VMs by desitnation host with least memory wont work as the host with the least memory could have VMs that are in to be migration list as well,  causing a temporary lack of resources.

Is there any way to have MOVE-VM prevalidate the move?   I was hoping the -whatif argument could do this,  it doesnt appear it can?

Thanks.


Can we pull VMware tools version and VM's HW version for specific lists of VMs ?

$
0
0

Hello Everyone,

 

Can we pull the VMware tools version and VM's HW version for the specific lists of VMs into CSV ? E.g. C:\Temp\vmliste.txt

I want to ensure that we are upgrading the VM's having older version of tools & HW

 

Thanks

vmk

List all IP addresses in new line

$
0
0

Hi,

 

Please help to get the list of all the IP Address in new or different lines

 

Get-VM db1 | Select @{N='VM Name';E={$_.Name}}, @{N="IP Address";E={[string]::Join(',',$_.guest.IPAddress)}}

 

Current Output

 

VM Name                                                                                             IP Address
-------                                                                                             ----------
db1                                                                                                 169.254.1.40,192.168.2.99

 

 

I would like to get output as below

 

VM Name                          IP Address
-------                                ----------
db1                                   169.254.1.40

db1                                   192.168.2.99

 

Please help!!!!

How to retrieve group membership from PowerCLI?

$
0
0

It seems like a pretty simple thing to look for, I just want an export saying Group A has these members, Group B has these members, etc.

I haven't been able to figure it out, but I am just starting out with PowerCLI.

 

I can get a list of all users or all groups easily enough with Get-VIAccount, but I don't know how to view the relationship between them.

 

(edit) Just to clarify, this is without using any AD or LDAP. The local account database for Vcenter.

Get Active FC Path WWN of all datastores

$
0
0

Hello. I need to turn off one of the FC switch for maintenance. To turn off the switch smoothly, I want to set the manual path selection mode and switch all datastores to the second switch. I have a lot of datastores, so I wanted to create a csv file in which I could see invofrmation to be sure that I did not miss anything: For example:

Host         |Datastore|ActiveTarget192.168.1.2  | DS-01     |21:00:00:1b:32:8f:d0:a5 

Unfortunately, all that I found on the Internet and tried to do it myself is to get HBAName, Target and State. I dont know how to comapre HBAName like "vmhba1:C0:T4:L1" with Identifier of Datastore and convert this to Datastore Name in one csv file.

Please, halp :)

Export list of VMs with complete folder path

$
0
0

Hi all,

 

I´m not a scripter so I need your help for my environemnt - 1 vcenter 5 datacenters without templates.

I need an export in csv contains the BlueFolderPath, I found a lot of scripts using Get-Folder and Get-FolderPath (is not recognized as the name of a cmdlet) something like that but nothing is working.

 

example CSV:

AB
testvm1DATACENTER\Applications\Banking\external
testvm2DATACENTER\Applications\Banking
testvm3DATACENTER\
testvm4DATACENTER\Applications

 

I found a lot of scripts from LucD but I think I´m to stuipd to get it to fly.

 

Get the folderpath - LucD notes

Folder by Path - LucD notes

 

I hope someone can help me

 

Thanks a lot

Greetings

Shutdown VM & poweron will work or not

$
0
0

Hi Everyone,

 

Recently, i tested the script from LucD, but not sure if it will work on schedule time or not tomorrow because of recent error

Why every time its throwing an error for Name parameter.

 

 

$vmNames = Get-Content -Path C:\Temp\vmnames.txt

 

 

$vms = Get-VM -Name $vmNames |

 

 

    where{$_.PowerState -eq 'PoweredOn'}

 

 

    Shutdown-VMGuest -VM $vms -Confirm:$false

 

 

 

while((Get-VM -Name $vmNames).PowerState -contains 'PoweredOn'){

 

 

    sleep 5

 

 

}

 

 

$vms | Select Name |  Export-Csv C:\Temp\vm-powered-off.csv -NoTypeInformation -UseCulture

 

**************************************************************************

 

For Power on

$vmNames = Import-Csv -Path C:\Temp\vm-powered-off.csv  -UseCulture

 

 

 

 

 

Get-VM -Name $vmNames.Name |

 

 

 

 

 

Start-VM -Confirm:$false

Need help ith HA status and DRS automation level in CSV

$
0
0

hey.. i am trying to get the HA, DRS status and DRS automation level in powershell script.. I am able to get the total output but i  am also looking for conitional output if HAenabled is false and DRS automation level not set in CSV.. can someone please h


VMotion is failing and need to check whether the VM's having CD rom mounted or not from Power Cli

$
0
0

Hi Everyone,

 

One of the ESXi host entered  into maintenance mode and it stuck at 19% but check the VM's edit setting be uase the Tasks is running. Can we see or check from Power Cli if any CD rom mounted or the VM's in local storage?  If yes, can we umount the CD rom from power Cli ?

thanks in advance.

 

regards,

vmk

issue with HTML output

$
0
0

Hi,

 

I am having issues in getting the output in html format

 

Get-VM-Namedb1-PipelineVariablevm|

ForEach-Object-Process {

    $_.guest.IPAddress |

    Select @{N='VM Name';E={$vm.Name}},

        @{N="IP Address";E={$_}}

}

 

From the above output, I would like to declare variable for name and ip address and would like to get the output

 

When I use the below method, I am getting blank

 

$VMInfo = $null

$VMInfo += "<th><center>VM Name</th><th><center>IP Address</th>"

 

Get-VM-Namedb1-PipelineVariablevm|

ForEach-Object-Process {

    $_.guest.IPAddress |

    Select $name = @{N='VM Name';E={$vm.Name}},

        $IP = @{N="IP Address";E={$_}}

}

 

$VMInfo += "<th><center>$Name</th><th><center>$IP</th>"

 

I have already have a HTML report, I would like to get this added along.

 

Please help!!!

How to change OSFullName, GuestId, RunTimeGuestID using powercli

$
0
0

Good morning;

Noticed a conflict with some of our centos 7 vm's.  In vSphere the Guest OS Version value is "CentOS 7 (64-bit)".  The output from  Get-VMGuest -VM (Get-VM -Name fwapp090) | Select-Object *  reveals the following:

 

OSFullName        : CentOS 6 (64-bit)

IPAddress         : {172.18.17.199}

State             : Running

Disks             : {Capacity:10726932480, FreeSpace:8529903616, Path:/, Capacity:1063256064, FreeSpace:735440896, Path:/boot, Capacity:7358906368, FreeSpace:3399409664, Path:/var,

                    Capacity:8990490624, FreeSpace:8833933312, Path:/opt...}

HostName          : fwapp090

Nics              : {Network adapter 1:dvportgroup-67}

ScreenDimensions  : {Width=800, Height=600}

VmId              : VirtualMachine-vm-1029692

VM                : fwapp090

VmUid             : /VIServer=wvus\ndl@fwapp100:443/VirtualMachine=VirtualMachine-vm-1029692/

VmName            : fwapp090

Uid               : /VIServer=wvus\ndl@fwapp100:443/VirtualMachine=VirtualMachine-vm-1029692/VMGuest=/

GuestId           : centos6_64Guest

ConfiguredGuestId : centos7_64Guest

RuntimeGuestId    : centos6_64Guest

ToolsVersion      : 10.2.5

ExtensionData     : VMware.Vim.GuestInfo

GuestFamily       : linuxGuest

 

Is there a way  using powershell to set the OSFullName to equal the Guest OS Version value displayed in vsphere?   Would like to change the GuestId and RuntimeGuestid to centos7_64Guest.

 

Thank you for any and all input.

 

Norm

Can we installVMware tools for the VM's VMware tools not installed ?

$
0
0

Hello Everyone,

 

Can we install the VMware tools  from Power Cli for the VM's  VMware tools not installed  ?

 

regards,

vmk

how to clone a vm & set ipv6 use powercli?

$
0
0

how to clone a vm & set ipv6 use powercli?

I can clone a vm with POWERCLI using a Customization Specification to set IPv4 as the specified IP address? But I didn't find how to set up IPv6.

How can I export free space on a datastore and used space on a datastore in my script below - PowerCLi

$
0
0

How can I export free space on a datastore and used space on a datastore in my script below - PowerCLi

This line works to pull the datastore itself but I am not sure how to get the free space and used space on the datastore itself.

$VMInfo.Datastore = ($Datastores|where {$_.ID -match (($vmview.Datastore |Select-First1) |SelectValue).Value} |SelectName).Name

 

===============================================================================

"@

filterGet-FolderPath {

$_|Get-View|% {

$row=""|selectName,Path

$row.Name =$_.Name

$current=Get-View$_.Parent

# $path = $_.Name # Uncomment out this line if you do want the VM Name to appear at the end of the path

$path=""

do {

$parent=$current

if($parent.Name -ne"vm"){$path=$parent.Name +"\"+$path}

$current=Get-View$current.Parent

} while ($current.Parent -ne$null)

$row.Path =$path

$row

}

}

$VCServerName="spvcenter11.reyesholdings.com"

$VC=Connect-VIServer$VCServerName-userRH\-password

$VMFolder="RFS"

$ExportFilePath="C:\users\wkieca\desktop\True-Up2018\Export-spvcenter11.csv"

$Report= @()

$VMs=Get-VM

$Datastores=Get-Datastore|selectName,Id

$VMHosts=Get-VMHost|selectName,Parent

ForEach ($VMin$VMs) {

$VMView=$VM|Get-View

$VMInfo= {} |SelectVMName,Powerstate,OS,Folder,IPAddress,ToolsStatus,ToolsVersion,Host,Cluster,Datastore,NumCPU,MemMb,DiskGb,DiskFree,DiskUsed,BusinessUnit

$VMInfo.VMName =$vm.name

$VMInfo.Powerstate =$vm.Powerstate

$VMInfo.OS =$vm.Guest.OSFullName

$VMInfo.Folder = ($vm|Get-Folderpath).Path

$VMInfo.IPAddress =$vm.Guest.IPAddress[0]

$VMInfo.ToolsStatus =$VMView.Guest.ToolsStatus

$VMInfo.ToolsVersion =$VMView.Guest.ToolsVersion

$VMInfo.Host =$vm.VMHost.Name

$VMInfo.Cluster =$vm.host.Parent.Name

$VMInfo.Datastore = ($Datastores|where {$_.ID -match (($vmview.Datastore |Select-First1) |SelectValue).Value} |SelectName).Name

$VMInfo.NumCPU =$vm.NumCPU

$VMInfo.MemMb =[Math]::Round(($vm.MemoryMB),2)

$VMInfo.DiskGb =[Math]::Round((($vm.HardDisks |Measure-Object-PropertyCapacityKB-Sum).Sum *1KB/1GB),2)

$VMInfo.DiskFree =[Math]::Round((($vm.Guest.Disks |Measure-Object-PropertyFreeSpace-Sum).Sum /1GB),2)

$VMInfo.DiskUsed =$VMInfo.DiskGb -$VMInfo.DiskFree

$VMInfo.BusinessUnit =$vm.CustomFields.Item("Business Unit")

$Report+=$VMInfo

}

$Report=$Report|Sort-ObjectVMName

IF ($Report-ne"") { $report|Export-Csv$ExportFilePath-NoTypeInformation

} $VC=Disconnect-VIServer-Confirm:$False

PowerCLI bug: Set-HardDisk -Controller: Crashes vCenter web services/SDK

$
0
0

Hello All,

 

I have recently started a fork of vDeployhttps://github.com/jdmu/vDeploy to update, bug fix, and use in my 6.7 environment.

 

There is a weird issue that seems to be causing my VM deployments to fail. I have added a few checks and bug fixes along the way to help in my troubleshooting.

 

There is a section of code that we run, and (it seems) that every other time it runs, it will crash the vCenter web services.

 

At first I thought that this was a vSAN issue, but I was able to reproduce on a local SSD datastore as well.

 

 

 

The issue is pinpointed to an area where we are creating new hard disks, and adding them to SCSI controllers.

 

The command runs, and does actually work, but the vCenter crashes.

 

After running :

 

service-control --start --all

 

The VM will have the new SCSI controller set.

 

Here is a section of code that can reproduce the issue:

 

Connect-VIServer

$vmName = 'SomeVMWith3Disks'

$Drive2Controller = '2'

$DISK2CONTROLLER = "SCSI Controller " + $Drive2Controller

$CONTROLLER = Get-ScsiController -Name $DISK2CONTROLLER -VM $VMNAME

Get-HardDisk -VM $VMNAME -Name "Hard disk 3" | Set-HardDisk -Controller $CONTROLLER -Confirm:$false

 

 

Sometimes it will work, sometimes it will cause a vCenter crash(about every other run) with the following error:

 

Set-HardDisk : 1/2/2019 09:06:11        Set-HardDisk            The HTTP service located at https://vcsaprd01.sky.net/sdk is unavailable. This could be because the service is too busy or because no endpoint was

found listening at the specified address. Please ensure that the address is correct and try accessing the service again later.

At E:\ServiceNowScripts\vCenterCrash.ps1:9 char:48

+ ...  "Hard disk 3" | Set-HardDisk -Controller $CONTROLLER -Confirm:$false

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

   + CategoryInfo          : NotSpecified: (:) [Set-HardDisk], ViError

   + FullyQualifiedErrorId : Client20_VirtualDeviceServiceImpl_UpdateAttachedVirtualHardDisk_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetHardDisk

 

 

 

vpxd.log for the event, some data may be unrelated, but happened at the same time:

 

 

2019-01-02T09:54:39.830-05:00 info vpxd[48000] [Originator@6876 sub=vpxLro opID=fb9e608] [VpxLRO] -- BEGIN task-17357 -- vm-1201 -- vim.VirtualMachine.reconfigure -- 52b009aa-b242-e324-2f85-cae1a0d6517e(526fb5d5-734c-0266-7958-813173d0e4fd)
2019-01-02T09:54:39.832-05:00 info vpxd[48000] [Originator@6876 sub=vpxLro opID=fb9e608-01] [VpxLRO] -- BEGIN lro-7215 -- -- VmprovWorkflow --
2019-01-02T09:54:39.836-05:00 info vpxd[48000] [Originator@6876 sub=pbm opID=fb9e608-01] No datastore for disk 2016 in config, filePath ds:///vmfs/volumes/vsan:52b4a5edf6f507ea-e1310d9c2d71dea6/a0012c5c-ab02-aacd-79dc-40f2e9af7b10/uhsush_2.vmdk
2019-01-02T09:54:40.326-05:00 info vpxd[47597] [Originator@6876 sub=Vsan opID=fb9e608-01-36bb5a51] [CheckDatastoreCapacity] Clearing DatastoreNoCapacity configIssue
2019-01-02T09:54:40.327-05:00 info vpxd[47656] [Originator@6876 sub=vpxLro opID=fb9e608-01-36bb5a51-01] [VpxLRO] -- BEGIN lro-7217 --  -- VsanClusterConfigIssuesLRO --
2019-01-02T09:54:40.327-05:00 info vpxd[47656] [Originator@6876 sub=Vsan opID=fb9e608-01-36bb5a51-01] [VsanClusterConfigIssueLRO] Clear CFG_ISS_VSAN_CLUSTER_NOSTORAGE configIssue for cluster vim.ClusterComputeResource:domain-c22
2019-01-02T09:54:40.327-05:00 info vpxd[47656] [Originator@6876 sub=vpxLro opID=fb9e608-01-36bb5a51-01] [VpxLRO] -- FINISH lro-7217
2019-01-02T09:54:40.373-05:00 info vpxd[48000] [Originator@6876 sub=Default opID=fb9e608-01] Creating SSL Contexts
2019-01-02T09:54:40.407-05:00 info vpxd[48000] [Originator@6876 sub=vpxCrypt opID=fb9e608-01] Failed to read X509 cert; err: 151441516
2019-01-02T09:54:40.407-05:00 info vpxd[48000] [Originator@6876 sub=pbm opID=fb9e608-01] ProfileManager max connections are 32
2019-01-02T09:54:40.448-05:00 error vpxd[47647] [Originator@6876 sub=vmomi.soapStub[29]] initial service state request failed, disabling pings. error=HTTP Status:500 'Internal Server Error'
2019-01-02T09:54:40.448-05:00 warning vpxd[47647] [Originator@6876 sub=Default] Closing Response processing in unexpected state: 3
2019-01-02T09:54:40.556-05:00 info vpxd[47670] [Originator@6876 sub=vpxLro opID=opId-d9dee-210621-6f] [VpxLRO] -- BEGIN lro-7219 -- session[5219f706-b0a8-a42f-ee32-d144187b3e5c]529ed1cf-d243-77a3-0c64-0c189061dad5 -- vim.event.EventHistoryCollector.readNext -- 5219f706-b0a8-a42f-ee32-d144187b3e5c(52b53296-c232-120d-1229-f8c4842d9dee)

 

 

 

Message was edited by: jdmu - Fixed formatting


Can we get the lists of Recently added VM's ?

$
0
0

Hello Everyone,

 

Can we get the lists of recently added VM's to VC or environment on a weekly basis or daily basis from power cli?

 

thanks

vmk

Script stopped with VM question in VC while detaching CD/DVD from VMs

$
0
0

Hi,


I have a script to detach CD/DVD for all VMs running on the specified datastore and print the result if successful or not.

My problem is for one of the VM, the script paused and I have the following "Virtual Machine Message" in vCenter:

 

"The guest operating system has locked the CD-ROM door and is probably using the CD-ROM, which can prevent the guest from recognizing media changes. If possible, eject the CD-ROM from inside the guest before disconnecting. Disconnect anyway and override the lock?"

 

The answer could be yes or no but I have to click manually.

How can I insert in my script to continue the process by answering yes or no automatically?

 

 

function Detach-CD-DS{
param([string] $Datastore)
$VM = Get-VM -Datastore $Datastore | sort Name
Foreach ($_ in $VM)
     {
          if ($_ | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false -WarningAction:SilentlyContinue)
          {write-host "CD/DVD detach ok for VM:"$_.Name}
          else
          {
          write-host "CD/DVD detach failed for VM:"$_.Name
          }
     }
}

 

2013-03-27_14h16_11.png

 

The VM is a Cisco VSG VM and has a CD/DVD attached that is connected and that connect at power on  (ISO image is located on the VM folder).

 

My goal is to move all the VMs running on this datastore to another datastore and I would like to make sure no CD/DVD are attached to them.

 

I have noticed that when I move this particular Cisco VM to another datastore, the ISO image move at the same time. Not true for other VMs with Media attached to them (e.g. Windows VM with a Windows ISO image attached).

 

So what I would like is to detach CD/DVD from all VMs and if it's a Cisco VM, answer to the Virtual Machine Message in VC by yes or no for the script to continue.

 

Thank you for your help.

How to get ESXi host coredump partition?

$
0
0

Hi

 

I would like to get a xls or csv report that extract coredump partition, canonnical name and hostname of following list of host.

If no coredump active, it will show on the report not set or not configure.

 

Here's what I've started:

 

 

$Target = Get-Datacenter DCNAME | Get-VMHost | sort Name

Foreach ($vmhost in $Target) {

$esxcli = Get-EsxCli -VMhost $vmhost

#$esxcli.system.hostname.get()

$esxcli.system.coredump.partition.get()

}

Write-Host "Done" -ForegroundColor DarkGreen

 

This script only extract configured naa devices as coredump without hostname and validation.

DRS function from script

$
0
0

we dont have enterprise license to enable DRS in our cluster, however we are keep getting an error about imbalanced resource usage and manually we are balancing.

is there a way to do powercli to balance across the cluster?

Edit/update Notes in VM

$
0
0

Hello, I have list of virtual machine where I need to modify existing notes, I would like to edit this notes (same for all) with powershell from a file (txt) Thanks

Viewing all 16717 articles
Browse latest View live


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