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

Script to remove floppy drive from VM on next reboot

$
0
0

My environment has 1000s of VMs running with Floppy drive. Looking for the possibility of removing of these floppy drives on next reboot during any OS patching cycle.

 

Can we have some automation in place to configure in such way that should remove the floppy drives when VM get restart next time.


Consolidate Disks

$
0
0

I am looking for a CLI way to Consolidate Disks. Normally I would

Right-Click a VM-Snapshot-Consolidate

 

I have been looking around, but I cannot find a CLI way to do this. Does this exist?

VM Remote Console to a Desktop Pool

$
0
0

We have a floating desktop pool that people need console access. I've found out ways to connect to individual machines, but I'd like to set up a PowerCLI script that is able to check the pool to see which desktops are available to console. Below is the regular command to connect to the single VM.

 

Connect-VIServer <vCenter> -Force

Get-VM <Single VM> | Open-VMConsoleWindow

 

I've also seen scripts people have created to connect to lots of machines at once. I haven't seen anything out there that would recognize user sessions active for console access.

Read VM Config save in array and parse in new VM

$
0
0

Hello,

I have some VM as WTS Servers I need to make them new with the same parameters like

Vmware folder

ESX Host

Name VM

MAC-Adress

Name NFS Datastore

that needs to be stored an a array or something

then I have a template that have all the infomation stores that are the same all on servers

after vcenter deployed the template the need to put in the information/config from above delete the server and gets to the next one in the cluster

 

can someone help me with that please

foreach_loop_csvinput_powercli

$
0
0

hi Luc,

 

can you please suggest what is wrong in following .it used to work fine numerous times in past but for some reasons not today.

 

 

$vms_info=Import-Csv -Path "c:\users\user1\desktop\folder1\vmnames.csv"

$vms.count

 

foreach ($line in $vms_info)

{

 

$vma=get-vm $line.vmname

 

$vma|select name

 

}

 

iam getting folowing

 

Connect-VIServer Method not found: 'Void VMware.Vim.VimClient.set_UseSystemProxy

$
0
0

I am running powercli script  from .net application and this used to work in 6.5.1 but with latest version when i run powercli script from c# c.net i get this error:

Connect-VIServer                Method not found: 'Void VMware.Vim.VimClient.set_UseSystemProxy

If i run script from powershell console it works fine, just fail when runing hosted in .net.

Any idea what is wrong or has changed in 10.x?

Get-View vs. Get-VM for $_.guest.ipaddress

$
0
0

I am working on improving the current scripts we have for reporting on VMs across our vcenters. So I started working on replacing Get-VM with Get-View where I could. My Google Foo isn't as good as some so here is where I am stuck currently.

 

