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

schedule

$
0
0

Hi guru

 

Very very new to CLI so go easy on me

 

I would like to make this small script to a psc1 file that I can run from a scheduled task

 

connect-VIserver -server

$Vms=Get-folder 'path' | get-vm | where-object {$_.powerstate -eq "poweredoff"}

get-vm $vms | start-vm

 

can anyone point me in the right direction, please

 

Thanks a bunch


Recompose Horizon Desktop Pools via PowerCLI

$
0
0

I have been trying to find a way to recompose our VDI Pools via PowerCli and find only references to old deprecated PowerCli commands.

 

Does anyone know how to kick off a recompose with the current version of PowerCli?

created local user but cannot login

$
0
0

I created a localuser on 6.5 esxi server but cannot login as user

 

 

connect-viserver -server esxiserver -user root -password "mypass"

New-VMHostAccount -Id test -Password "mypass" -UserAccount -GrantShellAccess -Server esxiserver

new-vipermission -entity -principal test -role admin -server esxiserver

 

any idea?

How to accomplish Get-VIevent from powercli via the API?

$
0
0

I am having trouble finding  the Get-VIEvent  equivalent in the vcenter   and vcenter server API.

Am I missing something?

Or is it not there, YET?

invoke a registry key for 32/64 bit OS

$
0
0

Hi

I am trying to fetch a registry value for AV. The reg value of agentguid is in different locations for 32bit and 64bit OS.

Here I want the information like if the OS is 64-bit write the reg value if not check for 32 bit path and write the value.

One more step if the OS is neither 32-bit or 64-bit and doesn't find the any registry value it should check the "McAfee Framework Service"  and write the status.

 

32-Bit:  [HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\]

64-Bit:  [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Agent\]

$testcode = @' 
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" |%{"$($_.AgentGUID)"} -ErrorAction SilentlyContinue
if(-not $text){     $text = Get-Service -Name "McAfee Framework Service" | %{"$($_.Name) is $($_.Status)"} 
}
$text
'@
$testout=Invoke-VMScript -VM "VM1" -GuestUser "administrator" -GuestPassword "admin@123"  -ScriptText $testcode -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
$testout 

 

Output for 64bit:

 

Connect-VIServer : Invalid URI: The hostname could not be parsed.

$
0
0

Hello folks,

I encountered error today on my code as shown error msg below, can someone help me on this pls?

Am trying to connect to multiple vcenter servers assigned to $VIServer variable.

 

 

Error:

Connect-VIServer : Invalid URI: The hostname could not be parsed.

At C:\PS_SCRIPTS\berns\getvminfo.ps1:30 char:1

+ Connect-VIServer $VIServer -User $user -Password $pass -WarningAction

SilentlyCo ...

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

~~~

    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], UriFormatE

   xception

    + FullyQualifiedErrorId : System.UriFormatException,VMware.VimAutomation.V

   iCore.Cmdlets.Commands.ConnectVIServer

 

 

Snippet:

# Credential

$user="dom\testid"

$pass="pass"

 

# All current Virtual Centers to check

$VIServer="vc1, vc2, vc3"

 

# Connect to Virtual Center servers

Connect-VIServer $VIServer -User $user -Password $pass -WarningAction SilentlyContinue |out-Null

PowerCLI + Horizon + smartcard Authentication

$
0
0

In our production environment administrators need to use smart cards to authenticate.  I'm trying to automate some recomposes via a powercli script and can't figure out a way to get the script to connect.  Has anyone run into this?

How do I get Extensiondata.guest.disk.capacity to generate total disk capacity on one line in script

$
0
0

Good afternoon;

Have modified this script originally created by Lucd.   For the life of me I cannot figure out how to get a grand total in GB the disk capacity for each vm.  Any all input would be appreciated.

 

Thank you

 

Norm

 

 

$VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

 

 

     ForEach ($VM in ($Datacenter | Get-VM | sort |  where {$_.powerstate -match "on"} | Get-VMGuest)) {

 

 

        $vm | Select @{N="VM_NAME#";E={$vm.Hostname}} ,

 

 

            @{N="VM_CPU_Core#";E={$VM.VM.NumCPU}},

 

 

            @{N="VM_MemoryGB";E={$VM.VM.MemoryGB}},

 

 

           @{N="VM_DiskGB";E={$VM.VM.Extensiondata.Guest.Disk.capacity}},

 

 

            @{N="VM_IP#";E={$vm.IPAddress}},

 

 

            @{N="VM_OS";E={$vm.OSFullName}},

 

 

            @{N="VM_DC";E={$Datacenter.name}},

 

 

            @{N='VM_Cluster';E={(Get-Cluster -VM $VM.VM).Name}},

 

 

            @{N="VM_NOTES";E={$VM.VM.Notes}},

 

 

            @{N='VM_Annotations';E={(Get-Annotation -Entity $VM.VM).Value}}

 

 

           

 

 

 

 

 

     }

 

 

}

