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

Please help with adding a member to PSObject

$
0
0

Thanks for everyone that has helped so far, I have this script that I am working on, I have this one section that does not display correctly, it's in bold, the rest is working correctly.  Basically, when it retrieves the names of the data centers, they come in as a table, showing that it's a hash table..similar to this: 

 

vSphere Data Center(s)  { @{Name=DC1}, @{Name=DC2} } and so on

 

I tried changing some things around, I would use Select-Object Name, and try some subexpressions, but they just don't work.  The output of the other data looks like this:

 

ESXihostCount                : 4

vSphere Version: 5.0.0       : 9

vSphere Version: 4.1.0       : 7                        I changed the numbers around...I know, no reason to, but I'm paranoid and I like to stay in that habit.

HW Model: ProLiant BL490c G6 : 1

HW Model: ProLiant BL460c G7 : 2

HW Model: ProLiant BL460c G1 : 1

HW Model: ProLiant BL460c G6 : 1

HW Model: ProLiant DL160 G6  : 1

 

I just want the curley braces removed, and I'm not sure how.

 

 

Portion of the Script

$ALLDataCenter = Get-Datacenter
$ALLCluster = Get-Cluster
$AllESXiHost = Get-VMHost
$ALLVM = Get-VM
$VMView = $ALLVM | Get-View
#Creating a new Powershell Object to store information (for data center)
$vDataCenter = New-Object -TypeName PSObject
#$vSphereDC = $ALLDataCenter | Select Name
#$vSphereDC | Foreach { Add-Member -InputObject $vDataCenter -MemberType NoteProperty -Name "$(vSphere Data Center(s) -Value $_.Name)" }
#$vSphereDC | Add-Member -MemberType NoteProperty -Name "vSphere Data Center(s)" -Value ($ALLDataCenter[0]).Name
$vDataCenter | Add-Member -MemberType NoteProperty -Name "vSphere Data Center(s)" -Value ($ALLDataCenter | select Name)
#Creating a new Powershell Object to store information (for ESXi Hosts)
$ESXiInfo = New-Object -TypeName PSObject
$vVersions = $AllESXiHost | Group Version | Select Name, Count
$HWModel = $AllESXiHost | Group Model | Select Name, Count
$ESXiInfo | Add-Member -MemberType NoteProperty -Name ESXihostCount -Value ($AllESXiHost).count
$vVersions | Foreach { Add-Member -InputObject $ESXiInfo -MemberType NoteProperty -Name "vSphere Version: $($_.Name)" -Value $_.Count }
$HWModel | Foreach { Add-Member -InputObject $ESXiInfo -MemberType NoteProperty -Name "HW Model: $($_.Name)" -Value $_.Count }

 

Thanks in advance


Script to report on virtual machine automation level in DRS

$
0
0

I'm having a difficult time building a report that gives me the "automation level" setting for each virtual machine in the infrastructure.  This setting is located in the cluster DRS "virtual machine options" setting (see attached image).  I've been working with get-drsrule and get-cluster commandlets, but no success.  Anyone know where to get this data from via powershell?  Thanks.

Edit Host Profiles with PowerCLI

$
0
0

Hi all,

 

I know we have some limitations on what we can do with PowerCLI and Host Profiles.

 

