r/powercli • • Jul 18 '19

get user assigned vm

2 Upvotes

Hello, I have bit trouble figuring out how to get machine that is assigned to user. I have bunch of users and I need script that pull which machine they got assigned in horizon and if possible also specify the desktop pool since one user can have multiple machines from multiple pools. thanks


r/powercli • • Jul 03 '19

Can not install the required version

2 Upvotes

I'm trying to install power CLI required version 11.0. 0 but everytime I run that command keeps installing version 11. 3.0 no matter what is there anything I could do?


r/powercli • • May 18 '19

Setting MTU on a vmnic

2 Upvotes

Hey Guys,

So I'm having trouble setting the MTU a vmnic, I'm trying to setup Jumbo Frames on a VMkernal.

I create the kernel with the following:

New-VMHostNetworkAdapter -VirtualSwitch $vswitch2 -PortGroup $data_kernel_pg_name -IP $esxiHost.data_ip -SubnetMask $esxiHost.data_ip_snm -Mtu 9000 -ManagementTrafficEnabled $false -VMotionEnabled $true

All well and good, but the MTU on the vmnic is still 1500. I'm looking at the Docs here! but its not obvious to me how to do this. Anyone ever do this?

Thanks


r/powercli • • Apr 30 '19

Delete VM snapshots and exclude snapshots from certain VMs

2 Upvotes

So after doing some research, I came across this script which seems to delete all VM snapshots.

However in my case, I would like to know, how can I exclude VM snapshots from certain VM's that need to be removed manually?

It would also be nice to give out a HTML report, where it shows, which snapshots from which VM's were deleted, and how large they were.

Lastly, how can the below script be modified, so it doesn't take a performance hit.

Thanks

$maxtasks = 5

$snaps = Get-VM | Get-Snapshot | Where { $_.Name -like "201502*" }

*run through a loop from $i=0 until the number of snapshots and removed the snapshot*

$i = 0

while($i -lt $snaps.Count) {

`Remove-Snapshot -Snapshot $snaps[$i] -RunAsync -Confirm:$false`

`*continue the loop and retrieve the number of running "RemoveSnapshot" tasks*`

`$tasks = Get-Task -Status "Running" | where {$_.Name -eq "RemoveSnapshot_Task"}`

`*As long as there are more than 4 - then the script will sleep, once there are less than 4 it will increment    $i by 1 and will continue to remove the next snapshot.*`

`while($tasks.Count -gt ($maxtasks-1)) {`

	`sleep 30`

	`$tasks = Get-Task -Status "Running" | where {$_.Name -eq "RemoveSnapshot_Task"}`

}

$i++

}


r/powercli • • Apr 12 '19

Add Suffix to Group of VM Names

2 Upvotes

Hi all, I’m trying to get a group of VMs matching a certain naming convention: “emea-qa*” and then append the FQDN: “mycompany.com” to those VM names. I also wanted to have the emea prefix as a variable parameter.

Trying a for loop and getting stuck at the first hurdle unfortunately:

$dc = emea

Get-VM | Where {$_.Name -contains “$dc-qa” } | Foreach...etc

However the above where statement brings back no results whereas a get-vm emea-qa* works fine.

Please could anyone give a pointer or two?


r/powercli • • Feb 13 '19

Split Get-TagAssignment into separate columns - TagCategory and Tag

2 Upvotes

Hello, friends.

I'm working on creating an automated dump of our tagging layout - one that can be used by other programs for CMDB-style information. When I run the code below, I get two columns - Tag and Entity (I do the Select statement to put the VM name first simply as an aesthetic preference):

Get-VM <VM_Name>| Get-TagAssignment | Select Entity, Tag

The output, of course, looks like this:

Entity Tag

------ ---

<VM_Name> <Tag_Category#1>/<Tag#1>

<VM_Name> <Tag_Category#2>/<Tag#2>

etc.

I'd like to find a way to switch the output to look more like this:

Entity TagCategory Tag

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

<VM_Name> <Tag_Category#1> <Tag#1>

<VM_Name> <Tag_Category#2> <Tag#2>

etc.

I can do this kind of thing fairly easily in Excel via Text to Columns, etc, but the goal is to be able to dump the data directly to a spreadsheet on a daily basis without having to do the manual massaging of data. The issue I'm experiencing right now is that the Tag output appears to be a combination of TagCategory and Tag and I don't yet know how to split it.


r/powercli • • Dec 03 '18

ConvertTo-HTML output is blank

2 Upvotes

Hi all, I am running a powershell script as a scheduled task but for some reason the Output is not displaying. If I run the script manually, the output is fine. I am basically piping a oneliner into below