$VmInfo | Export-Csv -Path "d:\powershell_temp\report_vm_notes.csv" -NoTypeInformation -UseCulture    


Add a new PV SCSI controller via API

$
0
0

I'm trying to add a new PV SCSI controller to a VM without having to power off the VM and use new-scsicontroller.

 

I can't get my head around the correct items I need to provide to the spec using "New-Object = VMware.Vim.VirtualMachineConfigSpec" etc, I've found a few helpful articles online but it always seems to just attempt to modify scsi0 and throws an error, rather than adding a new controller.

 

Can anyone help?

Invoke vmscript to get windows hotfix information on multiple versions

$
0
0

Hi

 

I am trying to fetch windows hotfix installed status for multiple versions.Here the problem is the Hotfix number is not same to all the versions of windows. -Like (kb4056897 is for windows 2k8r2 which is not same for win2k12)

with the below script I can able get only one hotfix details at once. -Like (For kb4056897 it will invoke the script for all the windows machines and write the output for only 2k8r2 as this hotfix belongs to 2k8r2). So is there any possibility to pass multiple hotfix numbers in one variable ($hotfix=kb4056897,kb4056894 )and pass this cmd (Get-WmiObject -Class "win32_quickfixengineering") and search the hotfix numbers which we given in $hotfix and write the output.

$script = @'
$hotfixinfo=Get-WmiObject -Class "win32_quickfixengineering" |?{$_.HotFixID -eq "KB4049011"}|%{"$($_.HotFixID) is installed on $($_.InstalledOn)"}
$hotfixinfo
'@
Invoke-VMScript -VM $vm.name -GuestCredential $password1  -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput 

Error using Get-VIEvent cmdlet - Server 2016 / PS 5.1 / PowerCLI 6.5

$
0
0

Hi,

 

On a Windows 2016 server running PowerShell 5.1, I get the following error when calling Get-VIEvent:

 

get-vievent : 8/23/2017 5:15:07 PM Get-VIEvent Error in deserializing body of reply message for operation 'RetrieveProperties'.

At line:1 char:1

+ get-vievent

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

    + CategoryInfo          : NotSpecified: (:) [Get-VIEvent], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEvent

 

It works fine on a server running Windows 2012 r2 and PowerShell 5.

 

Thanks,

Joel

Specify datastore per disk on template clone

$
0
0

I have a template that I need to roll out multiple times through PowerCli.
The template has three seperate virtual disks.
I want the first disk to be on a DatastoreA and I want disks two and three to be stored on DatastoreB. 
I now simply clone everything using this command: 

new-vm -name MyNewVM -template MyTemplate

Can anyone point me in the right direction for specifying the datastore on a per-disk level?

Thanks!

Suspend multiple VMGuests at once

$
0
0

Hello all,

 

I'm tasked with creating a script to invoke the suspension of over 50 VM's (all Win2012r2) in a very narrow timeframe (probably between 5-8 minutes) following a UPS event.hutfown

 

Suspend over shutdown is the preferred option, but as there's no -RunAsync switch for this, I'd be grateful for any advice anyone could offer as to how to achieve this.pped

 

I have this snippet  for the SQL boxes working fine, but the servers suspend in sequence, rather than simultaneously.

 

$vms = Get-VM

Foreach ($vm in $vms){

     if ((Get-View $vm).Name -match "SQL"){

               Write-Host $vm.Name, " => " , (Get-View $vm).Guest.GuestFullName

               Get-VM $vm | Suspend-VMGuest -Confirm: $false

     }

}

 

Many thanks,

 

Tim

Query vCenter to list VMs with virtualHW.scheduledUpgrade settings

$
0
0

Dear Community,

 

We are in a situation where vMotion doesn't work with some of our VMs.

 

This is related to:

 

https://kb.vmware.com/s/article/2080107
(vMotion of virtual machine fails with the error: The destination host is not compatible with the hardware version to which the virtual machine is scheduled to be upgraded)

 

I'm a PowerCLI beginner and I'm looking for a script that can list all VMs which have the following strings in their vmx:

 

virtualHW.scheduledUpgrade.when
virtualHW.scheduledUpgrade.state
tools.upgrade.policy

 

This is the script I came up with so far:

 

Get-VM | Get-AdvancedSetting -Name "[setting_name]" |
Select @{N="VM";E={$_.Entity.Name}},Name,Value | Format-Table -AutoSize

 

I have 2 issues/questions with my script:

 

1) I can't seem to find what's the correct name of the settings I need to use in my script.

 

2) When testing the script with another setting, for ex. ctkEnabled, I get a list but the name of lots of VMs is hidden:

 

 

 

VM                             Name       Value

 

--                             ----       -----

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

VMtest1                  ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

VMtest2                 ctkEnabled TRUE

 

                               ctkEnabled TRUE

 

 

 

Thanks in advance for your help.

 

Get-VM -name C00LBF01 | Get-AdvancedSetting -Name "ctkEnabled" |

 

