Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all 9071 articles
Browse latest View live

Add multiple baseline to ESXi host using powercli command

$
0
0

Friends

 

There are 2 predefined baseline in VUM 'Critical Host Patches (Predefined)' and 'Non-Critical Host Patches (Predefined)'. Please help me to modify below script so that it will add both baseline to ESXi host & remediate. in below script currently baseline 'ESXi-6.5.0-update01' is enclosed in it. i need all 3 baseline to be added to ESXi box and get host re mediated by each baseline.

 

write-host "!!! Please be Patient !!! $C maintenace mode is in progress ...."

Get-VMHost -Name $C | set-vmhost -State Maintenance | Select Name, State

$Baseline = Get-Baseline -Name 'ESXi-6.5.0-update01'

Add-EntityBaseline -Entity $C -Baseline $Baseline

Test-Compliance -Entity $C

Get-Compliance -Entity $C -Baseline $Baseline

#Update-Entity -Baseline $baseline -Entity $C -RunAsync -Confirm:$False

 

Thanks

Sooraj


Automating patching of Windows Templates - strange error on 2012 R2..

$
0
0

So, last friday I was about to patch templates in different systems, and this time it needed some special care for Spectre/Meltdown patches and workarounds. Figured I may as well finally start scripting this procedure as it needed to be repeated on several templates. Most of this is done with Invoke-VMScript and the use of different powershell modules, and utilize some pre-standardisation of our templates (same DVD drive letter, same user/password, script in c:\install etc.).

 