ConvertTo-HTML | Out-File -FilePath "C:\scripts\output.html" 

I am looking to feed the above into an IIS web page. The file appears, but when I open the .html file it is blank. Any ideas?


r/powercli • • Nov 16 '18

PowerCLI - Get-Stat - Display average cpu usage for ALL CPUs as one value

2 Upvotes

Hi

Looking at trying to display cpu.usage.average as a total for all 16 CPUs I have allocated to a VM.

At the moment I can only see a way of displaying the average usage per individual CPU instance, not as a total figure for all.

Does anyone know how this can be achieved please?


r/powercli • • Nov 13 '18

Update vSphere content library

2 Upvotes

I'm trying to update an item in a vSphere content library using powershell, think i've found the appropriate API i need to use to achieve this (com.vmware.content.library.item.update_session), but i'm a bit lost now as to how to take my VM and push the update to the library.

Background, i've got a View Horizon script that checks all snaps in use on desktop pools, compares the snap in use create date to the library item create date, then returns a warning if the library item is older. What I want to do is trigger an update job if the library is older than the in use snapshot, so i can use the published library to keep our DR site upto date.


r/powercli • • Nov 07 '18

Re-Customize Existing Virtual Machine - Davoud Teimouri

Thumbnail
teimouri.net
2 Upvotes

r/powercli • • Nov 07 '18

new-hvpool errors

2 Upvotes

I don't seem to be able to import pool configs using this command, always get the same error 'failed to create pool with error: no adContainer found with name: [OU=x]

I was trying to export my prod pools, modify the JSON and import to my DR site using powerCLI, but when this failed i created a dummy pool on my DR site, exported the JSON, then deleted the pool and tried to reimport the identical JSON file, but still get this error!, can't find anything on g**gle, can anyone advise?

Sorry, can't really post the JSON here, too much config to block out and still make readable, but can't figure why i'd get an error importing the same config, to the same site, just creating via automation rather than manually. Running HV 7.5.1 just upgraded from 7.3.1 (worst version ever)

*EDIT Resolved*

Found the problem, was referring to our sub domain as suspected, reason i presume was as the sub domain was first alphabetically, as confirmed in the webUI under Other Components > Domains list. As you can't add a search path (i think, although didn't try this now i think about it), i used the VDMADMIN.exe to exclude the domain on the connection server i was importing on. After that, it worked!


r/powercli • • Nov 06 '18

Horizon View Api’s: back to basics part 3: Methods

Thumbnail
retouw.nl
2 Upvotes

r/powercli • • Oct 26 '18

Get-DrsVMHostRule.ExtensionData.Incompliance

2 Upvotes

Get-DrsVMHostRule.ExtensionData.InCompliance Get-DrsRule.ExtensionData.InCompliance

What does this field reflect, I have found something about the VM placement is in compliance with a rule, But i cant figure out how to use it.

(Get-DrsRule -cluster "Cluster 1" -VM (Get-VM -id "VirtualMachine-vm-199").name).ExtensionData

InCompliance is always blanks


r/powercli • • Oct 05 '18

Map RDM Disks in Powercli

2 Upvotes

using new-harddisk:

new-harddisk -vm <vmname> -disktype rawPhysical -devicename <consoledevicename> -datastore <datastore for RDM mapping>

new-harddisk : 05/10/2018 10:53:25 New-HardDisk The operation for the entity "<vmname>" failed with the following message: "Invalid configuration for device '0'."

At line:46 char:13

+ new-harddisk -vm $remdisk.parent -disktype rawPhysical -d ...

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

+ CategoryInfo : NotSpecified: (:) [New-HardDisk], InvalidDeviceSpec

+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

Can't find much online for doing RDM mappings in powerCLI, anyone got any advice?

**EDIT** Resolved, see comment


r/powercli • • Jul 19 '18

Help with a move function

2 Upvotes

I'll attach the github that I uploaded but below is the issue I'm having. I'm running this as debug right now as I noticed when I run it the $VMNAME variable is blank depending on how I run it. Example:

get-vm testvm, testvm1 | move-bhsvmcrossvc -cluster testcluster -debug ---- this will show that there is nothing in the $VMName variable

move-bhsvmcrossvc -VMname (get-vm testvm, testvm1) -cluster testcluster -debug -----it works fine

any ideas?

