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

Need help with RDM script to set them to Perennially Reserved

$
0
0

So I found this script to set the RDMs to Perennially Reserved, however, we have probably 15-20 VMs with RDMs so doing this manually can be tough.  I'd like to be able to have PowerCLI build a list of all the RDMs. 

 

I tried to build a foreach loop around the existing one one to detect all the RDMs from the multiple VMs using:  Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent but was unsuccessful. 

 

$vmName = "VMwithRDM"

$vm = Get-VM -Name $vmName
$rdm = Get-HardDisk -DiskType rawPhysical -Vm $vm
$vmhosts = Get-Cluster -VM $vm | Get-VMHost
foreach($esx in $vmhosts){
  $esxcli = Get-EsxCli -VMHost $esx  Get-HardDisk -DiskType rawPhysical -Vm $vm | %{    $esxcli.storage.core.device.list($rdm.ScsiCanonicalName) |    Select @{N="Time";E={"{0:g}" -f (Get-Date).TimeOfDay}},Device,IsPerenniallyReserved#    $esxcli.storage.core.device.setconfig($false,$rdm.ScsiCanonicalName,$true)    $esxcli.storage.core.device.list($rdm.ScsiCanonicalName) |    Select @{N="Time";E={"{0:g}" -f (Get-Date).TimeOfDay}},Device,IsPerenniallyReserved  }
}

 

Any help would be appreciated! 

 

Thanks,


Configure SSL for NFC (STIG) script

$
0
0

So this one is throwing me for a loop. Right now we have tons of ESXi 5.5 host that need the setting at "Administration >> vCenter Server Settings >> Advanced Settings" for "config.nfc.useSSL = true" to be set. However, I can't find anything as far as a powercli command or script that would accomplish that.

 

If I could have the one liner to set this value that would be a huge help! I can put together the rest of the loops and reading from a text file etc. Here is some more info: Verify that SSL Certificate Validation Over Network File Copy Is Enabled 

Thanks in advance! Huge help!

Script to change ESXi host password via vCenter

$
0
0

Hi All,

Is there a way to change all of my ESXi passwords from vCenter, the conditions ares

1.i have to run powercli connect vCenter

2. Show the new password from source file

need a clone a Linux VM and change hostname, IP,SM,GW

$
0
0

need a clone a Linux VM and change hostname, IP,SM,GW looking for automation. Please suggest.

Connect-VIServer - Permission to perform this operation was denied. Required privilege 'System.View' on managed object with id 'Folder-group-d1'.

$
0
0

A vCenter server 5.5 was replaced with a VCSA 6.5 U3.

I have some Powershell/PowerCli jobs that connect to the VCSA server and fail with an error like:

 

Connect-VIServer Permission to perform this operation was denied. Required privilege 'System.View' on managed object with id 'Folder-group-d1'.

 

The use used to logon can connect to the VCSA interactively and perform all the required actions.

Should I presume a VCSA permission issue or a PowerCLI (currently 5.8.0.xxx version) issue?

Regards

marius

Export All Alarms and definitions from VCenter.

$
0
0

I found the following article which helps but its not exactly what I am looking for. Script to export Alarms from VCenter to analyze. I am looking to export all alarms and definitions to csv, not just the alarms with just actions set. 

From the screen shot above, if possible I am looking to export the Name\Description\Trigger Events.


Any help is much appreciated.

 

Thanks,

Chris

Looking for a PowerCLI script to get the ESXi hosts all the NIC driver and firmware version

$
0
0

Looking for a PowerCLI script to get the output of ESXi hosts all the NIC driver and firmware version (ESXi OS 6.0 and 6.5). Script should have ability to capture the host names from a input file and save the output in .csv format with date in file name.

 

Thanks in advance.

digital_signature_powercli

$
0
0

Hi Luc,

 

I  have one file  .psm1 with multiple functions which i want to upload to a internal share  where others can download and use it .

i want to make sure that that content  is not modified once other use them .

could you suggest the simplest way of digitally sign that .psm1 file

i have following powershell version

 


Opening a window to save a file using FolderBrowserDialog

$
0
0

Hello,

 

So I'm trying to introduce a GUI option to save a file when exporting an OVF.  I have this in my script:

 

[System.Reflection.Assembly]::LoadWithpartialName("System.windows.forms") | Out-Null
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowser.Description = "Select a folder"
$FolderBrowser.rootfolder = "MyComputer"
$FolderBrowser.SelectedPath

$result = $FolderBrowser.ShowDialog()
$result

if($result -eq "OK") {
Write-Host "Selected Location:" -ForegroundColor Green
$FolderBrowser.SelectedPath
}
else {Write-Host "File Save Dialog Canceled" -ForegroundColor Yellow
  &$commands
}

 

However when the prompt comes up it's only really showing me what's on the local machine.  From googling around I haven't found much to create a browse button to a network share and if a user has a mapped drive to a share that's easy to do, however I don't want to assume the user has a mapped drive.  I'd like for them to be able to use something like SaveFileDialog, but just able to put a folder instead of a file so the OVF is saved off.  Is there something else in FolderBrowserDialog I'm missing that will work with this or do I need to use SaveFileDialog but somehow modify it so it works with just allowing me to select a folder?

configure wsus downstream server in vm using Invoke-VMScript

$
0
0

I am trying to configure wsus downstream server on windows 2016 & 2012 machines with the below script  but  unable to invoke values in the variable  (upstream server IP and port number).

These are the variables

$susdaywus='susday2555.'

$portnumber='8530'

 

$vmsautodeploy=$inputfile |?{$_.serverroles -eq 'WUS'}
#Install-WindowsFeature -Name UpdateServices, UpdateServices-WidDB, UpdateServices-Services, UpdateServices-RSAT, UpdateServices-API, UpdateServices-UI
$wusfeatureinstall=@'
Install-WindowsFeature -Name UpdateServices, UpdateServices-WidDB, UpdateServices-Services, UpdateServices-RSAT, UpdateServices-API, UpdateServices-UI
'@
Invoke-VMScript -VM $vmsautodeploy.VMName -GuestUser $vmsautodeploy.UserName -GuestPassword $vmsautodeploy.Password -ScriptType Powershell -ScriptText $wusfeatureinstall
$susdaywus='susday2555.corp.ncr.com'
$portnumber='8530'
$wsusdownstreamserversetup= @'
$erroractionpreference="Continue" 
$error.clear() 
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null 
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer(); 
$wsusConfig = $wsus.GetConfiguration() 
$wsusConfig.SyncFromMicrosoftUpdate=$false 
$wsusConfig.UpstreamWsusServerName= $susdaywus
$wsusConfig.UpstreamWsusServerPortNumber=$portnumber 
$wsusConfig.IsReplicaServer=$True 
$wsusConfig.TargetingMode="Client" 
$wsusConfig.Save() 
$wsusSub = $wsus.GetSubscription() 
$wsusSub.SynchronizeAutomatically=$True 
$wsusSub.SynchronizeAutomaticallyTimeOfDay="12:00:00" 
$wsusSub.NumberOfSynchronizationsPerDay="1"  
$wsusSub.Save() 
$wsusSub.StartSynchronization()
'@
$wsusdownstreamserversetupSub = $ExecutionContext.InvokeCommand.ExpandString($wsusdownstreamserversetup) 
Invoke-VMScript -VM $vmsautodeploy.VMName -GuestUser $vmsautodeploy.UserName -GuestPassword $vmsautodeploy.Password -ScriptType Powershell -ScriptText 

 

Command to tell what vCenter you are connected to

$
0
0

Is there a PowerCLI command to display which vCenter(s) you are connected to?

Little help here with "NoGuestControl"

$
0
0

I created a NetworkAdapter  with "New-NetworkAdapter", and got this:

ConnectionState: Connected, NoGuestControl, StartConnected

How can I change it to "Connected, GuestControl, StartConnected"?

Get-Stat for the last week is null

$
0
0

For some reason, my get-stat is coming up null for the last week and I am not sure what is going on. vCenter and Hosts were just patched and rebooted as well.

 

Realtime is fine

get-stat -stat mem.usage.average -entity $vm -realtime

 

 

Just the normal command is fine.......but it only displays stuff from last month and before.....which I thought was odd

 

get-stat -stat mem.usage.average -entity $vm

 

But when I try to do last 7 days it is null

 

get-stat -stat mem.usage.average -entity $vm  -start (get-date).adddays(-7) -finish (get-date) |GM

 

 

I use this same script several other places and it all works fine, I am just trying to figure out what might this different.

 

Thanks

Deploy from template gets error: 'Location' expects a single value

$
0
0

I have one vCenter server with multiple clusters as described below...

 

yomama

jomama

 

Each cluster has a bunch of folders and they BOTH have the folder called 'Discovered virtual machine'.

 

I need to deploy my VM from a template but I need to target the specific cluster but when I try the below command.....

New-VM -Name doooofus -Template win2016x64 -Datastore superdoooperfast_ssd -Location "Discovered virtual machine" -ResourcePool yomama -DiskStorageFormat Thin

 

I get the below message....

"The specified parameter 'Location' expects a single value, but your name

criteria 'Discovered virtual machine' corresponds to multiple values."

 

But the VM deploys BUT it is in the root of the cluster.

 

How do I tell it explicitly what cluster to put my vm in and put it in the folder called 'Discovered virtual machine' in that specific cluster?

 

Thanks

PowerCLI to access Cluster Level DRS imbalance information?

$
0
0

I did a quick search on the forums here and only found some folks asking for CPU/MEM/Disk stats.

I'm reading through the vSphere 6.7 Clustering Deep Dive and I'm going through the DRS section.

In the past, I wanted to find a way to collect DRS information to see what it is doing.  Not reservations, or limits, but more around entitlements.  A cluster may be imbalanced but unable to satisfy that imbalance because of "XYZ".    I could log into the vCenter client and hit the Cluster/DRS window to see recommendations (if any exist) but that does not give me all of the data.

 

Is there anyway, via API, PowerCLI, SSH, that can give me "Normalized Entitlement" or CHLSD-Current Host Load Standard Deviation for each host in a cluster?

Maybe this is bubbled up into vRops?

 

I understand, we should not care about this information and should just let DRS take care of things.  But, I love data, and being able to see an imbalance, even if slight, with trending analysis would be interesting.  Knowing I can adjust the slider to be more aggressive and it would balance VMs without a mass vmotion storm every evening would be great.  Even more so, being able to create automation around imbalance metrics (cross cluster) would be amazing...

 

Nick


Does this error have to do with the vCenter version?

$
0
0

Hello,

 

I recently wrote a script with the help of LucD to be able to scan a vCenter if it has multiple datacenters or not.  If it has more than 1 it prompts to choose, if not then the script moves forward.  In this instance I'm having an issue when there's more than 1 datacenter.  For whatever reason it works fine on my vCenter (6.5), but when running on a 6.0 vCenter it throws up an error, but still completes.  PowerCLI version is 10.1.1 on the machine I test on and the one that the script is being run from.  Both are Windows 10 RS4 and have PowerShell 5.1 as well.  Below is the error:

 

 

Get-Cluster : 11/15/2018 4:29:24 PM     Get-Cluster             VMHost parameter: Could not find any of the objects specified by

 

name.

 

At C:\Users\admin\Desktop\GenSeriallyMigrateFromHostToHost.ps1:44 char:33

 

+ Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Tabl ...

 

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

 

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], O

 

   bnRecordProcessingFailedException

 

    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore

 

   .Cmdlets.Commands.GetCluster

 

 

 