Lately I came to know, thanks to mr. LucD (http://communities.vmware.com/message/1889243 and his own site) that it is possible to modify the root password in Host Profiles.

 

But know I have some addittional things I would like to do with Host Profiles and PowerCLI.

 

I want to use PowerCLI to:

 

  • Update Profile from reference host  (workaround is to delete / recreate host profile)

 

  • Edit these settings in a Host Profile:
    • Networking configuration | DNS configuration | Host Name
      Set to: User specified host name to be used while applying the configuration


    • Authentication configuration | Domain Name
      Set to: Configure a fixed domain name

 

Any ideas?

 

Thanks!

 

Cheers,

 

Harold

@hharold

esxcli Software Error

$
0
0

Hi All,

 

I wasn't able to post this in the PowerCLI section as it looks to be restricted to developers so this is the closest forum I could find.

 

I'm trying to follow some instructions from a Dell website to check if the VIBs were migrated across after I ran an update from 5.0 -> 5.1 via VUM.

 

The command is:      esxcli software vib list|grep -i open

 

when even running esxcli software I receive the error:

 

Get-EsxCli : 25/09/2012 10:48:12 AM    Get-EsxCli        The method or operatio
n is not implemented.
At line:1 char:7
+ esxcli <<<<  software
    + CategoryInfo          : NotSpecified: (:) [Get-EsxCli], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.GetEsxCli

 

This is after I've run:     Connect-VIServer and received confirmation that i've connected with the output:

 

Name                           Port  User
----                           ----  ----
vm04                           443   root

 

The original instructions i'm following can be found here:

http://www.dell.com/support/drivers/au/en/aulca1/DriverDetails/Product/poweredge-r710?driverId=W32PK&osCode=XI51&fileId=3006491785

..under "Using the Power CLI"

 

Any help or if someone could point me in the right direction would be much appreciated!

 

Regards,

 

Jon

connecting vCenter remotely (in different domain)

$
0
0

I'm sure it must be answered some where in the forum. But i couldn't locate it.

 

I have two domain.

 

Domain A and Domain B.

 

Domain B is secured and can be access from Domain A.

 

I've created a small script which will run on vCenter of Domain B but it is not allowed to send email using SMTP server.

 

So i've to run a script from Domain A where I'm allowed to sent email using SMTP server.

 

Now since I will be connecting to vCenter remotely using credentials of Domain B, I would like to know how do I store credentials of vCenter of domain B in script file?

 

As I will be running this script under schedule tasks i can't keep plain text password in the script

 

e.g. connect-viserver "remoteVC" -username "DomainAdminA" -password "Password"

 

I can't run get-credentials it will be only valid for that session inside the shell.

 

Thank you for helping me in advance.

 

Preetam

DRS Rule -Virtual Machine DRS Group

$
0
0

Hi There,

 

I tried googling but didn't found much help.

 

Is there a way I can get VM's defined inside the DRS Group for Virtual Machine rules

 

 

When I try to use get-DRSRule but it was not much of help.

 

Thank you in Advance,

Preetam

List all VMs per Datastore

$
0
0

Hello,

 

At some point LucD posted the following answer in another thread http://communities.vmware.com/thread/293395

Get-Datacenter | Get-VM | %{$vm = $_Get-Datastore -VM $vm | %{$vm.Name + "-" + $_.Name} } | ft -AutoSize

 

But on my end, I can not make it work I get the following error:

 

You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:41
+ Get-Datacenter | Get-VM | %{$vm = $_Get- <<<< Datastore -VM $vm | %{$vm.Name + "-" + $_.Name} } | ft -AutoSize
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

 

Thanks for your help,

 


insufficient permissions error with get-vmguestnetworkinterface

$
0
0

Hi,

 

I am experimenting with powercli on an ESX 4.0.0 environment with VSphere client  v5.0 and Powercli 4.1 with VIX 1.10.0.12331.

 

I want to automate a cloning process by script. In testing I logon to my vsphere server with the Connect-VIServer -Server xxxxxxx -User xxxxx -Password xxxxx command. Then I try a Get-VMGuestNetworkInterface -VM xxxxxxxx command to query info about the network settings of a vm running Windows 2008 Server.

 

The command then prompts for both a HOST id and password and a GUEST id and password. The Host id and pass seems to be for whichever ESX host is currently running the vm. This is a pain in the ass as I don't have an account for each ESX host, just my vsphere login - which has administrator rights, all I need to manually clone, change settings etc.

 

I have seen documentation that suggests that Powercli with VIX allows access to the Guest OS with vms without requiring a login to the ESX host server, e.g.: 

 

http://www.vmware.com/support/developer/PowerCLI/PowerCLI50/html/Invoke-VMScript.html   says in reference to get-vmguest commands:

 

" Specify the password you want to use for authenticating with the host. You need to specify host credentials only if the version of the vCenter Server or ESX you are authenticating with is earlier than 4.0, or the VIX version you have installed is earlier than 1.10. "
But I'm still prompted  to login to a host when I run the command.
I am working for a 3rd party and it is a big ask to request individual ESX host logins, and I'm not sure what level of permissions they require.
Can anyone advise what I'm doing wrong? Why can't powercli use the vsphere authentication I've already logged in with connect-vi? I accept I need to provide a guest os password but attaching to individual ESX hosts seems redundant seems redundant.

 

Thanks!


Remove vmnic from Host

$
0
0

I'm trying to remove a vmnic from a host, and the PowerCLI Cmdlets Reference looks like it's giving me the wrong information:  www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Remove-VMHostNetworkAdapter.html

 

Here's what I tried:

  $network = get-vmhostnetworkadapter -vmhost Host1 -name vmnic7

  Remove-VMHostNetworkAdapter -nic $network

Cannot bind parameter 'Nic'. Cannot convert the "vmnic7" value of type "VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.Nic.PhysicalNicImpl" to type "VMware.VimAutomation.ViCore.Types.V1.Host.Networking. Nic.HostVirtualNic".

 

I also tried:

  $network = get-vmhostnetwork -vmhost Host1

  remove-vmhostnetworkadapter -nic $network.virtualnic[7]

Cannot validate argument on parameter 'Nic'.  The argument is null or empty.

 

Any ideas?

Error: Exception setting "Item":

$
0
0

Hello Gurus,

 

I have the following code:

 

$array0 = Get-Datacenter | Get-VM | %{$vm = $_ ; Get-Datastore -VM $vm | %{$vm.Name + "--" + $_.Name} } | ft -AutoSize


Do {

 

    $value = $array0[$i]
    $value
    $Sheet.Cells.Item($intRow,$intColumn) = $value
    $i ++
    $intRow ++
} Until ( $array0[$i] -eq $null )

 

The $value echoes fine but there is an error when inserting that value into excell. I get the following error:

 

UPIRDS01--UPI-SAS-V5-DS04
Exception setting "Item": "Exception from HRESULT: 0x800A03EC"
At C:\scripts\VMware\Healthcheck_vCenter_xls.ps1:396 char:19
+     $Sheet.Cells.Item <<<< ($intRow,$intColumn) = $value
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertySetValueTI

 

Thanks for your help

Migrating VMs to other Hosts in the Cluster

$
0
0

Hi there

 

I am looking for a simple script to move VMs off a Host, and move them to various other Hosts within the same Cluster

 

I have found this

 

 

$sourcehostname = (Get-VMHost 'esx01’).name

 

$clusterhosts = Get-Cluster 'Cluster 1' | Get-VMHost |
    Where-Object {$_.name -notlike "$sourcehostname"}

 

$vms = Get-VMHost $sourcehostname | Get-VM

 

Which I understand gets all the VMs on the Host, and prepares them to be moved to other Hosts withing the Cluster specified

 

I just need a hand with the Move-VM part, I need it to move more than one VM at a time, I'm not sure if I need runassync in it

powercli script to see if someone is loged in into a view client.

$
0
0

Hi,

I'll be working on a script that will shut down the view desktops at night. In the morning these clients boot up before 7 am. When i use the view shutdown option every time i logged out the client turns off and that is not what i want .

My idea was to make a list of running desktops with a logged in user around 1 pm.

shut down all the clients that has no logged in user at 8 pm. (homeworkers had to work in the evening)

boot up the clients from the list at 6 am.

Creating a list for shutdown and boot up works already but my problem is to find out if there is a user logged into the desktop.

Can someone put me in the right direction because googling on user and login gives me many hits !

ESX Cluster Load--Host wise...

$
0
0

Hi all,

 

I have 2 clusters with ESX Hosts.

Now I need to get the report for each cluster configuration and cluster have HOSTs.configuration ..I want the report like...cluster resource report and cluster's HOST report..in same

 

like below

 

Clustername ||||  Total Disk Space (MB) |||| Available CPU (Mhz) |||| Total CPU (Mhz) |||||||||   Total Physical Memory (MB) |||   Available Memroy (MB)

____________________________________________________________________________________________________________


 

 

 

Thks for LUC providing below report. ,i got this report from our vmware blogs,its same rreport this only for CLUSTERS

 

I hope u all understand my problem.

 

appreciate your help

 

Thank you,

ALDOVMWARE

 

# Virtual Center Server
$VCServerName = "my servername"
$creds = Get-Credential
# Some variables
$portvc="443"
$VC = Connect-VIServer -server $VCServerName -Credential $creds  -ErrorAction Stop -port $portvc
$report = @()
$clusterName = "MonitoringTestCluster"
$report = foreach($cluster in Get-Cluster -Name $clusterName){
    $esx = $cluster | Get-VMHost
#    $ds = Get-Datastore -VMHost $esx | where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess}
    New-Object PSObject -Property @{
        VCname = $cluster.Uid.Split(':@')[1]
        DCname = (Get-Datacenter -Cluster $cluster).Name
        Clustername = $cluster.Name
        "Number of hosts" = $esx.Count
        "Total Processors" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuPkgs} -Sum).Sum
        "Total Cores" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuCores} -Sum).Sum
        "Current CPU Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentCpuFailoverResourcesPercent
        "Current Memory Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentMemoryFailoverResourcesPercent
        "Configured Failover Capacity" = $cluster.Extensiondata.ConfigurationEx.DasConfig.FailoverLevel
        "Migration Automation Level" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.DefaultVmBehavior
        "DRS Recommendations" = &{$result = $cluster.Extensiondata.Recommendation | %{$_.Reason};if($result){[string]::Join(',',$result)}}
        "DRS Faults" = &{$result = $cluster.Extensiondata.drsFault | %{$_.Reason};if($result){[string]::Join(',',$result)}}
        "Migration Threshold" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
        "target hosts load standard deviation" = "NA"
        "Current host load standard deviation" = "NA"       
        "Total Physical Memory (MB)" = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum
        "Configured Memory MB" = ($esx | Measure-Object -Property MemoryUsageMB -Sum).Sum
        "Available Memroy (MB)" = ($esx | Measure-Object -InputObject {$_.MemoryTotalMB - $_.MemoryUsageMB} -Sum).Sum
        "Total CPU (Mhz)" = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
        "Configured CPU (Mhz)" = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum
        "Available CPU (Mhz)" = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum
        "Total Disk Space (MB)" = ($ds | where {$_.Type -eq "VMFS"} | Measure-Object -Property CapacityMB -Sum).Sum
        "Configured Disk Space (MB)" = ($ds | Measure-Object -InputObject {$_.CapacityMB - $_.FreeSpaceMB} -Sum).Sum
        "Available Disk Space (MB)" = ($ds | Measure-Object -Property FreeSpaceMB -Sum).Sum
    }
}
$report | Export-Csv "Q:\Cluster-Report.csv" -NoTypeInformation -UseCulture

