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

update vmware tools status

$
0
0

is it possible to get a status on mass vmware tools upgrade?

 

get-content vms.txt | % { update-tools -VM $_ - noreboot -runasync}

 

when i run this I only see this

 

Screen Shot 2017-07-18 at 10.41.30 AM.png


Snapshots report

$
0
0

Hello, I would like to run a script to get snapshots list (csv) with: Who created (user) When (date) Snapshot name and description, Host and VM name., Space in Gb or Mb, Datacenter/Cluster I use RvTools  but with this tool I can't get who created. Thanks

Need PowerCLI script to list all the fibre channel HBAs and WWNs and WWPNs for each HBA for each of the ESXi hosts connected to a vCenter ... not sure where to start

$
0
0

Hi all,

 

I need a PowerCLI script: for each of the ESXi hosts connected to a vCenter, for each fibre channel HBA on that ESXi host: list the fibre channel WWNs and WWPNs of that HBA.

 

I'm not sure where to start.

 

 

Thanks in advance for your help!

 

-Chris

Having Severe Issues with VI TK 1.5

$
0
0

 

When I try and connect to a VC using Get-VC or Connect-VIServer I recieve an exception error as shown below.  The issue is just not limited to just connecting to a VC but just about any cmdlet within the VI toolkit.   I have tried to remove and reinstall .NET 2.0, VI Toolkit, Powershell and the VIC.  None of which corrects the issue.

 

 

 

 

 

cmdlet Connect-VIServer at command pipeline position 1

Supply values for the following parameters:

Server[0]: VC01

Server[1]:

Connect-VIServer : The type initializer for 'VMware.VimAutomation.Logging.SoapI

nterceptor.LoggingHelper' threw an exception.

At line:1 char:17

