LucD's Accepted Solutions

You didn't specify the Property for the imported data Change to $missingPrivileges = $PList.LIST | Where-Object { $_ -notin $currentPrivileges }
Looks like you didn't import the PowerCLI module that holds the definition for that type. Import-Module -Name VMware.VimAutomation.Core
The Principal parameter only accepts a single value. You will have to use a loop to add multiple $users = 'domain\user1','domain\user2','domain\user3' $users | Foreach-Object -Process { New-VI... See more...
The Principal parameter only accepts a single value. You will have to use a loop to add multiple $users = 'domain\user1','domain\user2','domain\user3' $users | Foreach-Object -Process { New-VIPermission -Entity (Get-Folder -Name Datacenters) -Principal $_ -Role Admin }
Ok, I think I found the cause of the issue. First I changed the here-string to single quotes, that way there is no issue with variable substitution and you don't need to use the back-tick before e... See more...
Ok, I think I found the cause of the issue. First I changed the here-string to single quotes, that way there is no issue with variable substitution and you don't need to use the back-tick before every $ in the code. But the real issue is the length of the script itself, i.e. the length of the text passed to ScriptText. There is unfortunately an undocumented limit on the allowed length of that text. See also Invoke-VMScript ScriptText Maximum Length - VMware Technology Network VMTN With my Invoke-VMScriptPlus function that limitation in length is not there. The attached version (including the code for the Invoke-VMScriptPlus function) works for me.
To get the 'Unlimited' limit you have to provide a $null value. You can do that with a simple if-then-else. Also, by using splatting the code becomes much more readable and you can limit the numb... See more...
To get the 'Unlimited' limit you have to provide a $null value. You can do that with a simple if-then-else. Also, by using splatting the code becomes much more readable and you can limit the number of calls to the Set-VMResourceConfig cmdlet to 1. Something like this $OriginalVMSettings = Get-Content -Raw -Path ".\LSVMOriginalSettings.json" | ConvertFrom-Json foreach ($LSVM in $OriginalVMSettings) { Write-Output $LSVM.Name $CurrentVM = Get-VM -Name $LSVM.VMName $CurrentVMResConfig = $CurrentVM | Get-VMResourceConfiguration Write-Output $CurrentVMResConfig $sConfig = @{ CpuReservationMhz = $LSVM.CPUReservationMHz CpuLimitMhz = if ($LSVM.CpuLimitMhz -eq -1) { $null }else { $LSVM.CpuLimitMhz } MemReservationMB = $LSVM.MemReservationMB MemLimitMB = if ($LSVM.MemLimitMB -eq -1) { $null }else { $LSVM.MemLimitMB } } $CurrentVMResConfig | Set-VMResourceConfiguration @sConfig Write-Output "After restoration..." $CurrentVM | Get-VMResourceConfiguration }  
Try leaving out the ErrorAction on the Import-Module. Import-Module -Name VMware.PowerCLI
This is not really a PowerCLI question but a bash question. In any case, this seems to work for me $vmName = 'MyVM' $user = 'user' $pswd = 'VMware1!' $cred = New-Object -TypeName PSCredential -Ar... See more...
This is not really a PowerCLI question but a bash question. In any case, this seems to work for me $vmName = 'MyVM' $user = 'user' $pswd = 'VMware1!' $cred = New-Object -TypeName PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force) $code = @' echo 'name,MAC' ip -o link | awk '$2 != "lo:" {print $2 "," $(NF-2)}' '@ $result = Invoke-VMScript -VM $vmName -ScriptText $code -GuestCredential $cred -ScriptType Bash $net = $result.ScriptOutput | ConvertFrom-Csv Get-NetworkAdapter -VM $vmName -PipelineVariable vnic| Select @{N='VM';E={$vmName}}, Name,NetworkName,MacAddress, @{N='Check';E={$vnic.Type}}, @{N='GuestLink';E={$net | where{$_.MAC -eq $vnic.MacAddress} | Select -ExpandProperty name}}
What exactly does the error say? That line with Get-View is not needed. You can get those values also from the original $vm variable. $VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Ob... See more...
What exactly does the error say? That line with Get-View is not needed. You can get those values also from the original $vm variable. $VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) { ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) { ForEach ($VM in ($Cluster | Get-VM | Where-Object{$_.Name -notmatch '^vcls'} | Sort-Object -Property Name)) { ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) { $guestHD = Get-VMGuestDisk -HardDisk $HardDisk "" | Select-Object -Property @{N="VM";E={$VM.Name}}, @{N="Configured OS";E={$vm.ExtensionData.Config.GuestFullName}}, @{N="Running OS";E={$vm.ExtensionData.Guest.GuestFullName}}, @{N="Datacenter";E={$Datacenter.name}}, @{N="Cluster";E={$Cluster.Name}}, @{N="Hard Disk";E={$HardDisk.Name}}, @{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}}, @{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}}, @{N="VMDKpath";E={$HardDisk.FileName}}, @{N="VMDK Size";E={[math]::Round(($vm.extensiondata.layoutex.file|Where-Object{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB)}}, @{N="Drive Size";E={$HardDisk.CapacityGB.foreach{[math]::Round($_)}}}, @{N='GuestDiskPath';E={$guestHD.DiskPath -join "`n"}}, @{N='GuestCapacityGB';E={($guestHD.CapacityGB.foreach{[math]::Round($_)}) -join "`n"}}, @{N='GuestFreeGB';E={($guestHD.FreeSpaceGB.foreach{[math]::Round($_)}) -join "`n"}}, @{N='GuestDiskType';E={$guestHD.FileSystemType -join "`n"}} } } } } $VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path ".\VmInfo.csv"
You mean like this? @{N="VMDK Size";E={[math]::Round(($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB)}}, Like I said earlier, thi... See more...
You mean like this? @{N="VMDK Size";E={[math]::Round(($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB)}}, Like I said earlier, this Get-VMGuestDisk doesn't always work. There are many prerequisites for this cmdlet and VMware Tools to return values.
Afaik there is no property indicating if an object was created due to linked vCenters. That only plays when the object is created I suspect. So yes, testing, like your snippet, might be the best ... See more...
Afaik there is no property indicating if an object was created due to linked vCenters. That only plays when the object is created I suspect. So yes, testing, like your snippet, might be the best solution.
It might be a long shot, and yes, KB88928 is about exporting, but that resolution in there might help.
You can change the HD unitnumber with the ReconfigVM method. See for example Re: Automate add Windows Hard Disk - VMware Technology Network VMTN
I would definitely open an SR for that one. And if GSS claims you need a Developer Support contract, that is not correct. Point them to PowerCLI Support Breakdown (para 3 & 4)
Is $vm.UsedSpaceGb the number you are after?
You might want to have a look at Solved: Re: Invoke-VMScript. Pass variable in BASH - VMware Technology Network VMTN as an example on how to use Invoke-VMScript on a Linux box and use the sed to chan... See more...
You might want to have a look at Solved: Re: Invoke-VMScript. Pass variable in BASH - VMware Technology Network VMTN as an example on how to use Invoke-VMScript on a Linux box and use the sed to change a file on there.
Try like this Get-VMHost | Select Name, @{N='CryptoState';E={$_.ExtensionData.Runtime.CryptoState}}
Have a look at Solved: Re: Network Adapter information using Invoke-VmScr... - VMware Technology Network VMTN
You are not alone, I often see the same. Looks like the concept is not yet 100% working all the time (even the documented prereqs are fulfilled). And since the ExtensionData doesn't show the data, ... See more...
You are not alone, I often see the same. Looks like the concept is not yet 100% working all the time (even the documented prereqs are fulfilled). And since the ExtensionData doesn't show the data, it is obviously not a PowerCLI issue imho.
Have a look at Re: Extract All vSS & VDS details for all vCenters - VMware Technology Network VMTN
The 'Do not use ..." option is indeed missing from the current PowerCLI version. The only way I know off to set IPv6 to that option is to use the CustomizationSpecManager methods. The following... See more...
The 'Do not use ..." option is indeed missing from the current PowerCLI version. The only way I know off to set IPv6 to that option is to use the CustomizationSpecManager methods. The following code should work if you only have 1 NIC in your OSCustomizationSpec. If you have more, the script needs to loop through all of them.     $osCustName = 'MyCustomization' $custMgr = Get-View CustomizationSpecManager $cust = $custMgr.GetCustomizationSpec($osCustName) $cust.Spec.NicSettingMap[0].Adapter.IpV6Spec = $null $custMgr.OverwriteCustomizationSpec($cust)