This command returns 18 IP address for the particular VM I am using to test against. (yes, it has 18 IP's assigned to it)

$vm = Get-VM $server | Select Guest

$vm.guest.ipaddress

 

Trying this command returns only one IP

$vm = Get-View -Viewtype virtualmachine -Filter @{"Name"="$server"} -Property Guest

$vm.guest.ipaddress

Get-Harddisk bug

$
0
0

PS C:\> Get-Harddisk -VM $vm

Works fine.  Returns the disks for $vm.

 

PS C:\> cd vmstore:\mydatacenter\datastore1

PS vmstore:\mydatacenter\datastore1> Get-Harddisk -VM $vm

Returns the disks for $vm and also all disks on datastore1.


VM report with drives connected to SAN (clustered servers)

$
0
0

Creating a VM report of all our vcenters and one of the columns of data that has proved helpful in our environment is the canonicalname. When space increase request come in, we supply these to the storage team for them to increase the Lun. Then we expand the drive within the OS. Here is what I have and just can't seem to figure out how to do it.

 

Get-VICredentialStoreItem-FileC:\Scripts\PowerCli\credentials-da1.xml|%{Connect-VIServer-Server$_.host -User$_.User -Password$_.Password}

 

$allhostinfo= @()


$Virtuals=Get-VM|Sort-Object-Propertyname


Foreach($Virtualin$Virtuals){

 

$list=Get-view-ViewTypeVirtualMachine-Filter @{"Name"="$($Virtual.Name)"} -Propertyname,config,guest,runtime

$allhostinfo+=$list}

 

$Report= @()

Foreach($virtualin$allhostinfo){

 

$worksheet=[pscustomobject]@{

 

"VM Name"=$virtual.name

 

"Guest Host Name"=$virtual.guest.hostname

 

"Primary IP"=$Virtual.Guest.IPAddress

 

"Power State"=$virtual.Runtime.PowerState

 

"CPU #"=$virtual.config.Hardware.NumCPU

 

"Memory GB"=$virtual.config.Hardware.MemoryMB

 

"Configured OS"=$virtual.Config.GuestFullName

 

"Guest OS"=$virtual.Guest.GuestFullName

 

"Cluster"= (Get-VM-Name$virtual.name |Select-Object-PropertyName,@{Name=’Cluster’;Expression={$_.VMHost.Parent}}).Cluster.name

"ScsiCanonicalName"= (Get-View-Id$virtual.Runtime.Host -PropertyConfig.StorageDevice.ScsiLun).Config.StorageDevice.ScsiLun |where ??????

 

 

}

$Report+=$worksheet

}

 

Function from THE book : vSphere PowerCLI Reference

$
0
0

Hello everybody.

 

First message but long time reader !

 

There is a function in my Bible,  VMware vSphere PowerCLI Reference (2nd Edition), with which I am blocked.

I did some research, maybe there is a problem during the print. But the problem has to be me !

 

I won't copy the function, to protect authors rights, but maybe owners of the book, or authors himselves could answer to me

 

The function I am talking about is the Listing 12.8, p 422 (2nd edition), in the chapter Organize your disaster recovery

 

I had export all my items in .xml files, but still there is a problem with the function Get-VILocation.

 

The problem is here :

 

Get-Folder -Location $parent $_.Name

 

Cannot validate argument on parameter 'Name', The argument is null or empty. I tried during Create Datacenters (p. 423) or VM Locations (p. 426)

 

Sorry for my english and thank you for the help !

 

Regards

 

Nicolas

certificate import error

$
0
0

Hi,

 

I am getting the below error while I try to run the below script to import the certificate

 

Please help

 

Error:

 

Testing vCenter URL https://pocvcenter65:5480

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 10.10.10.10:5480

   at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)

   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)

   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exc

eption)

   --- End of inner exception stack trace ---

   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)

   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

 

Downloading VC SSL Certificate from https://pocvcenter65/certs/download.zip to C:\Users\adm\Desktop\cert.zip

Importing to VC SSL Certificate to Certificate Store

System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "The system cannot find the file specified.

" ---> System.Security.Cryptography.CryptographicException: The system cannot find the file specified.

 

   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)

   at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)

   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)

   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName)

   --- End of inner exception stack trace ---

   at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)

   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)

   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)

Cleaning up, deleting C:\Users\adm\Desktop\cert.zip

Cleaning up, deleting C:\Users\adm\Desktop\certs

Get-Vm : Value cannot be null

$
0
0

With PowerCli 11, I got Value cannot be null

 

Get-Vm : Value cannot be null.

Parameter name: format

At line:1 char:1

+ Get-Vm *

+ ~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], ArgumentNullException

    + FullyQualifiedErrorId : System.ArgumentNullException,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

 

 

I got this error on almost all commands.

After some digging, I got this error only if I change windows display language (in my case from french to english). Currently running Windows 10 1709

 

Could anyone can confirm this a bug with PowerCLI?

How determine if VM in Vcenter (6.7) is Managed by Vcloud Director (9.5)

$
0
0

I used to have a script which connected to Viirtual Center and listed all VMs which are not managed by vcloud director. This worked well for Vcenter 6.5 and vcloudDirector 9.1 using the ManagedBy Attribute in the class VMware.Vim.VirtualMachineConfigInfo
After the Update to 6.7 and 9.5 this was unfortunately changed, and the managedby Attribute is now empty.... does anyone know how to determine between a VM managed by vcloud director and which is not? I cannot find any attribute which contains that part of information.

select template via portgroup and datastore

$
0
0

Hello,

I have a Lists of VMs in a CSVfile that I want to create from templates

I have a templates:

"vlan1DS0101"

"vlan1DS0102"

"vlan2DS0101"

"vlan2DS010"

so I want to check in whitch vlan and datastore the VM in the CSVfile is

 

like

 

Name = $row.Name

Datastore = $row.Datastore

$NameTemplate1 = "vlan1DS0101"

$NameTemplate2 = "vlan1DS0102"

$NameTemplate3 = "vlan2DS0101"

$NameTemplate4 = "vlan2DS0102"

 