In broad terms, the script (in it's current revision) does the following:

- Checks for powered on VMs in folders named "Templates" that has guestID matching "windows"

- Adds registry value so January security patches gets installed (No AV in base image, except Windows Defender)

- Adds NuGet package provider

- Installs PSwindowsupdate PS Module

- Downloads all windows updates (filtered if needed)

- Install all Windows Updates and reboots the machine

- Runs DISM with some parameters to ensure a small image

- Maps the ISO for VMware Tools and runs the installation silently, then dismounts the CD

- Shutting down the VM when complete

.. everything is logged to c:\temp\<name of VM>.txt

 

I have been trying to figure out why some VMs work, and some don't. Often the failure is due to problems with powershell, and I'm guessing that is because the machine is not logged on (or have some intrusive patch installed).

 

The errors I get are these:

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:47 char:77
+ ... osoft.PowerShell.Management\Join-Path -Path $env:LOCALAPPDATA -ChildP ...
+                                                 ~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

The variable '$script:PSGetAppLocalPath' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:48 char:86
+ ... werShell.Management\Join-Path -Path $script:PSGetAppLocalPath -ChildP ...
+                                         ~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (script:PSGetAppLocalPath:String) [], RuntimeException    + FullyQualifiedErrorId : VariableIsUndefined

The variable '$script:PSGetAppLocalPath' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:51 char:81
+ ... werShell.Management\Join-Path -Path $script:PSGetAppLocalPath -ChildP ...
+                                         ~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (script:PSGetAppLocalPath:String) [], RuntimeException    + FullyQualifiedErrorId : VariableIsUndefined

WARNING: The property 'Values' cannot be found on this object. Verify that the property exists.
WARNING: The property 'Keys' cannot be found on this object. Verify that the property exists.
WARNING: The variable '$script:PSGetModuleSourcesFilePath' cannot be retrieved because it has not been set.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PSWindowsUpdate'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

 

So far, it seems to be working if the console is logged on, or if the OS is 2008 R2.

Here's the script (it has no error handling or much intelligense yet, but it does the job..)

 

$guestuser = "administrator"
$guestpass = "password"
$skipupdates = "KB4033369,KB4033342"
$toolspath = "[Isofiles] VMware/VMware Tools/10.2.0/vmtools/windows.iso"

if( $Host -and $Host.UI -and $Host.UI.RawUI ) {
    $rawUI = $Host.UI.RawUI    $oldSize = $rawUI.BufferSize    $typeName = $oldSize.GetType( ).FullName    $newSize = New-Object $typeName (120, $oldSize.Height)    $rawUI.BufferSize = $newSize  }

Clear-Host

foreach ($vm in (Get-Folder Templates | Get-VM | Sort-Object Name | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.guestid -match "windows" })) {
    Write-Host Processing: $vm.name    $file = "c:\temp\$($vm.name).txt"    $now = get-date    add-content $file "Actions started on $now"    Write-host " - Adding registry values for Spectre/Meltdown patches"    add-content $file "Adding registry values for Spectre/Meltdown patches"    $output = Invoke-VMScript -vm $vm -ScriptText "reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat /v cadca5fe-87d3-4b96-b7fb-a231484277cc /t REG_DWORD /d 0 /f" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType bat    add-content $file $output    Write-host " - Installing NuGet package provider"    add-content $file "Installing NuGet package provider"    $output = Invoke-VMScript -vm $vm -ScriptText "Install-PackageProvider nuget -force" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType PowerShell    add-content $file $output    Write-host " - Installing PSWindowsUpdate module"    add-content $file "Installing PSWindowsUpdate module"    $output = Invoke-VMScript -vm $vm -ScriptText "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; Import-Module PowerShellGet; Start-Sleep -Seconds 10; Install-Module -Name PSWindowsUpdate -force -scope AllUsers" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType PowerShell    add-content $file $output    if ($skipupdates -eq "") {        Write-host " - Downloading all Windows Updates"        add-content $file "Downloading all Windows Updates"        $output = Invoke-VMScript -vm $vm -ScriptText "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; Import-Module PSWindowsUpdate; Start-Sleep -seconds 10; Get-WindowsUpdate -Download -Verbose -AcceptAll" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType PowerShell        add-content $file $output        Write-host " - Installing all Windows Updates"        add-content $file "Installing all Windows Updates"        $output = Invoke-VMScript -vm $vm -ScriptText "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; Import-Module PSWindowsUpdate; Start-Sleep -seconds 10; Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install -AutoReboot -Verbose" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType PowerShell        add-content $file $output    } else {        Write-host " - Downloading all Windows Updates, except $skipupdates"        add-content $file "Downloading all Windows Updates, except $skipupdates"        $output = Invoke-VMScript -vm $vm -ScriptText "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; Import-Module PSWindowsUpdate; Start-Sleep -seconds 10; Get-WindowsUpdate -Download -Verbose -AcceptAll -NotKBArticleID $skipupdates" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType PowerShell        add-content $file $output        Write-host " - Installing all Windows Updates, except $skipupdates"        add-content $file "Installing all Windows Updates, except $skipupdates"        $output = Invoke-VMScript -vm $vm -ScriptText "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; Import-Module PSWindowsUpdate; Start-Sleep -seconds 10; Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install -AutoReboot -NotKBArticleID $skipupdates -Verbose" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType PowerShell        add-content $file $output    }    Write-Host " - Waiting 180 seconds for reboot to complete"    Start-Sleep -Seconds 180    Write-host " - Running cleanup script"    add-content $file "Running cleanup script"    $output = Invoke-VMScript -ToolsWaitSecs 360 -vm $vm -ScriptText "c:\install\cleanup.cmd" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType bat    add-content $file $output    Write-Host " - Upgrading VMware Tools"    add-content $file "Upgrading VMware Tools"    Get-CDDrive -vm $vm | Set-CDDrive -IsoPath $toolspath -Connected:$true -Confirm:$false | Out-Null    Write-Host "  - Waiting for ISO to be mounted"    Start-Sleep -Seconds 15    $output = Invoke-VMScript -ToolsWaitSecs 360 -vm $vm -ScriptText "Z:\setup64.exe /s /v ""/qn REBOOT=Force ADDLOCAL=ALL REMOVE=Hgfs""" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType bat    add-content $file $output    #sleep added due to vmware tools upgrade trashing the connection    Write-Host "  - Waiting five minutes for VMware Tools installation to complete"    Start-Sleep -Seconds 300    Write-Host "  - Dismounting ISO file"    Get-CDDrive -vm $vm | Set-CDDrive -NoMedia -Connected:$false -Confirm:$false | Out-Null    Write-host " - Shutting down the VM"    add-content $file "Shutting down the VM"    $output = Invoke-VMScript -vm $vm -ScriptText "shutdown /s /f /t 10 /d p:0:0" -GuestUser $guestuser -GuestPassword $guestpass -ScriptType Bat    add-content $file $output
}

 