Select @{N="VM";E={$_.Entity.Name}},Name,Value | Format-Table -AutoSize

Retrieving Multiple Annotations in Script

$
0
0

We have previously had a script in place for some time that pulls our inventory plus a single annotation field. We run extracts weekly for sharing the state of our datacenter, but now we are adding additional annotation fields. As much as I've looked online I can't seem to properly add multiple annotation fields so that they show up as columns in the extracted CSV.

 

Previously we only looked to get the VM-Owner annotation now we are looking for things like Application, LastConfirmed, etc etc.

 

Here is our previous script,

add-pssnapin VMware.VimAutomation.Core

 

 

Connect-VIServer -Server XXXXXX -User XXXXXXX -Password XXXXXX

 

 

$targetCA = 'VM-Owner'

$report = @()

 

 

foreach($vm in Get-VM){

    $row = [ordered]@{

        VM = $vm.Name

Hostname = $vm.Guest.Hostname

IPAddress = $vm.guest.IPAddress[0]

CPU = $vm.NumCpu

RAM = ($vm.MemoryGB * 1024)

OperatingSystem = $vm.Guest.OSFullName

PowerState = $vm.PowerState

   

    }

    Get-Annotation -Entity $vm | where{$targetCA -contains $_.Name} | %{

        $row.Add($_.Name,$_.Value)

    }

    $report += New-Object PSOBject -Property $row

  

}

 

 

$report | Export-Csv 'c:\temp\scripts\export\vSphere_Export.csv' -NoTypeInformation -UseCulture


Check if the Datastore is detached or not using LUNID

$
0
0

Whenever we perform EOW of storage array controller, we are performing datastore migration from OLD datastore to NEW datastore.

After migraion, we are informing Storage team to reclaim those LUNs during that stage, they always double check with us, whether these LUNs can be reclaimed or not. We used to manually check, if these LUNs are detached or not and confirming them.

Always they used to give us LUN ID as below

isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000

isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000

isrtpxiv32     7811090_3b44 (thp_606)      RAID1      2     4388000

isrtpxiv32     7811090_3b45 (thp_607)      RAID1      3     4388000

 

Where LUN ID is = 01e2, 0d8d 3b44 3b45 and NAA ID will have these strings ex: NAA.6742b0f0000004530000000000003b45, NAA.6742b0f0000004530000000000003b44.

Now i want to automate this to avoid manual error.

Whenever they give as LUN ID, i would like to check, those string contains LUN(NAA ID) is in place or detached.

 

Please help me on this.

Always they used to give us LUN ID as below
isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000
isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000
isrtpxiv32     7811090_3b44 (thp_606)      RAID1      2     4388000
isrtpxiv32     7811090_3b45 (thp_607)      RAID1      3     4388000
 
Where LUN ID is = 01e2, 0d8d 3b44 3b45 and NAA ID will have these strings ex: NAA.6742b0f0000004530000000000003b45, NAA.6742b0f0000004530000000000003b44.
Now i want to automate this to avoid manual error.
 
Whenever they give as LUN ID, i would like to check, those string contains LUN(NAA ID) is in place or detached.
 
Please help me on this.

Generate CSV with Datastore Space Info from multiple VCs and Clusters

$
0
0

I'm looking to create a script that outputs a table of our hundreds of datastores, showing all the datastores:

 

  • capacity utilisation (%)
  • space provisioned (%)

 

The script needs to query multiple vCenters and would output something along the lines of:

 

vCenter Name | Cluster Name | Datastore Name | Datastore capacity (GB) | Datastore capacity (%) | Datastore Provisioned (%)

 

The script below explains what I want to do, but I don't know how to pull the data from both the get-Cluster and get-Datastore commands...

 

 

$report = Foreach($vcin$global:DefaultVIServers){

    foreach($dcinGet-Datacenter-Server$vc){

        Get-Cluster-Server$vc| Get-Datastore

        Select @{N='vCenter Name';E={$vc.Name}},

            @{N='Cluster';E={$_.Name}},

            @{N='Datastore Name';E={ds.Name}},

            @{N='Datastore Capacity (GB)';E={ds.CapacityinGB}},

            @{N='Datastore Capacity (%)';E={ds.CapacityinPC}},

            @{N='Datastore Provisioned (%)';E={ds.ProvisionedSpaceinPC}},

    }

}

$report | Export-CSV C:\Scripts\vCenterClusterDatastoreInfo.csv

Which PowerShell version do you now use?

$
0
0

To help us understand where to move in the future and what versions of PowerShell people are currently using on production machines please help by letting us know what version of PowerShell you currently use.

 

$psversiontable.PSVersion

 

Thanks

 

PowerCLI Team

What OS do you run natively on your primary work machine?

Answer types

$
0
0
What do you expect from an answer to your question(s) ? Should it be code that a beginner understands or code that provides the fastest solution in a large vSphere environment ?
Viewing all 16717 articles
Browse latest View live


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