+ Connect-VIServer <<<<

    + CategoryInfo          : NotSpecified: (, TypeInitia

   lizationException

    + FullyQualifiedErrorId : System.TypeInitializationException,VMware.VimAut

   omation.Commands.ConnectVIServer

 

 

 

 

 

Disable a Hardware Sensor

$
0
0

I have a ProLiant DL360p Gen8 running esxi 6.5 with a memory sensor problem. VMware shows two info/errors under the Memory rollup, and these get relayed to our SolarWinds monitor and show as red flagged errors with host memory and kick off alerts.

 

I have asked about the memory messages and have been told they are not critical and can be safely ignored, but the reporting itself is causing problems. Is there anyway to disable these two sensors or kill the reporting that riles up Solarwinds?

 

 

I haven't found a way to disable through the webclient, and the scripts I've seen enumerate HealthStatusSystem but don't seem to have a set feature anywhere to disable, ON/OFF, a sensor.

only local server local file path is supported for offline bundle

$
0
0

any idea why I am getting this error with esxcli from powercli?

 

Screen Shot 2017-07-19 at 7.59.47 AM.png

How do I get all VMs for a VIserver

$
0
0

Hi,

 

I import module vmware.powercli, then issue a Connect-VIServer -server MyVMVIServer.acme.com and after I enter my creds, im connected on port 443.

 

I can issue a Get-VM myvmbox -Server MyVMVIServer.acme.com -Location somedatacenter and I get info about myvmbox, however is there a way to just give me all the VMs and their properties under a VIServer such as MYVMVIServer the way I can do with Powershell using a filter like 'Get-AdDomainController -Filter *' which will give me everything.

 

This is a new install of VMWare with NSX which im not really familiar with, so wondering how I can get all VMs returned.

 

Thanks in advance.

Network data transfer for a VM

$
0
0

Hi all, I need to establish some figures for a VM running under vCenter 5.5 in preparation for moving to AWS. I gather there is a tool called Stats Toolbox which I have downloaded. However I'm have a few problems getting it to work so I thought I'd better check that it will provide the information I need before spending any more time on it.

 

Will Stats Toolbox give me a a figure for the amount of data transferred in or out of a VM over its network interface? A monthly or weekly figure would be perfect.

 

Thanks


Finding Lun details using powercli

Using get-view, how to get guest VMs on a vmhost or in a cluster/datacenter, when the parents were also retrieved via get-view

$
0
0

Hi LucD et al.  -

 

In my functions, I am trying whenever possible to substitute get-view for get-vm (and get-vmhost, get-cluster, get-datacenter, etc.), because it's soooo much faster.

 

I still can't figure out the equivalent to:

$ get-vmhost | get-vm

 

For example, if I have a vmhost object retrieved via get-view, how do I pipe that (or otherwise reference it) to get all the guests on that host?

$ Get-View -ViewType HostSystem -Filter @{Name="hostname.domain.local"}  | get-view -ViewType VirtualMachine  # this does not work, obviously

 

(and yes, I'd add -Property once I figured out which properties I need )

 

I'm on 6.5.0.2, if that makes any difference.

 

Thanks!

Paula

Multiple Virtual Network Adapters on VM - How to Map to Corresponding Windows Network Adapters?

$
0
0

Hi All,

 

(ESXi 6.0. standlone)

I have a Windows Server 2012 VM that Im trying to setup via script.

This VM has 4 Network Adapters: VM Network, Something0, Something1, Application.

 

The OVA is deployed and then the VM is sysprepped before initial login.

Once logged in, I look at the network adapters in Windows and see 4 adapters, each with a name "Ethernet #". The placement of the Virtual NIC -> Windows NIC seems to be different each time, presumably because of sysprep.

 

Via script, Im can rename and enable the VMware Virtual Adapters to their specific portgroup and StartConnected,

but Im not sure how to map the corresponding VMware Adapters that I rename with the default "Ethernet #" Windows adapters

 

Any help would be greatly appreciated

 

Thank you

Invoke-VMscript to create local user on Windows 2012r2 Guuest

$
0
0

I am trying to use the invoke-vmscript to create a local user on a 2012r2 Guest. I have tried 2 different methods both unsuccessfully. Below are those methods. Any guidance would be greatly appreciated. I plan to switch to use a PSCredential instead of standard user and password inputs once I get this working. .

 

Script 1

This script calls a PS script saved on the local C drive of the guest. I receive an access denied error. If I run the script locally with an elevated PowerShell prompt it works. How can I run PowerShell through the invoke-vmscript elevated? The user account I use to access the guest is a local admin.

 

#variables

$user = "test"

$userpw = "Thisismypasswordin2017!"

$script = "C:\scripts\create_local_user.ps1 -username $user -password $userpw"

 

#Executing the Script
#Connect to vCenter
Connect-viserver $vcenter -User $vcenter_user -Password $vcenter_password

#Creating the local User account via the invoke command
Write-Host "Creating local user account"
Invoke-VMScript -VM $bserver -ScriptText $script -GuestUser $adminaccount -GuestPassword $adminpw

 

 

create_local_user.ps1

param (
[Parameter(Position=0,Mandatory=$True,HelpMessage="the desired username you want to create")]
[ValidateNotNullOrEmpty()]
[string]$username,

[Parameter(Position=1,Mandatory=$True,HelpMessage="the account's desired password")]
[ValidateNotNullOrEmpty()]
[string]$password

)

 

$prov = [adsi]"WinNT://localhost,computer"
$user = $prov.Create("User", $username)
#obvious
$user.SetPassword($password)
# set to not expire and not allow changing of password
$user.userflags = 65536 -bor 64
#commit the change
$user.SetInfo()

#add them to the users group
$group = $prov.Children.Find("Users", 'group')
#cant't use the same syntax as you see up above
$group.Add(("WinNT://$env:COMPUTERNAME/$username"))

 

 

Error Output

ExitCode     : 0
ScriptOutput : Exception calling "SetInfo" with "0" argument(s): "Access is denied.
               "
               At C:\scripts\create_local_user.ps1:21 char:1
               + $user.SetInfo()
               + ~~~~~~~~~~~~~~~
                   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
                   + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

               Exception calling "Add" with "1" argument(s): "A member could not be added to
               or removed from the local group because the member does not exist.
               "
               At C:\scripts\create_local_user.ps1:26 char:1
               + $group.Add(("WinNT://$env:COMPUTERNAME/$username"))
               + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
                   + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

 

 

 

 

Script2

This attempt I installed WRM 5.1 on the 2012r2 guest so I could get the Microsoft.PowerShell.LocalAccounts Module. Whether I run the command through the invoke-vmscript or locally in the guest I get the same error. The only difference between script 1 and script 2 is the variable $script.

 

$script = "Microsoft.PowerShell.LocalAccounts\New-LocalUser -Name $user -Password $userpw -PasswordNeverExpires -UserMayNotChangePassword"

 

Error Output

ExitCode     : 0

ScriptOutput : New-LocalUser : Cannot bind parameter 'Password'. Cannot convert the

               "Thisismypasswordin2017!" value of type "System.String" to type

               "System.Security.SecureString".

               At line:1 char:74

               + ... s\New-LocalUser -Name test -Password Thisismypasswordin2017!  -Passwo ...

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

                   + CategoryInfo          : InvalidArgument: (:) [New-LocalUser], ParameterB

                  indingException

                   + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh

                  ell.Commands.NewLocalUserCommand

Output All VM Names and MAC Addresses from Multiple vCenters to CSV

$
0
0

Hi,

 

I'm looking to generate a query that queries multiple vCenters and outputs a CSV in the following format:

 

vCenter Name | Cluster Name | VM Name | VM MAC Address

 

My script draft is as follows, but I don't fully understand how the Select statement is formated.

 

$MAC_Address_Report = foreach($vc in $global:DefaultVIServers){   
$vCList = $vc
$vCCluster = get-Cluster
$vmList = get-VM
$MAC_Addr = get-VM PNA* | Get-NetworkAdapter

Select @{N="vCenter";E={$vCList.Name}} @{N="Cluster";E={$vCCluster.Name}}, @{N="VM Name"; E={$vmList.Name}}, @{N="MAC Address";E={$MAC_Addr.MacAddress}}
}

$MAC_Address_Report| Export-Csv C:\Scripts\VM_MAC_Address_Inventory.csv

Enum all datastores by cluster and host for unmap

$
0
0

I am currently working on a script to do a vmfs unmap across a wide number of datastores. I have a script for doing it against a single datastore, and it works well, but in this case I have hundreds to touch, so this is my thought process:

  • Loop through every cluster in the datacenter and grab the first vmhost returned.
  • Perform a Get-Datastore on that host to pull all the datastore names
  • Connect to that vmhost and loop through all the datastores to perform the unmap cleanup

 

Attached is my script thus far:

$aHosts = @()
$report = @()
$aClusters = Get-Datacenter "MyDC" |                            Get-Cluster |                                Select Name


foreach($sCluster in $aClusters) {
    $sHost = Get-VMHost -Location $sCluster.Name |                                    Select -First 1 |                                             Select Name    $aHosts += $sHost
}


foreach ($sHost in $aHosts | Sort Name) {
    $sStore = Get-VMHost $sHost.Name |                         Get-Datastore |                                Select Name                           $report += $sStore.Name
}


$report | Out-GridView

 

First and foremost, as I am still learning with PowerCLI, while this works I wonder if there is not a simpler way to accomplish this through a better pipeline call than splitting it out into two for loops. I attempted to do so but unsuccessfully. Secondly, the output I get has just the datastore name. I have tried a couple different ways of getting the hostname and the datastore name with each pass, but it doesn't come out the way I would expect. My end goal, as I stated, would be to have for each VMHost a list of its datastores, so I can cycle through them. Any suggestions would be welcome.

PowerCLi

$
0
0

Hi All,

 

Can somebody Hel me  how to find CPU Usage percentage and Memory Usage percentage of ESX Host via PowerCLI command or script?

Note : I want usage level in terms of percentage.


Stopping script from running in lockdown mode

$
0
0

I am trying to find a way to stop the script from continuing to run when in lockdown mode or any other circumstances This script I'm using now does stop the script from continuing to run, however it only stops if the wrong credential or IP address is stated, it doesn't stop if the vSphere host is in lockdown mode. It will give this error (picture below) and still continuining to run the script with errors.

Capture.PNG

 

So this is the code I am using:

param (

[Parameter(Mandatory=$true)][string]$s,

[Parameter(Mandatory=$true)][string]$u,

[Parameter(Mandatory=$true)][string]$p

)

 

function connect-server {

    #Connecting to server

    Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

    $serverin = $s

    $userin = $u

    $passin = $p

    $error.clear()

    Connect-VIServer -Server $serverin -User $userin -Password $passin

  

    $serverlist = $global:DefaultVIServer

  

    if($serverlist -eq $null) {

        write-host "No connected servers."

        BREAK

        } else {

        foreach ($server in $serverlist) {

            $serverName = $server.Name

            if($serverName -eq $serverin){

                write-Host "Connected"

                scoringsystem

                } else {

                write-host "Something did not work right. Please try again"

            }

        }

    }

}

PowerCLI 6.5 - Get-VMConfigChanges

$
0
0

Hi,

 

When I run the command Get-VMConfigChanges I get error message "The term 'Get-VMConfigChanges' is not recognized as the name of a cmdlet.

 

I have seen that I need to inject the cmdlet into PowerCLI, any ideas what I need to run to do this?

 

Thanks

snapshot a vm using perimeterized script.

$
0
0

Hi all ,

need some help in following syntax of powercli to create snapshotof vm .

 

 

function take-snapshot

{

[cmdletbinding()]

param(

[parameter(mandatory=$true)]

[string]$virtualmachine

 

 

)

 

 

param(

[parameter(mandatory=$true)]

[string]$name

 

)

 

$snapshot=New-Snapshot -VM $virtualmachine -Name $name  -Description "test3" -Verbose

 

}

 

can i have two param blocks for

1.virtual machine name

2:name of screen shot

 

all i want is when i run this function it should pop us  virtual machine name and then name of screenshot.

export-csv shows this

$
0
0

I am trying to get a list of my esxi host and version and export to csv but getting no data

 

Screen Shot 2017-07-24 at 7.12.39 AM.png

 

any idea?

 

get-datacenter xxx | get-vmhost | select NAme, @{N="version"; E={$_.extensiondata.config.product.fullname}} | ft -auto | export-csv file.csv

Cluster CPU Usage Average

$
0
0

Hello,

 

After I have read few topic related to this problem I found this script:

 

$stat = "cpu.usage.average"

$entity = Get-Cluster

$start = (Get-Date).AddDays(-7)

 

 

Get-Stat -Entity $entity -Start $start -Stat $stat |

Group-Object -Property {$_.Entity.Name} |

Select Name,

    @{N="CPU average";E={$_.Group | Measure-Object -Property Value -Average | Select -ExpandProperty Average}}

 

The problem is that I'm getting only 1 cluster in results and one of Vcenter have 2 cluster and second one 4 clusters.

Get-Cluster  is showing correct numer and name for clusters.

I've already try to modify this code but nothing seems to work. A littel bit of help please?

Viewing all 14549 articles
Browse latest View live


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