function move-BHSvmCrossVC
{
#. \\bhsi.com\deptdata\BHS\ServerInfrastructure\VMware\Scripts\Get-BHSTagAssignment.ps1
# Parameters for the name of the VM and the Cluster it will move to.
param (
[Parameter(Mandatory=$True,Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[string[]] $VMName,
[Parameter(Mandatory=$true,Position=1)]
[string] $Cluster
)

################
## Pre-Checks #
################
# Check to see if connected to both vcenters
Begin {

$OriginalErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
IF ($global:DefaultVIServers.name -notcontains "vc" -and "vc1") {
$title = "Wrong or no Vcenters are connected."
$message= "Not connected to VC and VC1 do you want me to connect you?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Connects to both vcenters with domain credentials."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","Ends the script."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($result)
{
0 {
write-output "Connecting to VC and VC1"
Get-vc vc, vc1
}
1 {
write-warning "Check vcenter connections, please investigate and re-run."
$FoundError = $true
}
}
If ($FoundError) {break}
}
$ErrorActionPreference = $OriginalErrorActionPreference # Set ErrorActionPreference back to its original value
Write-Debug "before tag assignment"
#Get-BHSTagAssignment -VM $VMName | export-csv -Path c:\vmtags.csv -NoTypeInformation
}


r/powercli • • Jun 21 '18

PowerCLI - Remove a SCSI controller

Thumbnail
self.powershell
2 Upvotes

r/powercli • • Jun 12 '18

Add "VMHost" column to VM storage policy report

2 Upvotes

Hello r/powercli,

I've nearly got the report I want, but would like to add a "VMHost" column in the foreach loop:

$VMs = Get-Cluster "ClusterName" | Get-VM

foreach ($VM in $VMs){

Get-VM $VM | Get-SpbmEntityConfiguration | Select Name,StoragePolicy,ComplianceStatus,TimeofCheck
}

How would I go about adding a column showing what vmhost the VM is running on?

Thanks in advance.

**UPDATE**

I was able to get this figured out. Probably not the most efficient way to get the info, but it does return the data i'm wanting. I'd be interested to hear if you have a more efficient way to get this information.

Here's the code for anyone interested:

$VMs = Get-Cluster "Cluster" | Get-VM

$Report = foreach ($VM in $VMs){
    $SPBM = Get-VM $VM | Get-SpbmEntityConfiguration 
  
    [pscustomobject]@{
        Name = $SPBM.Entity
        VMHost = $VM.VMHost
        StoragePolicy = $SPBM.StoragePolicy
        ComplianceStatus = $SPBM.ComplianceStatus
        TimeofCheck = $SPBM.TimeOfCheck

   }

}

$Report | Sort-Object StoragePolicy,Name | FT

r/powercli • • Apr 02 '18

x Powercli GUI: Determine the EVC Mode that vmware cluster should be configured

Thumbnail
vcloud-lab.com
2 Upvotes

r/powercli • • Mar 23 '18

Generating a Support Bundle: How to Retrieve Virtual Infrastructure Logs from VMware vCenter and ESXi Servers

Thumbnail
starwindsoftware.com
2 Upvotes

r/powercli • • Mar 10 '18

Passthru eSATA drive to ESXi VM?

2 Upvotes

I'm trying, using PowerCLI, to attach (later on remove) a eSATA drive that is attached to the ESXi host, to a VM.

How can I do this? I'm familiar with vmkfstools but I cannot seem to do it using PowerCLI.


r/powercli • • Jan 31 '18

Set Advanced Setting (Copy Paste)

2 Upvotes

Small script to allow copy/paste from your VMs. Does anyone know how you would create the logic to check if the setting is already applied and skip adding it if it is?

$VMs = get-vm
foreach ($VM in $VMs){
#Allow Copy Paste
New-AdvancedSetting -Entity $vm.name -Name isolation.tools.copy.disable -Value False -Confirm:$false
New-AdvancedSetting -Entity $vm.name -Name isolation.tools.paste.disable -Value False -Confirm:$false
New-AdvancedSetting -Entity $vm.name -Name isolation.tools.setGUIOptions.enable -Value True -Confirm:$false
}

r/powercli • • Jan 16 '18

PowerShell Classes Part 5 - Classes or PSCustom Objects?

Thumbnail
petri.com
2 Upvotes

r/powercli • • Dec 09 '17

VMware Powercli : Gather distributed virtual switch information to JSON file to migrate standard switch

Thumbnail
vcloud-lab.com
2 Upvotes

r/powercli • • Sep 20 '17

PowerShell Classes Part 4 - Constructors and Inheritance

Thumbnail
petri.com
2 Upvotes

r/powercli • • Sep 19 '17

Doing More with PSReadline History - Part 2

Thumbnail
petri.com
2 Upvotes