If{(

      $row.Name = ($row.Portgroup = vlan1) & ($row.Datastore = DS0101) then Template1 = "vlan1DS0101")

       else (

                 If $row.Name = ($row.Portgroup = vlan1) & ($row.Datastore = DS0102) then Template2 = "vlan1DS0102")

     else(

                If $row.Name = ($row.Portgroup = vlan2) & ($row.Datastore = DS0101) then Template3 = "vlan2DS0101")

    else(

            If $row.Name = ($row.Portgroup = vlan2) & ($row.Datastore = DS0102) then Template4 = "vlan2DS0102")

}

somethin like this

Moving and Deleting VMDKs via PowerCLI in vSphere 6.5

$
0
0

Previously helped here:

Move, Remove, or Copy an orphaned VMDK all result in a Flat file?

 

From that thread for 5.5 I have a script that is basically:

 

$si = Get-View ServiceInstance
$vmdkMgr = Get-View $si.content.VirtualDiskManager
$ds = (a datastore object)
$file = '[Datastore] Path/File.vmdk'
$dcObj = Get-VMhost -Datastore $ds | Get-Datacenter

$vmdkMgr.DeleteVirtualDisk($file,$DCobj)

 

Summarized as it's part of a loop processing a report but more or less the above and it's working.

 

Problem is 6.5 managed files return 'A general system error occurred: The part of this virtual disk could not be opened'

Looking into it for 6.5 I need to instead use the VStorageObjectManager and the DeleteVStorageObject task using IDs from ListVStorageObject.

 

I've attempted:

 

$si = Get-View ServiceInstance
$vStorageMgr = Get-View $si.content.VStorageObjectManager
$ds = (a datastore object)
$dsView = Get-View $ds

$vStorageMgr.ListVStorageObject($dsView.MoRef)

 

Which yields no results or errors.

 

Am I missing something? To move/delete the VMDKs I need IDs provided from ListVStorageObject right?

Or is there a way to get this ID required by the VStorageObjectManager if I know the specific file I want to interact with?


starting ntp on esxi_powercli

$
0
0

hi Luc,

 

can you check if this is the corrrect way of starting ntp service

 

$clu=read-host "provide cluster name"

$cluster=Get-Cluster -Name $clu

$vmhosts=get-vmhost -Location $cluster

foreach($vmhost in $vmhosts)

{

$ntpd=Get-VMHostService -VMHost $vmhost|?{$_.Key -eq 'ntpd'}

$ntpd.Running

if($ntpd.Running -eq 'false')

{

 

$ntpd|Start-VMHostService -WhatIf

 

}

 

 

}

powershell command to remove PCI devices on vm's?

$
0
0

Does anyone know how to remove all PCI devices on vm's with either powershell or an advanced setting ?

vmware tools upgrade_powercli

$
0
0

Hi Luc,

 

can you suggest the easisest way of upgrading vmware tools on multiple machine through powercli.

most of machines are on esxi6.5 .

remove all pci devices on all vm's using powershell

$
0
0

I wish to harden all my vm's on an esxi host. However I don't know how to remove all pci devices. Any help ?

Renaming default ESXi datastores

$
0
0

By default, new ESXi creates a datastore on the local disk called "datastore1" on all new hosts.

When you add a batch of new hosts to vCenter, it will create duplicate names by appending a sequence number as below:

 

datastore1 datastore1 (1) datastore1 (2) datastore1 (3)

datastore2 datastore2 (1) datastore2 (2) datastore2 (3)

datastore3 datastore3 (1) datastore3 (2) datastore3 (3)

datastore4 datastore4 (1) datastore4 (2) datastore4 (3)

 

I would like to create powercli script that renames these datastores per new host to format ( short hostname + local + N )

 

example: esx-local1, esx-local2, esx-local3, esx-local4

 

Here's my initial function that i suppose to call within the script. There is a CSV file of hostlist that being called.

 

 

Function Rename-datastore {

Foreach ($Item in $CSV) {

$ESXHost=$Item.Hostname + ".domain.com"

$ds = get-vmhost $ESXHost | Get-Datastore -name datastore* | sort

Foreach ($datastore in $ds) {

$id = 0

        $id+=1

       

        Set-Datastore -Datastore $datastore -name (Get-VMHost $ESXHost -Id $_.ExtensionData.Host[0].Key[0]).Name.Split('.')[0] + '-local'+$id

        }

}

}

 

 

Thanks in advance. =)

Viewing all 14549 articles
Browse latest View live


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