More Free Space Reporting...

$
0
0

We have requirements to report on a group of VMs in certain blue folders.  We would like to generate a report for VMs with less the 100MB of free space.

 

Taking the script developed in Report Free Space, is this something that can be done?

Adding a Windows computer to a Windows domain

$
0
0

Hi,

 

I've had some success automatically creating Unix machines from a template using an XMl config file and PowerShell - works nicely.

 

However, I am now trying to do the same with Windows machines and am having a couple of problems.  I hope someone will be able to help.

 

1) I have a Windows XP template.  This has one local user and is set to auto-login (i.e. doesn't require any user intervention to get to the desktop).  When I use Powershell to create a new machine from this template (using new-vm and specifying a customisation), the machine is created, it boots logs in and starts the customisation and then reboots.  Once it has rebooted, the machine does not auto login.  If I click the (only) username, it logs in and then does some more customisation.  I'm obviously looking to see why it asks to login - it's preventing the process from being completely hands-off.

 

2) The customisation adds the computer to a Windows domain.  If I create a machine from the template from within VCenter it works fine.  If I specify the same customisation from Powershell, the machine is not added to the Windows domain, though it seems to have done everything else - set the computer name, IP address, DNS etc. 

I see that there is a cmdlet called Add-Computer but a) I don't see why I should need to do this if the customisation does it, and b) I'm not sure when I'd actually execute this (after all the customisation has occurred presumably but I don't see how I know that - the script has finished well before the machine has completed the customisation process.

 