Get-Cluster : 11/15/2018 4:29:25 PM     Get-Cluster             VMHost parameter: Could not find any of the objects specified by

 

name.

 

At C:\Users\admin\Desktop\GenSeriallyMigrateFromHostToHost.ps1:44 char:33

 

+ Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Tabl ...

 

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

 

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], O

 

   bnRecordProcessingFailedException

 

    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore

 

   .Cmdlets.Commands.GetCluster

 

 

 

Get-Cluster : 11/15/2018 4:29:25 PM     Get-Cluster             VMHost parameter: Could not find any of the objects specified by

 

name.

 

At C:\Users\admin\Desktop\GenSeriallyMigrateFromHostToHost.ps1:44 char:33

 

+ Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Tabl ...

 

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

 

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], O

 

   bnRecordProcessingFailedException

 

    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore

 

   .Cmdlets.Commands.GetCluster

 

Below is the initial code, where the last line is line 44 that's referenced in the error:

 

$commands = { #This is the top of the loop, if you hit C at the end of the script it will take you back here
$dc = Get-Datacenter #This gets the datacenters, if more than 1 it will ask you which one to choose, if only one it will move forward in the script

if ($dc.Count -gt 1) {

  Write-Host "I found $($dc.Count) datacenters"
  Write-Host "Choose a datacenter"

  1..($dc.Count) | %{
   Write-Host "$_ - $($dc[$_ - 1].Name)"

   }
   $answer = 0
   while (1..($dc.Count) -notcontains $answer){
   $answer = Read-Host -Prompt "Select a datacenter (1-$($dc.Count))"
  
   }
}

Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Table #Gets the clusters in the datacenter

 

So is it something that needs to be changed somehow to accommodate different vCenter versions?  I thought this script would work pretty well between versions of vCenter/ESXi.  Is there that much of a difference?  I'm tempted to build my own setup that has 6.0, 6.5 and 6.7 just to see how differently the scripts behave.

 

Virtual Distributed Switch Report

$
0
0

Hi,

 

I am trying to write a script that will report on my Virtual Distributed Switches.  My Script is as follows:

 

$reportcsv = @()
Get-VdsDistributedPortgroup | Sort Name -Descending |
  ForEach-Object {
    $vdsportgroup = $_
$vdsportgroupsec = $vdsportgroup | Get-VdsDVPortSecurityPolicy
$Report = "" | Select-Object "Port Group Name","Number of Ports","Port Binding","Virtual Switch","VLAN Id","VLAN Type","AllowPromiscuous","MAC Changes","Forged Transmits"
$Report."Port Group Name" = $vdsportgroup.Name
$Report."Number of Ports" = $vdsportgroup.NumPorts
$Report."Port Binding" = $vdsportgroup.PortBinding
$Report."Virtual Switch" = $vdsportgroup.VirtualSwitch
$Report."VLAN Id" = $vdsportgroup.VlanId
$Report."VLAN Type" = $vdsportgroup.VlanType
$Report."AllowPromiscuous" = $vdsportgroupsec.AllowPromiscuous
$Report."MAC Changes" = $vdsportgroupsec.MacChanges
$Report."Forged Transmits" = $vdsportgroupsec.AllowPromiscuous
$reportcsv += $Report
  }

 

The script works, however when I view the contents of $reportcsv the values for AllowPromiscuous, MacChanges & ForgedTransmits shows up as VMware.VimAutomation.VdsComponent.Types.V1.BoolPolicy.

 

Does anyone have any suggestions?

 

Thanks

Frank

Retrieving the vDS Distributed switch version for all the ESXi host in the cluster

$
0
0

Hi All,

 

Can we retrieve the  vDS  Distributed switch version  for all the ESXi host in the cluster with ESXi host name, version and Cluster name ?

 

 

Thanks

vmk

Remove old Snapshots

$
0
0

Hello,

I use to remove old snapshots with this script where I pute VM name and then run:

 

$vmlist = Get-Content C:\Users\gemela\Desktop\sv.txt
 foreach($VM in $VMlist) { 
Get-Snapshot -VM $vm | 
Remove-Snapshot -Confirm:$false } 
Disconnect-VIServer -Confirm:$false

 

I would like to set this script in a different way, to delete only snapshots older than X days except VM inside a txt list or except snapshots where name/description contain some specific word.

 

Thanks

control and action in function_powercli

$
0
0

Hi Luc,

 

good morning,

 

could you review following code i am trying to combine both control (getting snapshot) and control(deleting snapshot) in same function .

do you recommend such practice and if not what could be the issues?

also for some reasons $snap1 is not being displayed on console that is very weired.

 

 

function get-snapshot_deletesnpshot_utilities

{

 

 

 

 

    [cmdletbinding()]

 

    param (

 

        [parameter(mandatory = $true,

 

            valuefrompipeline = $true,

 

            valuefrompipelinebypropertyname = $true)]

 

       

        [string]$filepath

 

 

 

    )

    $csv=Import-Csv "$filepath\clusters.csv"

   

 

foreach($line in $csv)

{

 

    $cluster=Get-Cluster $line.cluster

 

 

 

 

 

 

$vms=get-vm -Location $cluster

$snap1=$vms|Get-Snapshot|select @{N='snapshot';E={$_.name}},@{N='vmname';E={$_.vm}},@{N='datecreated';E={$_.created}}

$snap=$vms|get-snapshot

$snap1

if($snap -ne $null)

 

{

 

$res=read-host "do yu want to delete snapshot y/n"

if($res -eq 'y')

{

write-host "deleting snapshot"

$snap|remove-snapshot -WhatIf

 

}

}

}

}

Viewing all 14549 articles
Browse latest View live


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