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

Schedule Snapshot with PowerCli

$
0
0

Hi All,

 

I there any way to use PowerCli to schedule a snapshot? I'm looking to built a script to take user inputs such as Vm name, snapshot name, snapshot date, etc. to schedule a snapshot. I'm hoping to create a simple webpage to take some user inputs and pass it to script. I saw some examples that use PowerShell to create schedule task but they are all about creating a windows scheduled task. I would like to create the task as you would create in vSphere.

 

Thanks,

Haluk


See number of paths per LUN per host

$
0
0

Hi

 

I've seen so many scripts these past days on how to check my storage connections, but I still don't get the info I'm searching for. I would like to see per host for each LUN (RDM / Datastore) the number of paths. I have found scripts that show me the active paths, dead paths and working paths, but none of these helps me to see the number of paths per host.

 

The following script from Luc Dekens seems to be a good starting point, but again this only shows totals per hba, I need it per host per lun.

 

$esx = Get-VMHost vcdvm580.virtualcenter.lan

foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){

     $target = ((Get-View $hba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target

     $luns = Get-ScsiLun -Hba $hba  -LunType "disk"

     $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum

     Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths

}

 

Any help would be appreciated.

 

Gabrie

Add VM IP and vCenter name to script

$
0
0

Hi all,

 

I have an script and would like to add the vms ip and the vcenter name to it.

I'll run it over multple vcenter inside a foreach loop, i'm still working on it, but is failing right now, for only one host without the foreach look works fine:

 

 

$hosts = @("IPs");

 

 


$a = "<style>"

$a = $a + "BODY{background-color:white;}"

$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"

$a = $a + "TH{border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"

$a = $a + "TD{border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color:white}"

$a = $a + "</style>"

 

if($global:defaultviservers){

   Disconnect-VIServer -Server $global:defaultviservers -Force -Confirm:$false

}


$output = foreach($vcin$hosts){


Write-Host ("Getting Cluster Information from $hosts")

Connect-VIServer$vc -User "P.VXRAUTOMAT.01" -Password "xxx"

Get-Datacenter -PipelineVariable dc |

Get-Cluster -PipelineVariable cl -ErrorAction SilentlyContinue |

Get-Datastore -PipelineVariable ds|

Get-VMHost -PipelineVariable VMHost |

Get-VM -PipelineVariable vm |

Select-Object@{N='Datacenter';E={$dc.Name}},

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

@{N="Host Memory Size GB";E={[math]::Round($VMHost.ExtensionData.Hardware.MemorySize/1073741824)}},

@{N="Host Num CPU Cores";E={$VMHost.ExtensionData.Hardware.CpuInfo.NumCpuCores}},

@{N="ESXi Host";E={$vm.VMHost}},

@{N="VM Name";E={$vm.Name}},

@{N="VM Power State";E={$vm.PowerState}},

@{N="VM CPU";E={$vm.NumCpu}},

@{N="VM Memory GB";E={$vm.MemoryGB}},

@{N="VM OS";E={$vm.Guest}},

@{N="VM Folder";E={$vm.Folder}},

@{n="VM HardDiskSizeGB";E={[math]::Round((Get-HardDisk -VM $vm | Measure-Object -Sum CapacityGB).Sum)}},

@{N="VM UsedSpaceGB";E={[math]::Round($vm.UsedSpaceGB,1)}},

@{N="VM Datastores";E={

$script:vmds = Get-View -Id $vm.DatastoreIdList -Property Name,Summary.Capacity,Summary.FreeSpace

$script:vmds.Name -join '|'}},

@{N='VM Datastores CapacityGB';E={

[math]::Round(($script:vmds.Summary.Capacity | Measure-Object -Sum | Select -ExpandProperty Sum)/1GB,0)}},

@{N=" VM Datastores UsedSpaceGB";E={

[Math]::Round((($script:vmds.Summary.Capacity | Measure-Object -Sum | Select -ExpandProperty Sum)-($script:vmds.Summary.FreeSpace | Measure-Object -Sum | Select -ExpandProperty Sum))/1GB,0)}},

@{N='VM Datastores FreeGB';E={

[math]::Round(($script:vmds.Summary.FreeSpace | Measure-Object -Sum | Select -ExpandProperty Sum)/1GB,0)}}


}

 

$output |ConvertTo-Html -Head $a | Out-File C:\Users\nicolas.porta\Desktop\$hosts1.htm -width 400


Disconnect-VIServer * -Confirm:$false


Invoke-Expression C:\Users\nicolas.porta\Desktop\$hosts1.htm

 

Importing VM Tags from CSV file

$
0
0

I've been struggling to complete a massive import task of assigning upwards of a dozen categories of tags to a few thousand VMs.

I've started by using Alan Renouf's code to begin the process but I'm only successful at importing one or two categories before the script unexpectedly ends. Anyone else have suggestions?

Check My Code

$
0
0

Hey guys

Is there anyway yall can check this code and let me know if there is any errors or anything I can change. The purpose of the code is to deploy an OVF template then connect it to an already created switch. I have yet to get the OVF Template into its final directory so the source entry is just a place holder. Here's the code:

 

$csv_data =Import-Csv"Desktop\names.csv"-Header Student, Username

 


foreach($line in$csv_data){

   $first =$_.Description.split(",")[0]

   $last =$_.Description.split(" ")[1]

   Import-vApp-Source " "-Name "Ubuntu-$first"-Location $resourcepool -VMHost eng-vserv4.nmsu.edu -Force Thin -server vcenter1.nmsu.edu


   New-VirtualPortGroup-Name "BasicConnect"-VirtualSwitch $last$first

   New-NetworkAdapter-VM "Ubuntu-$first"-DistributedSwitch $last$first -NetworkName "VM Network"-Portgroup "BasicConnect"-PortId 1

}

Get Hardware info

$
0
0

Hello,

I would like to get host hardware info, something like this but with more information:

 

Get-VMHost |Sort Name |Get-View | Select Name, @{N=“Type“;E={$_.Hardware.SystemInfo.Vendor+ “ “ + $_.Hardware.SystemInfo.Model}}, @{N=“CPU“;E={“PROC:“ + $_.Hardware.CpuInfo.NumCpuPackages + “ CORES:“ + $_.Hardware.CpuInfo.NumCpuCores + “ MHZ: “ + [math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}}, @{N=“MEM“;E={“” + [math]::round($_.Hardware.MemorySize / 1GB, 0) + “ GB“}} | ` Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\VM_CLuster_Host_Datastore.csv

 

What I need is:

 

Hostname

Cluster

Cpu Model

Cores for Cpu

Logical Processors

Vendor

Model

Speed

Memory GB

Network Nic Count 1Gb/s (Management, Production,Backup)

SAN FC

Local Disk

Active?

Available

 

Is possible to get all info in one script?

 

Thanks

add vCheck script to task scheduler

$
0
0

Hello,

the goal is to add vcheck.ps1 to a scheduled task on a server, I need to do the following:

 

I am using PoweCLi 6.5

 

1- run the PoweCLi.

2- connect to the vcenter server (I have a PS1 script that has the connect-viserver along with the credentials)

3- run vCheck.ps1 script.

 

I've read many articles but not working for my scenario, so what's the least-administrative-effort approach to accomplish this please?

 

I can load PowerCLi but couldn't add more scripts to the sequence.

 

Thanks.

Need a script to scan hosts on a vCenter and see what datastores are mounted to each one

$
0
0

Hello,

 

I'm trying to figure this out, but not having much luck so far.  I'm cleaning up a vCenter (patching hosts, removing vSwitches and port groups and unused datastores) to move some hosts to a new vCenter.  I just want to be able to scan all the hosts in the vCenter and get a text file or csv file that shows me what NFS datastore are mounted on each host.  I haven't had much luck on google and trying this isn't working well for me.  I know if I do something like this:

 

Get-Datacenter -Name MyDatacenter | Get-VMHost -Name hostname | Get-Datastore | where {$_.type -eq "NFS"} | Format-Table I will get a result for the host.  However it only shows me the name of the datastore, the free space and capacity.  It doesn't tell me what host it's attached to which I really want.  I saw this thread: powershell script that can pull  NFS datastore info mounted from VC host

 

but it didn't do anything for me.  I also found the following code on another thread but for the vSwitch info (from LucD):

 

&{foreach($esx in Get-VMHost){

    $vNicTab = @{}

    $esx.ExtensionData.Config.Network.Vnic | %{

        $vNicTab.Add($_.Portgroup,$_)

    }

    foreach($vsw in (Get-VirtualSwitch -VMHost $esx)){

        foreach($pg in (Get-VirtualPortGroup -VirtualSwitch $vsw)){

            Select -InputObject $pg -Property @{N="ESX";E={$esx.name}},

                @{N="vSwitch";E={$vsw.Name}},

                @{N="Active NIC";E={[string]::Join(',',$vsw.ExtensionData.Spec.Policy.NicTeaming.NicOrder.ActiveNic)}},

                @{N="Standby NIC";E={[string]::Join(',',$vsw.ExtensionData.Spec.Policy.NicTeaming.NicOrder.StandbyNic)}},

                @{N="Portgroup";E={$pg.Name}},

                @{N="VLAN";E={$pg.VLanId}},

                @{N="Device";E={if($vNicTab.ContainsKey($pg.Name)){$vNicTab[$pg.Name].Device}}},

                @{N="IP";E={if($vNicTab.ContainsKey($pg.Name)){$vNicTab[$pg.Name].Spec.Ip.IpAddress}}}

        }

    }

}} | Export-Csv report.csv -NoTypeInformation -UseCulture

 

 

So I feel like that could possibly work, though I'm not quite sure what to change to what exactly to do the datastore tab.  I'm assuming I'd change $vNicTab to $vDatastoreTab and probably the Get-VirtualSwitch to Get-Datastore, but other than that I wouldn't know where to begin.  Can anybody help with this?

 

Thanks.


pipeline_powercli

$
0
0

Hi Luc,

 

could you check following screenshot .

here it started with get-vm command and continue using pipeline for filtering poweredon vms.after that one more pipe to get datastore .

is it possible to change the object type from virtualmachine to datastore .

$_ will remain vmobject till the end of pipeline or can it be altered??

 

 

 

Can't use http when doing connect-viserver

$
0
0

Hi experts,

I am trying to use Connect-VIServer with http. Whatever server and username/password are specified, I always get the error below.

 

PowerCLI C:\> Connect-VIServer -Server 101.207.40.46 -Protocol http -User foo -Password ****

Connect-VIServer : 10/19/2018 1:18:47 AM        Connect-VIServer                The provided URI scheme 'http' is invalid; expected 'https'.

Parameter name: via

At line:1 char:1

+ Connect-VIServer -Server 101.207.40.46 -Protocol http -User foo -Pass ...

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

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

    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

 

My PowerCLI configuration is below,

PowerCLI C:\> Get-PowerCLIConfiguration

 

 

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout

                                                                                                  Seconds

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

Session  UseSystemProxy  Multiple            Unset                     True                       300

User                     Multiple

AllUsers                 Single              Unset

 

I believe it's something wrong with my local settings.

Could anybody point out what the root cause is?

 

Thanks.

Martin

Execute SSH command to multiple ESXi Hosts in Parallel

$
0
0

Hi All,

 

I've written a PowerShell script witch leverages PoSH-SSH to execute a command on a host to get some NSX VDR stats which can only be obtained via shell command.

 

Currently it loops through an array of hosts, executes the command and stores the output into PSObject which I then build a report from. It all works perfectly however I would like for it to run in parallel against all 10 hosts.

 

I use the following posh command

 

$data = Invoke-SSHCommand $ssh -Command "Shell Command"

 

I was think I need to run jobs because the session need to remain open and I need to execute the command every 2 mins, can anyone please assist, I don't know anything about jobs.

Task/Events for a ESX or VM: PowerCLI script

$
0
0

Hello All,

 

Please can someone suggest a script that copies all the Task/Events entries of a VM or ESX to html or excel sheet and mail it. It should be particular server not all servers in vCenter.

 

Thanks,

Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section."

$
0
0

I have a problem running PowerCLI as a non-Administrator user.

 

When I run Import-Module VMware.VimAutomation.Core I get the following error

 

Exception calling "OnImportModule" with "2" argument(s): "Error creating the Web Proxy specified in the

'system.net/defaultProxy' configuration section."

At C:\Program Files

(x86)\VMware\Infrastructure\PowerCLI\Modules\vmware.vimautomation.core\VMware.VimAutomation.Core.ps1:1 char:1

+ [VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory]::CoreService.OnImportMo ...

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

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ConfigurationErrorsException

 

I also get the following error when running Connect-VIServer vcenter01

 

connect-viserver : 19/10/2018 17:08:51    Connect-VIServer        Error creating the Web Proxy specified in the

'system.net/defaultProxy' configuration section.

At line:1 char:1

+ connect-viserver vcenter01

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

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

    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets

   .Commands.ConnectVIServer

 

A connection to vcenter01 is not established.

 

If I make the user I am logged on as an Administrator of the Workstation I am running the Powershell from then it works without this issue. Any idea how to resolve this?

 

 

Question regarding Move-Vm

$
0
0

Hi,

Background,
I need to move alot of VM's from cluster A to cluster B. Cluster A and B have shared storage. Easy enough i thought and tried to use Move-VM. 

Problem:
The VM's are located in Resourcepools. It looks like i can't do something like,

Move-VM -VM $VMs -Destination ClusterB -Destination ResourcePoolB

Parameters on Move-VM states "Specify a folder, host, cluster, or a resource pool where you want to move the virtual machines."
From that i understand that what im trying to do is not doable, i have to pick on of them.

Anyone have a suggestion?

Datastore folder renaming

$
0
0

Hi gurus.

 

I have a few folders within a datastore that I would like to rename to "foldername_Old" , I have quite a few of this folders so I was thinking of reading a text file and then match the name and then rename the folders adding the "_Old", is this possible using PowerShell CLI.

 

has anyone done this before that can help me

 

I am very new to this CLI but learning little by little so go easy on me.


move-vm is not working as expected with PowerCLI 6.4 or higher

$
0
0

Hi all,

trying to move a VM to a specific folder. vCenter is 6.5 U2c in ELM with another vCenter (same version).

For some reason move-vm cmdlet is not working correctly - it's not moving VM to a specified folder. If I use the older PowerCLI 6.3 it's moving the VM correctly. So basicaly, old syntax -Destination is working, and the new syntax -InventoryLocation is not. Am I missing something obvious?

For example, with PowerCLI 10, trying to move vm1 from vApps folder to test1 folder - no error messages, but VM is still in the same folder:

PS C:\> get-vm "vm1" | select Folder

Folder
------
vApps


PS C:\> get-folder "test1"

Name                           Type
----                           ----
test1                          VM


PS C:\> move-vm -VM "vm1" -InventoryLocation "test1"

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
vm1                  PoweredOn  1        1.000


PS C:\> get-vm "vm1" | select Folder

Folder
------
vApps

PS C:\> Get-Module VMware.PowerCLI -ListAvailable | ft -AutoSize


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version       Name            ExportedCommands
---------- -------       ----            ----------------
Manifest   6.5.4.7155375 VMware.PowerCLI

 

 

 

Example with PowerCLI 6.3 R1, works fine:

=================================================

PowerCLI C:\> get-vm "vm1" | select Folder

Folder
------
vApps

PowerCLI C:\> move-vm -VM "vm1" -Destination "test1"

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
vm1                  PoweredOn  1        1.000


PowerCLI C:\> get-vm "vm1" | select Folder

Folder
------
test1

How to get the Virtual Machine Tasks completed time using PowerCLI

$
0
0

Friends,

 

I am trying to get the task completed time for a particular task type using Powercli. Any help appreciated.  I am getting StartTime of the Tasks using Get-VIEvent . How to get the Task completion time for a particular VM.

 

I am looking for a Backup Job status for all VM's in the vCenter, whether the backup job is successful / failed from the last 24 hrs.

 

 

I am able to get the particular task and start time using below command

 

Get-VM <VM Name> | Get-VIEvent | Where {$_.username -eq "username" -and $_.Info.DescriptionId -eq "task type" -and $_.CreatedTime -gt (Get-Date).AddHours(-24) }

 

Help is required to get the required task type completion time and completion status ( successful / failed / error )

 

Thanks,

Naga Suresh.

Setting a delay in powercli script for tagging hosts

$
0
0

Scenario is:  Tagging multiple hosts from my flat switch. I will lose connectivity to hosts until I plug in my startech device and assign the tag to it.  when the script runs it pretty much just stalls after the 1st host. I have tried removing the discconect-viserver.   /Any thoughts? see script below.   Looking for something that acts like nohup sleep command.   Also start-sleep is not what i need. 

 

$file_hosts = "c:\ps\ip.csv"

 

 

#Login Variables

$auth_usr = "root"

$auth_pwd = "Youwillneverknow"

 

 

#variables - Management network

$pg_ManageNet = "Management Network"

 

 

 

 

#variables - CVM network

$Host_CVM_VLAN = 3

$New_NamePortGroupCVM = "CVM_MGNT"

$pg_CVM = "VM Network"

   

  Import-csv $file_hosts | ForEach-Object {

    $host_ntnx = $_.hostntnx 

   

    Connect-VIServer -Server $host_ntnx -User $auth_usr -Password $auth_pwd -Force

    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue -Confirm: $false

    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm: $false

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "connected to" $host_ntnx

 

 

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Configuring CVM Portgroup for" $host_ntnx

 

 

    #Setting vSwitch0 Variable

    $VSwitch0 = Get-VirtualSwitch -VMHost $host_ntnx -Name "vSwitch0"

 

 

    #rename/tag CVM port group

    Write-Host "rename/tagging cvm portgroup"

    $VSwitch0 = Get-VirtualSwitch -VMHost $host_ntnx -Name "vSwitch0"

    $CVM_PortGroup_Config = Get-VirtualPortGroup -VMHost $host_ntnx -VirtualSwitch $VSwitch0 -Name $pg_CVM | Set-VirtualPortGroup -Name $New_NamePortGroupCVM -VlanId $Host_CVM_VLAN

   

    if($?)

{

Write-Host "******************************************************************"

Write-Host "******************************************************************"

  Write-Host "command succeeded"

Write-Host "******************************************************************"

Write-Host "******************************************************************"

  

}

else

{

Write-Host "******************************************************************"

Write-Host "******************************************************************"

   Write-Host "command failed"

Write-Host "******************************************************************"

Write-Host "******************************************************************"

}

 

 

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Configuring Host Portgroup for" $host_ntnx

 

 

    #Tag Management Network

    Write-Host "Tagging mgmt network"

    $TAGnetwork = Get-VirtualPortGroup -VMHost $host_ntnx -VirtualSwitch $VSwitch0 -Name $pg_ManageNet | Set-VirtualPortGroup -VlanId $Host_CVM_VLAN

   

 

 

        Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Finished DNS Config" $host_ntnx

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Disconnecting from" $host_ntnx

 

 

    Disconnect-VIServer -Server $host_ntnx -Confirm:$false

 

    }

VMware Management with PowerCLI 5.0

$
0
0

Download the PowerCLI 5.0 Poster from this post.

get-vm -tag gives a timeout with newer versions of PowerCLI

$
0
0

We use get-vm -tag <tagname> a lot with the Powershell Powercli module, but as of late we found out that it gives a timeout on some machines.

I have tried the latest powerclicore container (to rule out incompatibilities with older module versions) but that does also give a timeout.

 

Machines with older versions of the module (6.5) can still use this functionality.

 

I tried downgrading to 6.5, but on my machine it still gives a timeout.

 

Ideally I would start using PowerCLIcore so we can containerize our scripts (always the right version for the scripts) so my question is:

Has someone seen this working on the newer versions of PowerCLI (or knows what could be the problem)

 

Version 11 and 6.5 do not seem to work when downloaded with install-module

 

Best regards,

Sander

 

VMware ESXi, 6.5.0, 8294253

Vcenter 6.5.0 7312210

Viewing all 14549 articles
Browse latest View live


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