Any pointers would be gratefully received.

 

Thanks


Detach datastore using NAA ID number

$
0
0

All,

  does anyone know the command or view to be able to detach a scsi lun by NAA number?  I am using William Lam's script for detaching by datastore name, but i also have some that haven't been created and i only have NAA number, but i need ot remove them to unpresent cleanly.  I tried to reverse engineer his script, but it is a little over my head.

 

 

Any help?

Clone VM PowerCLI

$
0
0

I am using PowerCLI to manage, and I need to clone a virtual machine. I'm using the command:

 

 

New VM VM-fromVMname-name $ $ $ vmhost vmname-VMHost $ ds-datastore

 

But always returns me the error:

 

New-VM: 09/21/2012 11:48:56 New-VM The operation for the entity VirtualMachine-1440 failed with the follow ing message: "The operation is not supported on the object."

At C: \ Users \ Administrator \ Desktop \ test \ teste2.ps1: 20 char: 7

+ New-VM <<<<-VM-name $ $ fromVMname vmname-VMHost $ vmhost-datastore $

+ ds

     + CategoryInfo: NotSpecified: (:) [New-VM] NotSupported

     + FullyQualifiedErrorId: Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed, VMware.VimAutomati

    on.ViCore.Cmdlets.Commands.NewVM

 

Any suggestions?

Signature details of a package added to the depot via PowerCLI

$
0
0

Hello, Is there any cmdlet / parameter available to fetch the signature ( Whether it's signed or unsigned ) details of a package added to the depot?

 

Thanks,

Krishnaprasad

powercli command to add cpu cores to the cpu?

$
0
0

i know that the command for add cpu is -NumCpu  ... but whats the command to add x numbers of cores to the cpu?

 

Thanks for your help

I need to run this command in all ESXi servers 5.0.1

$
0
0

I need to run this command "esxli system syslog reload" in all the ESXi servers, need a powerli script.

Viewing all 16717 articles
Browse latest View live


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