Have anyone else encountered problems with Invoke-VMScript and powershell?

(Note, I could prepare a BAT/CMD that does all the above, but this can be used for other purposes as well when automating customer patching later on)

 

Message was edited by: Andreas Cederlund Forgot to edit out password :-)

Ping host from ip list with powershell

$
0
0

Hello, I would like to ping some or all host in vcenter in some specific time, Is possible to do by script?

PowerCLI 6.5.4 Malware detection

$
0
0

I tried installing PowerShell 6.5.4. I received an error with the attached content.

Is there someone who is receiving the same event?

Windows Defender reports false positive for PowerShell Modules

$
0
0

Over the weekend, Microsoft released a Windows Defender signature file that falsely reports many PowerShell modules, including PowerCLI as containing a virus.

This is a FALSE POSITIVE widely affecting the PowerShell community.

https://social.technet.microsoft.com/Forums/en-US/40fa56dd-b73f-456a-9d97-cdb4500bc7ed/latest-updates-indicated-peasectoa-infection-?forum=WindowsDefenderATPPreview

There is no official statement from Microsoft yet, but the PowerCLI community on VMware {Code} has been working overtime! Here’s what you need to do to get back to automating:

  1. Update Windows Defender Signatures to the latest (>= 1.261.424.0).
  2. If your PowerShellGet module was affected, you may need to download manually from Github (https://github.com/PowerShell/PowerShellGet)
    1. Update: Kevin Marquette has a pretty good workaround for PowerShellGet, which reverts back it back to 1.0.0.1.
  3. Release the affected files from Quarantine, or reinstall PowerCLI (Install-Module VMware.PowerCLI -scope CurrentUser -force)

This story is still developing, so I will update as the info comes in.

This is a great time for a shout out to the PowerCLI community on VMware {Code}. Special thanks to the PowerCLI users that have been working on this over the weekend and this morning: Luc Dekens, Edgar Sanchez, Wouter Kursten, Scott Haas, and John Kavanagh

You can join the VMware {Code} Slack by signing up here: https://code.vmware.com/join

 

Any further updates will be here:

Windows Defender reports false positive for PowerShell Modules - VMware PowerCLI Blog - VMware Blogs

PowerCLI - Clear Alarm

$
0
0

Hi all,

 

We recently found our hosts were susceptible to this issue.  After applying the vCenter update to resolve this going forward, we went through all the affected VMs with VMware's PowerCLI script.  The result is that every single VM fixed by this script now has a 'vSphere HA virtual machine failover failed' alarm triggered.

 

I figured it would be quite simple to write a script to run through all our VMs, and clear the alarm if the triggered date or alarm type matched certain criteria.

 

I would highly recommend exposing this functionality through PowerCLI.  I am quite surprised that we will need to manually clear these alarms - was trying to force myself to not use the GUI.

 

Thanks!

 

 

 

 

On a side note, it might be worthwhile to update the post found here:

http://communities.vmware.com/message/1869541

 

The code there is missing a line break:

 

$alarmMgr = Get-View AlarmManager Get-VM | where {$_.ExtensionData.TriggeredAlarmState} | %{    $vm = $_    $vm.ExtensionData.TriggeredAlarmState | %{        $alarmMgr.AcknowledgeAlarm($_.Alarm,$vm.ExtensionData.MoRef)    }
}

 

Should be

 

$alarmMgr = Get-View AlarmManager #note the previous code missed a line break here

Get-VM | where {$_.ExtensionData.TriggeredAlarmState} | %{
    $vm = $_    $vm.ExtensionData.TriggeredAlarmState | %{        $alarmMgr.AcknowledgeAlarm($_.Alarm,$vm.ExtensionData.MoRef)    }
}

Transmitted Packet drops for a VM

$
0
0

Hi Team ,

 

I wanted to know if there is a way to get transmitted packet drops for a VM , I know the stat is available through powercli for host however checking if its available for a VM as well.

 

I can see the values for VM through Realtime Performance graphs

 

Thanks!

need to create an Alarm in multiple VM using pcli

$
0
0

Dears

I need to create an Alarm in multiple VM. using Pcli

Many thanks


Connect-HVServer Could not find user

$
0
0

Even after using recent version of view and powercli we are still seeing below error while trying to connect to connection broker

 

Connect-HVServer : ExceptionType : VMware.Hv.EntityNotFound

ErrorMessage : Could not find user or group in AD

Id : VMware.Hv.UserOrGroupId

At line:1 char:1

 

Have created new user account and added directly to view admin but still same error.

 

Any resolution or workaround is greatly appreciated

 

Thanks 

Get VMs with Tag Like and export csv just vm name

$
0
0

Hi,

 

I would like to export in csc the list of my vm who have a specific tag.

i can do that but the powercli command extract the vm with all properties,

so i would like just the name of my vms.

i 'm blocked with this powercli command :

Get-VM|where {(Get-TagAssignment-Entity$_|Select-ExpandPropertyTag) -like'tag-1*'} | Export-CSV C:\Scripts\result\vms-tag-1.csv

 

thank you for your help.

Ping host and get result for X hours

$
0
0

Hello, This is relate to my previous PostPing host from ip list with powershell

 

I need to use this script (if possible) to ping some hosts for X hours  for example each 5 minutes, and get result in a file,

 

Result file need to have date/time and if host is Up or Down

 

GC C:\Users\gemela\Desktop\Ping\hnames.txt | %{
If (Test-Connection $_ -Quiet -Count 2){
"$_ is UP"
}
Else{
"$_ is Down"
}
} | Out-File C:\Users\gemela\Desktop\Ping\ping_result.txt

 

 

Thanks

Script to verify activation of VM Windows License

$
0
0

I have deployed over 50 VM's via powercli Script and noticed the customization on some of the VM's didn't activate windows license. Is it possible to run a powercli script on these 50 VM's to see which VM's completed with windows activated or not? This would save loads of time without having to check every VM individually. 

Using plink.exe in Powershell script returns "Unable to create scratch directory"

$
0
0

Hello,

I wrote this powercli script in order to update the HP Smart array P840 firmware and driver of my HP DL380 G9s. I am currently running ESXi 65U1 and vSAN 661.

I staged the files with another script so assume they are already on the hosts chomod'd and unzipped.

 

The VIB installation works just fine but when this part of the code runs I get an error stating: "unable to create scratch directory"

$cmd1 = @'

'/tmp/CP032780.vmexe --rewrite --force --silent --log-dir=/tmp'

'@

I also tried to stage the files in a datastore as opposed to root with the same message being returned:

$cmd1 = @'

'/vmfs/volumes/datastore1 (5)/files/CP032780/CP032780.vmexe' --inventory --log-dir=/tmp

'@

 

This is the command output. The ./_hp_scexe_info does not exist anywhere. I'm presuming the command can't write to either /tmp or /vmfs/...

Capture.PNG

Here is a detailed ls of both directories.

post 2.PNG

permissions for the exe

-rwxr-xr-x    1 root     root         27408 Jan 30 19:25 CP032780.vmexe

-rw-r--r--    1 root     root      12460831 Jan 30 19:25 CP032780.vmfile

-rw-r--r--    1 root     root        370802 Jan 30 19:25 CP032780.xml

 

I forgot to mention that either command works in an SSH session.

 

You can see the entire script here, in my github page.

https://github.com/Coolguydoesnotlookatexplosions/vmware-utils/blob/master/Executeremotecommands.ps1

 

LucD tagging as i have seen him post some on plink.

everyday storage bool size reduced, and i dont know why, i have to increase the storage size every day, Please some help me

$
0
0

everyday storage bool size reduced, and i dont know why, i have to increase the storage size every day, Please some help me

HYPE TEST!

$
0
0

Are you ready for the PowerCLI Beta?


Get Number of VM CPU and Cores

$
0
0

Hi

 

I've tried the following but cannot get the number of VM CPU and Cores. What am I doing wrong?

 

 

 

 

Setting svga.vramSize with New-AdvancedSetting

$
0
0

Hi

I got a problem setting the vram size of the video Card. I'm using PowerCLI 6.5 lattest release. If i type "New-AdvancedSetting -Entity $vm -Name svga.vramSize -Value 32768000 -confirm:$false" nothing happens. In my VCSA I can see the reconfigure task, but there is no change at my VM.

 

Has anyone a hint for me?

-Finish parameter in Get-Stat (not getting any output)

$
0
0

I am trying to get historical data for VMs from ESXi using PowerCLI.

 

When I use the following cmdlet:

 

Get-Stat -Entity IPMVMCloudVM -stat cpu.usage.average -Start (Get-Date).AddDays(-25) -Finish (Get-Date).AddDays(-24)

 

I do not get any data, but when give only -Start parameter I get data.

Get-Stat -Entity IPMVMCloudVM -stat cpu.usage.average -Start (Get-Date).AddDays(-25)

 

I don't know why am I getting this issue. Logically this should work.

Report Generation of VMs

$
0
0

Hi All,

 

Currently we are trying to generating report on VMs allocation with respect to Teams.

 

Each VM will be having a custom attribute as Team and corresponding team name is entered.

 

In below example I am illustrating the set of VMs belongs to 3 Teams.

 

Team: X

Setab01

Setab02

Setab03

Setab04

 

Team: Y

Setcd01

Setcd02

Setcd03

 

Team: Z

Setef01

Setef02

 

Team: X

Setgh01

Setgh02

 

Sample Output Needed:

 

Team                      Number of Sets               Number of VMs

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

X                                       2                                        6

Y                                       1                                        3

Z                                       1                                        2

 

Below script is returning only VM Set with respect to Number of VMs of each set

 

 

$vmnames=Get-VM

$vmname=$vmnames.name.substring(0,5) |Group-Object  |selectName,Count

$vmad= @()

foreach($vin$vmname){

    $vmcount=$v.count

    $vmd=""|select"VM Set","VMs Count"

    $vmd."VM Name"=$v.name

    $vmd."VMs Count"=$vmcount

    $vmad+=$vmd

}

$vmad

 

Ex: Output

 

VM Set                     VMs Count

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

Setab                                   4

Setcd                                   3

Setef                                    2

Setgh                                   2

 

I am not able to get the desired output, Could some one help me.

PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

$
0
0

Hello All,

 

I have done some serious googling, and am about to accept that it is not possible through PowerCLI.

But I wanted to make a last effort by asking you guys.

 

For ESXi host maintenance, I want to use a PowerCLI script which does this:

 

  1. - disable alarm actions on Cluster
  2. - disable alarm actions on Hosts

  3. - perform maintenance (can be anything, but will include host reboots)

  4. - enable alarm actions on Hosts
  5. - enable alarm actions on Cluster

 

Because we have 300+ ESXi hosst, you can imagine I want to do this scripted.

 

Is there any way to disable/enable alarm actions through PowerCLI ?

 

Thanks and kind regards,

 

Harold

Viewing all 9071 articles
Browse latest View live


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