Merge remote-tracking branch 'refs/remotes/vmware/master' into AlansBranch
This commit is contained in:
123
Modules/PSvLIMessage.psm1
Normal file
123
Modules/PSvLIMessage.psm1
Normal file
@@ -0,0 +1,123 @@
|
||||
add-type @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
public class TrustAllCertsPolicy : ICertificatePolicy {
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint srvPoint, X509Certificate certificate,
|
||||
WebRequest request, int certificateProblem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
|
||||
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Markus Kraus
|
||||
Organization: Private
|
||||
Personal Blog: mycloudrevolution.com
|
||||
Twitter: @vMarkus_K
|
||||
===========================================================================
|
||||
Tested Against Environment:
|
||||
vRealize Log Insight 3.3.1
|
||||
PowerShell Version: 4.0, 5.0
|
||||
OS Version: Windows 8.1, Server 2012 R2
|
||||
Keyword: vRealize, RestAPI
|
||||
|
||||
Dependencies:
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
|
||||
.SYNOPSIS
|
||||
Push Messages to VMware vRealize Log Insight.
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a Messages in VMware vRealize Log Insight via the Ingestion API
|
||||
|
||||
.EXAMPLE
|
||||
Push-vLIMessage -vLIServer "loginsight.lan.local" -vLIAgentID "12862842-5A6D-679C-0E38-0E2BE888BB28" -Text "My Test"
|
||||
|
||||
.EXAMPLE
|
||||
Push-vLIMessage -vLIServer "loginsight.lan.local" -vLIAgentID "12862842-5A6D-679C-0E38-0E2BE888BB28" -Text "My Test" -Hostname MyTEST -FieldName myTest -FieldContent myTest
|
||||
|
||||
.PARAMETER vLIServer
|
||||
Specify the FQDN of your vRealize Log Insight Appliance
|
||||
|
||||
.PARAMETER vLIAgentID
|
||||
Specify the vRealize Log Insight Agent ID, e.g. "12862842-5A6D-679C-0E38-0E2BE888BB28"
|
||||
|
||||
.PARAMETER Text
|
||||
Specify the Event Text
|
||||
|
||||
.PARAMETER Hostname
|
||||
Specify the Hostanme displayed in vRealize Log Insight
|
||||
|
||||
.PARAMETER FieldName
|
||||
Specify the a Optional Field Name for vRealize Log Insight
|
||||
|
||||
.PARAMETER FieldContent
|
||||
Specify the a Optional FieldContent for the Field in -FieldName for vRealize Log Insight
|
||||
If FielName is missing and FieldContent is given, it will be ignored
|
||||
|
||||
#Requires PS -Version 3.0
|
||||
|
||||
#>
|
||||
function Push-vLIMessage {
|
||||
|
||||
[cmdletbinding()]
|
||||
param (
|
||||
[parameter(Mandatory=$true)]
|
||||
[string]$Text,
|
||||
[parameter(Mandatory=$true)]
|
||||
[string]$vLIServer,
|
||||
[parameter(Mandatory=$true)]
|
||||
[string]$vLIAgentID,
|
||||
[parameter(Mandatory=$false)]
|
||||
[string]$Hostname = $env:computername,
|
||||
[parameter(Mandatory=$false)]
|
||||
[string]$FieldName,
|
||||
[parameter(Mandatory=$false)]
|
||||
[string]$FieldContent = ""
|
||||
)
|
||||
Process {
|
||||
$Field_vLI = [ordered]@{
|
||||
name = "PS_vLIMessage"
|
||||
content = "true"
|
||||
}
|
||||
$Field_HostName = [ordered]@{
|
||||
name = "hostname"
|
||||
content = $Hostname
|
||||
}
|
||||
|
||||
$Fields = @($Field_vLI, $Field_HostName)
|
||||
|
||||
if ($FieldName) {
|
||||
$Field_Custom = [ordered]@{
|
||||
name = $FieldName
|
||||
content = $FieldContent
|
||||
}
|
||||
$Fields += @($Field_Custom)
|
||||
}
|
||||
|
||||
$Restcall = @{
|
||||
messages = ([Object[]]([ordered]@{
|
||||
text = ($Text)
|
||||
fields = ([Object[]]$Fields)
|
||||
}))
|
||||
} | convertto-json -Depth 4
|
||||
|
||||
$Resturl = ("http://" + $vLIServer + ":9000/api/v1/messages/ingest/" + $vLIAgentID)
|
||||
try
|
||||
{
|
||||
$Response = Invoke-RestMethod $Resturl -Method Post -Body $Restcall -ContentType 'application/json' -ErrorAction stop
|
||||
Write-Information "REST Call to Log Insight server successful"
|
||||
Write-Verbose $Response
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Error "REST Call failed to Log Insight server"
|
||||
Write-Verbose $error[0]
|
||||
Write-Verbose $Resturl
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Modules/Vi-Module/README.md
Normal file
34
Modules/Vi-Module/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
##  <b>V</b>Mware <b>i</b>nfrastructure <b>Module</b>
|
||||
|
||||
### <ins>[Vi-Module.psm1</ins>] (https://github.com/vmware/PowerCLI-Example-Scripts/tree/master/Modules/Vi-Module)
|
||||
|
||||
To install this module, drop the entire '<b>Vi-Module</b>' folder into one of your module directories.
|
||||
|
||||
The default PowerShell module paths are listed in the `$env:PSModulePath` environment variable.
|
||||
|
||||
To make it look better, split the paths in this manner `$env:PSModulePath -split ';'`
|
||||
|
||||
The default per-user module path is: `"$env:HOMEDRIVE$env:HOMEPATH\Documents\WindowsPowerShell\Modules"`.
|
||||
|
||||
The default computer-level module path is: `"$env:windir\System32\WindowsPowerShell\v1.0\Modules"`.
|
||||
|
||||
To use the module, type following command: `Import-Module Vi-Module -Force -Verbose`.
|
||||
|
||||
To see the commands imported, type `Get-Command -Module Vi-Module`.
|
||||
|
||||
For help on each individual cmdlet or function, run `Get-Help CmdletName -Full [-Online][-Examples]`.
|
||||
|
||||
#### <b><ins>Vi-Module Cmdlets:</ins></b>
|
||||
|
||||
|No|Cmdlet|Description|
|
||||
|----|----|----|
|
||||
|1|<b>[Get-RDM</b>] (http://www.ps1code.com/single-post/2015/10/16/How-to-get-RDM-Raw-Device-Mappings-disks-using-PowerCLi)|Report all VM with their RDM disks|
|
||||
|2|<b>[Convert-VmdkThin2EZThick</b>] (http://www.ps1code.com/single-post/2015/11/05/How-to-convert-Thin-Provision-VMDK-disks-to-Eager-Zeroed-Thick-using-PowerCLi)|Inflate thin virtual disks|
|
||||
|3|<b>[Find-VcVm</b>] (https://cloud.githubusercontent.com/assets/6964549/17361776/d5dff80e-597a-11e6-85a2-a782db875f78.png)|Search VCenter VM throw direct connection to group of ESXi hosts. Thanks to <i>VMGU.ru</i> for the [article] (http://www.vmgu.ru/news/vmware-vcenter-how-to-find-powered-off)|
|
||||
|4|<b>[Set-PowerCLiTitle</b>] (http://www.ps1code.com/single-post/2015/11/17/ConnectVIServer-deep-dive-or-%C2%ABWhere-am-I-connected-%C2%BB)|Write connected VI servers info to PowerCLi window title bar|
|
||||
|5|<b>[Get-VMHostFirmwareVersion</b>] (http://www.ps1code.com/single-post/2016/1/9/How-to-know-ESXi-servers%E2%80%99-BIOSFirmware-version-using-PowerCLi)|Get a Firmware version and release date of your ESXi hosts|
|
||||
|6|<b>[Compare-VMHostSoftwareVib</b>] (http://www.ps1code.com/single-post/2016/1/10/How-to-compare-installed-VIB-packages-between-two-or-more-ESXi-hosts)|Compare installed VIB packages between two or more ESXi hosts|
|
||||
|7|<b>[Get-VMHostBirthday</b>] (https://cloud.githubusercontent.com/assets/6964549/12399803/c8439dfa-be24-11e5-8141-09199caa301e.png)|Get ESXi hosts' installation date. Thanks to <i>Magnus Andersson</i> for his [idea] (http://vcdx56.com/2016/01/05/find-esxi-installation-date/)|
|
||||
|8|<b>[Enable-VMHostSSH/Disable-VMHostSSH</b>] (http://www.ps1code.com/single-post/2016/02/07/How-to-enabledisable-SSH-on-all-ESXi-hosts-in-a-cluster-using-PowerCLi)|Enable/Disable SSH on all ESXi hosts in a cluster|
|
||||
|9|<b>[Set-VMHostNtpServer</b>] (http://www.ps1code.com/single-post/2016/03/10/How-to-configure-NTP-servers-setting-on-ESXi-hosts-using-PowerCLi)|Set `NTP Servers` setting on ESXi hosts|
|
||||
|10|<b>[Get-Version</b>] (http://www.ps1code.com/single-post/2016/05/25/How-to-know-any-VMware-object%E2%80%99s-version-Use-GetVersion)|Get VMware Virtual Infrastructure objects' version info: `VM`, `ESXi Hosts`, `VDSwitches`, `Datastores`, `VCenters`, `PowerCLi`, `License Keys`|
|
||||
120
Modules/Vi-Module/Vi-Module.psd1
Normal file
120
Modules/Vi-Module/Vi-Module.psd1
Normal file
@@ -0,0 +1,120 @@
|
||||
#
|
||||
# Module manifest for module 'Vi-Module'
|
||||
#
|
||||
# Generated by: Roman Gelman @rgelman75
|
||||
#
|
||||
# Generated on: 8/1/2016
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'Vi-Module'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'a5ad4817-fbef-41b9-b5e2-714a7a16fb26'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Roman Gelman @rgelman75'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Taldor Israel'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2016 Roman Gelman @rgelman75. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'VMware Virtual Infrastructure Management functions'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
PowerShellVersion = '3.0'
|
||||
|
||||
# Name of the Windows PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
|
||||
# Minimum version of the Windows PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
|
||||
# Minimum version of Microsoft .NET Framework required by this module
|
||||
# DotNetFrameworkVersion = ''
|
||||
|
||||
# Minimum version of the common language runtime (CLR) required by this module
|
||||
# CLRVersion = ''
|
||||
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
# ScriptsToProcess = @()
|
||||
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
# NestedModules = @()
|
||||
|
||||
# Functions to export from this module
|
||||
FunctionsToExport = '*'
|
||||
|
||||
# Cmdlets to export from this module
|
||||
CmdletsToExport = '*'
|
||||
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
|
||||
# Aliases to export from this module
|
||||
AliasesToExport = '*'
|
||||
|
||||
# DSC resources to export from this module
|
||||
# DscResourcesToExport = @()
|
||||
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
|
||||
PSData = @{
|
||||
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
|
||||
# A URL to the license for this module.
|
||||
# LicenseUri = ''
|
||||
|
||||
# A URL to the main website for this project.
|
||||
ProjectUri = 'https://github.com/rgel/PowerCLi'
|
||||
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
|
||||
} # End of PSData hashtable
|
||||
|
||||
} # End of PrivateData hashtable
|
||||
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
|
||||
}
|
||||
|
||||
1241
Modules/Vi-Module/Vi-Module.psm1
Normal file
1241
Modules/Vi-Module/Vi-Module.psm1
Normal file
File diff suppressed because it is too large
Load Diff
92
Pester/Get-DatastoreProvisioned.Tests.ps1
Normal file
92
Pester/Get-DatastoreProvisioned.Tests.ps1
Normal file
@@ -0,0 +1,92 @@
|
||||
# To run: "Invoke-Pester <path>\Get-DatastoreProvisioned.Tests.ps1"
|
||||
|
||||
<#
|
||||
Script name: Get-DatastoreProvisioned.Tests.ps1
|
||||
Created on: 2016/07/27
|
||||
Author: Brian Bunke, @brianbunke
|
||||
Description: Help validate that any changes to Get-DatastoreProvisioned.ps1 do not break existing functionality
|
||||
Dependencies: Pester
|
||||
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 6.0 U1/U2
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 7/10
|
||||
#>
|
||||
|
||||
# Tests file stored separately from actual script
|
||||
# Find where this file is running from, replace parent folder 'Pester' with 'Scripts'
|
||||
$Path = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Pester","Scripts")
|
||||
# Remove the '.Tests.' from the file name
|
||||
$File = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
# With changes made to the path, dot-source the function for testing
|
||||
. "$Path\$File"
|
||||
|
||||
Describe 'Get-DatastoreProvisioned' {
|
||||
# Need to create a few example objects to proxy Get-Datastore pipeline input
|
||||
$1 = [PSCustomObject]@{
|
||||
Name = 'iSCSI-spin'
|
||||
CapacityGB = 38.40
|
||||
FreeSpaceGB = 15.55
|
||||
ExtensionData = @{
|
||||
Summary = @{
|
||||
Capacity = 41234567890
|
||||
FreeSpace = 16696685366
|
||||
Uncommitted = 12345678999
|
||||
}}}
|
||||
$2 = [PSCustomObject]@{
|
||||
Name = 'iSCSI-ssd'
|
||||
CapacityGB = 51.74
|
||||
FreeSpaceGB = 10.35
|
||||
ExtensionData = @{
|
||||
Summary = @{
|
||||
Capacity = 55555555555
|
||||
FreeSpace = 11111111111
|
||||
Uncommitted = 23456765432
|
||||
}}}
|
||||
$3 = [PSCustomObject]@{
|
||||
Name = 'FC-ssd'
|
||||
CapacityGB = 10.35
|
||||
FreeSpaceGB = 4.14
|
||||
ExtensionData = @{
|
||||
Summary = @{
|
||||
Capacity = 11111111111
|
||||
FreeSpace = 4444444444
|
||||
Uncommitted = 2222222222
|
||||
}}}
|
||||
|
||||
It "Doesn't change existing functionality" {
|
||||
$StillWorks = $1,$2,$3 | Get-DatastoreProvisioned
|
||||
$StillWorks | Should Not BeNullOrEmpty
|
||||
($StillWorks | Measure-Object).Count | Should Be 3
|
||||
($StillWorks | Get-Member -MemberType NoteProperty).Count | Should Be 6
|
||||
'Name','FreeSpaceGB','CapacityGB','ProvisionedGB','UsedPct','ProvisionedPct' | ForEach-Object {
|
||||
($StillWorks | Get-Member -MemberType NoteProperty).Name -contains $_ | Should Be $true
|
||||
}
|
||||
}
|
||||
|
||||
It 'Still calculates correctly' {
|
||||
$calc = $1 | Get-DatastoreProvisioned
|
||||
$calc | Should Not BeNullOrEmpty
|
||||
$calc.ProvisionedGB | Should Be 34.35
|
||||
$calc.UsedPct | Should Be 59.51
|
||||
$calc.ProvisionedPct | Should Be 89.45
|
||||
}
|
||||
|
||||
# Get-Datastore | Get-DatastoreProvisioned | Format-Table -AutoSize
|
||||
It 'Follows Help Example 1' {
|
||||
$Help1 = $1,$2,$3 | Get-DatastoreProvisioned
|
||||
$Help1 | Should Not BeNullOrEmpty
|
||||
($Help1 | Measure-Object).Count | Should Be 3
|
||||
# not testing Format-Table
|
||||
}
|
||||
|
||||
# Get-Datastore -Name '*ssd' | Get-DatastoreProvisioned | Where-Object ProvisionedPct -ge 100
|
||||
It 'Follows Help Example 2' {
|
||||
$Help2 = $1,$2,$3 | Where Name -like '*ssd' | Get-DatastoreProvisioned | Where ProvisionedPct -ge 100
|
||||
$Help2 | Should Not BeNullOrEmpty
|
||||
($Help2 | Measure-Object).Count | Should Be 1
|
||||
$Help2.Name | Should BeExactly 'iSCSI-ssd'
|
||||
$Help2.ProvisionedPct | Should BeGreaterThan 100
|
||||
}
|
||||
}
|
||||
44
Pester/Test Connection to VC.ps1
Normal file
44
Pester/Test Connection to VC.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
<#
|
||||
Script name: Test Connection to VC.ps1
|
||||
Created on: 07/15/2016
|
||||
Author: Alan Renouf, @alanrenouf
|
||||
Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection and disconnection can be made to a vCenter
|
||||
Dependencies: Pester Module
|
||||
Example run:
|
||||
|
||||
Invoke-Pester -Script @{ Path = '.\Test Connection to VC.ps1'; Parameters = @{ VCNAME="VC01.local"; VCUSER="Administrator@vsphere.local"; VCPASS="Admin!23"} }
|
||||
|
||||
#>
|
||||
|
||||
$VCUSER = $Parameters.Get_Item("VCUSER")
|
||||
$VCPASS = $Parameters.Get_Item("VCPASS")
|
||||
$VCNAME = $Parameters.Get_Item("VCNAME")
|
||||
|
||||
Describe "PowerCLI Tests" {
|
||||
It "Importing PowerCLI Modules" {
|
||||
Get-Module VMware* | Foreach {
|
||||
Write-Host "Importing Module $($_.name) Version $($_.Version)"
|
||||
$_ | Import-Module
|
||||
Get-Module $_ | Should Be $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Connect-VIServer Tests" {
|
||||
|
||||
$connection = Connect-VIServer $VCName -User $VCUser -password $VCPass
|
||||
It "Connection is active" {
|
||||
$Global:DefaultVIServer[0].isconnected | Should Be $true
|
||||
}
|
||||
|
||||
It "Checking connected server name is $VCName" {
|
||||
$Global:DefaultVIServer[0].name | Should Be $VCName
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Disconnect-VIServer Tests" {
|
||||
It "Disconnect from $VCName" {
|
||||
Disconnect-VIServer $VCName -confirm:$false
|
||||
$Global:DefaultVIServer | Should Be $null
|
||||
}
|
||||
}
|
||||
51
PowerActions/VM-CdDrive-Report.ps1
Normal file
51
PowerActions/VM-CdDrive-Report.ps1
Normal file
@@ -0,0 +1,51 @@
|
||||
<#
|
||||
.MYNGC_REPORT
|
||||
KEY\(VM\)
|
||||
.LABEL
|
||||
VM CD-Drive Report
|
||||
.DESCRIPTION
|
||||
PowerActions Report Script that reports on VMs CD-Drive configuration, making it easy to find VMs holding onto ISOs that you
|
||||
need to update, or VMs that can't vMotion because they are tied into a physical resource from the ESXi host that is running it.
|
||||
VM object is key (as it's the first managed object in the output), enabling you the ability to right-click an entry in the
|
||||
report to edit the target VM. Script is able to report on VMs with multiple CD-Drives as well. Version 1.0, written by
|
||||
Aaron Smith (@awsmith99), published 07/29/2016.
|
||||
#>
|
||||
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]
|
||||
$vParam
|
||||
);
|
||||
|
||||
[Array] $vmList = @( Get-VM -Location $vParam | Sort Name );
|
||||
|
||||
foreach ( $vmItem in $vmList )
|
||||
{
|
||||
[Array] $vmCdDriveList = @( Get-CDDrive -VM $vmItem );
|
||||
|
||||
foreach ( $vmCdDriveItem in $vmCdDriveList )
|
||||
{
|
||||
[String] $insertedElement = "";
|
||||
[String] $connectionType = "";
|
||||
|
||||
switch ( $vmCdDriveItem )
|
||||
{
|
||||
{ $_.IsoPath } { $insertedElement = $_.IsoPath; $connectionType = "ISO"; break; }
|
||||
{ $_.HostDevice } { $insertedElement = $_.HostDevice; $connectionType = "Host Device"; break; }
|
||||
{ $_.RemoteDevice } { $insertedElement = $_.RemoteDevice; $connectionType = "Remote Device"; break; }
|
||||
default { $insertedElement = "None"; $connectionType = "Client Device"; break; }
|
||||
}
|
||||
|
||||
$output = New-Object -TypeName PSObject;
|
||||
|
||||
$output | Add-Member -MemberType NoteProperty -Name "VM" -Value $vmItem
|
||||
$output | Add-Member -MemberType NoteProperty -Name "CD-Drive" -Value $vmCdDriveItem.Name;
|
||||
$output | Add-Member -MemberType NoteProperty -Name "Connection" -Value $connectionType;
|
||||
$output | Add-Member -MemberType NoteProperty -Name "Inserted" -Value $insertedElement;
|
||||
$output | Add-Member -MemberType NoteProperty -Name "Connected" -Value $vmCdDriveItem.ConnectionState.Connected;
|
||||
$output | Add-Member -MemberType NoteProperty -Name "StartConnected" -Value $vmCdDriveItem.ConnectionState.StartConnected;
|
||||
$output | Add-Member -MemberType NoteProperty -Name "AllowGuestControl" -Value $vmCdDriveItem.ConnectionState.AllowGuestControl;
|
||||
$output;
|
||||
}
|
||||
}
|
||||
@@ -178,11 +178,10 @@ The VMware Technnology Preview License Agreement: <https://github.com/vmware/Pow
|
||||
|
||||
## Board Members
|
||||
|
||||
Board members are voulenteers from the PowerCLI community and VMware staff members, board members are not held responsible for any issues which may occur from running of scripts inside this repository.
|
||||
Board members are volunteers from the PowerCLI community and VMware staff members, board members are not held responsible for any issues which may occur from running of scripts inside this repository.
|
||||
|
||||
Members:
|
||||
* Josh Atwell (Community Member)
|
||||
* Mathieu Buisson (Community Member)
|
||||
* Luc Dekens (Community Member)
|
||||
* Jonathan Medd (Community Member)
|
||||
* Alan Renouf (VMware)
|
||||
|
||||
67
Scripts/Get-DatastoreProvisioned.ps1
Normal file
67
Scripts/Get-DatastoreProvisioned.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
<#
|
||||
Script name: Get-DatastoreProvisioned.ps1
|
||||
Created on: 2016/07/27
|
||||
Author: Brian Bunke, @brianbunke
|
||||
Description: Augments Get-Datastore with thin provisioned info
|
||||
Note to future contributors: Test changes with Pester file Get-DatastoreProvisioned.Tests.ps1
|
||||
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 6.0 U1/U2
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 7/10
|
||||
#>
|
||||
|
||||
function Get-DatastoreProvisioned {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrieve the total thin provisioned space on each datastore.
|
||||
|
||||
.DESCRIPTION
|
||||
Intended to reveal provisioned space alongside total/free space, to assist with svMotion decisions.
|
||||
-Name should be supplied from the pipeline via Get-Datastore.
|
||||
|
||||
.EXAMPLE
|
||||
Get-Datastore | Get-DatastoreProvisioned | Format-Table -AutoSize
|
||||
View all datastores and view their capacity statistics in the current console.
|
||||
|
||||
.EXAMPLE
|
||||
Get-Datastore -Name '*ssd' | Get-DatastoreProvisioned | Where-Object -Property ProvisionedPct -ge 100
|
||||
For all datastores ending in 'ssd', return the capacity stats of those at least 100% provisioned.
|
||||
|
||||
.INPUTS
|
||||
[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl]
|
||||
Object type supplied by PowerCLI function Get-Datastore
|
||||
|
||||
.LINK
|
||||
https://github.com/vmware/PowerCLI-Example-Scripts
|
||||
|
||||
.LINK
|
||||
https://twitter.com/brianbunke
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
# Specifies the datastore names to check. Tested only with pipeline input (see examples).
|
||||
[Parameter(ValueFromPipeline = $true)]
|
||||
$Name
|
||||
)
|
||||
|
||||
PROCESS {
|
||||
ForEach ($DS in $Name) {
|
||||
# Calculate total provisioned space from the exposed properties
|
||||
$Provisioned = ($DS.ExtensionData.Summary.Capacity -
|
||||
$DS.ExtensionData.Summary.FreeSpace +
|
||||
$DS.ExtensionData.Summary.Uncommitted) / 1GB
|
||||
|
||||
# Return info, wrapping it in the Math.Round method to trim to two decimal places
|
||||
[PSCustomObject]@{
|
||||
Name = $DS.Name
|
||||
FreeSpaceGB = [math]::Round($DS.FreeSpaceGB, 2)
|
||||
CapacityGB = [math]::Round($DS.CapacityGB, 2)
|
||||
ProvisionedGB = [math]::Round($Provisioned, 2)
|
||||
UsedPct = [math]::Round((($DS.CapacityGB - $DS.FreeSpaceGB) / $DS.CapacityGB) * 100, 2)
|
||||
ProvisionedPct = [math]::Round(($Provisioned / $DS.CapacityGB) * 100, 2)
|
||||
} #pscustomobject
|
||||
} #foreach
|
||||
} #process
|
||||
} #function
|
||||
41
Scripts/Get-VMID.ps1
Normal file
41
Scripts/Get-VMID.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
function Get-VMID {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Markus Kraus
|
||||
Organization: Private
|
||||
Personal Blog: mycloudrevolution.com
|
||||
Twitter: @vMarkus_K
|
||||
===========================================================================
|
||||
.DESCRIPTION
|
||||
This will quickly return all IDs of VMs
|
||||
.Example
|
||||
Get-VMID -myVMs (Get-VM) | ft
|
||||
.Example
|
||||
$SampleVMs = Get-VM "tst*"
|
||||
Get-VMID -myVMs $SampleVMs
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$True,
|
||||
Position=0)]
|
||||
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
|
||||
$myVMs
|
||||
)
|
||||
Process {
|
||||
|
||||
$MyView = @()
|
||||
ForEach ($myVM in $myVMs){
|
||||
$UUIDReport = [PSCustomObject] @{
|
||||
Name = $myVM.name
|
||||
UUID = $myVM.extensiondata.Config.UUID
|
||||
InstanceUUID = $myVM.extensiondata.config.InstanceUUID
|
||||
LocationID = $myVM.extensiondata.config.LocationId
|
||||
MoRef = $myVM.extensiondata.Moref.Value
|
||||
}
|
||||
$MyView += $UUIDReport
|
||||
}
|
||||
$MyView
|
||||
}
|
||||
}
|
||||
62
Scripts/Report-LUNPath-ESXCLI.ps1
Normal file
62
Scripts/Report-LUNPath-ESXCLI.ps1
Normal file
@@ -0,0 +1,62 @@
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Markus Kraus
|
||||
Organization: Private
|
||||
Personal Blog: mycloudrevolution.com
|
||||
Twitter: @vMarkus_K
|
||||
===========================================================================
|
||||
Tested Against Environment:
|
||||
vSphere Version: 6.0 U1, 5.5 U2
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 8.1, Server 2012 R2
|
||||
Keyword: ESXi, LUN, Path, Storage
|
||||
|
||||
Dependencies:
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
|
||||
.DESCRIPTION
|
||||
This script will create a Report of LUNs with Paths that have more than one unique LUN ID or have more than the defined Paths.
|
||||
Information’s will be gathered via ESXCLI. This is necessary to report also hidden Paths!
|
||||
|
||||
.Example
|
||||
./Report-LUNPath-ESXCLI.ps1
|
||||
|
||||
#>
|
||||
|
||||
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
|
||||
|
||||
#region 1: Global Definitions
|
||||
$MaxLUNPaths = 2
|
||||
#endregion
|
||||
|
||||
#region 2: Get all Connected Hosts
|
||||
$myHosts = Get-VMHost | where {$_.ConnectionState -eq "Connected" -and $_.PowerState -eq "PoweredOn"}
|
||||
#endregion
|
||||
|
||||
#region 3: Create Report
|
||||
$Report = @()
|
||||
foreach ($myHost in $myHosts) {
|
||||
$esxcli2 = Get-ESXCLI -VMHost $myHost -V2
|
||||
$devices = $esxcli2.storage.core.path.list.invoke() | select Device -Unique
|
||||
|
||||
foreach ($device in $devices) {
|
||||
$arguments = $esxcli2.storage.core.path.list.CreateArgs()
|
||||
$arguments.device = $device.Device
|
||||
$LUNs = $esxcli2.storage.core.path.list.Invoke($arguments)
|
||||
|
||||
$LUNReport = [PSCustomObject] @{
|
||||
HostName = $myHost.Name
|
||||
Device = $device.Device
|
||||
LUNPaths = $LUNs.Length
|
||||
LUNIDs = $LUNs.LUN | Select-Object -Unique
|
||||
}
|
||||
$Report += $LUNReport
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 4: Output Report
|
||||
$Report | where {$_.LUNPaths -gt $MaxLUNPaths -or ($_.LUNIDs | measure).count -gt 1 } | ft -AutoSize
|
||||
#endregion
|
||||
116
Scripts/vRealize Operations Maintenance Mode.ps1
Normal file
116
Scripts/vRealize Operations Maintenance Mode.ps1
Normal file
@@ -0,0 +1,116 @@
|
||||
Connect-VIServer vc-l-01a.corp.local -User administrator@vsphere.local -Password VMware1!
|
||||
Connect-OMServer vrops.corp1.local -User admin -Password VMware1!
|
||||
|
||||
function Enable-OMMaintenance {
|
||||
<#
|
||||
.NOTES
|
||||
Script name: vRealize Operations Maintenance Mode.ps1
|
||||
Created on: 07/26/2016
|
||||
Author: Alan Renouf, @alanrenouf
|
||||
Dependencies: PowerCLI 6.0 R2 or later
|
||||
.DESCRIPTION
|
||||
Places a vSphere Inventory object into maintenance mode in vRealize Operations
|
||||
.Example
|
||||
Set All VMs with a name as backup as being in maintenance mode for 20 minutes:
|
||||
|
||||
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||
|
||||
Name Health ResourceKind Description
|
||||
---- ------ ------------ -----------
|
||||
backup-089e13fd-7d7a-0 Grey VirtualMachine
|
||||
backup-d90e0b39-2618-0 Grey VirtualMachine
|
||||
backup-e48ca842-316a-0 Grey VirtualMachine
|
||||
backup-77da3713-919a-0 Grey VirtualMachine
|
||||
backup-c32f4da8-86c4-0 Grey VirtualMachine
|
||||
backup-c3fcb95c-cfe2-0 Grey VirtualMachine
|
||||
backup-4318bb1e-614a-0 Grey VirtualMachine
|
||||
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]
|
||||
$Resource,
|
||||
|
||||
[Parameter(Position=1, Mandatory=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Int]
|
||||
$MaintenanceTime
|
||||
)
|
||||
process {
|
||||
Foreach ($Entry in $resource) {
|
||||
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
} Else {
|
||||
$Item.ExtensionData.MarkResourceAsBeingMaintained($MaintenanceTime)
|
||||
Get-Inventory -Name $Entry | Get-OMResource
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Disable-OMMaintenance {
|
||||
<#
|
||||
.NOTES
|
||||
Script name: vRealize Operations Maintenance Mode.ps1
|
||||
Created on: 07/26/2016
|
||||
Author: Alan Renouf, @alanrenouf
|
||||
Dependencies: PowerCLI 6.0 R2 or later
|
||||
.DESCRIPTION
|
||||
Removes a vSphere Inventory object from maintenance mode in vRealize Operations
|
||||
.Example
|
||||
Disable maintenance mode for all VMs with a name of backup
|
||||
|
||||
Get-VM backup* | Disable-OMMaintenance
|
||||
|
||||
Name Health ResourceKind Description
|
||||
---- ------ ------------ -----------
|
||||
backup-089e13fd-7d7a-0 Grey VirtualMachine
|
||||
backup-d90e0b39-2618-0 Grey VirtualMachine
|
||||
backup-e48ca842-316a-0 Grey VirtualMachine
|
||||
backup-77da3713-919a-0 Grey VirtualMachine
|
||||
backup-c32f4da8-86c4-0 Yellow VirtualMachine
|
||||
backup-c3fcb95c-cfe2-0 Yellow VirtualMachine
|
||||
backup-4318bb1e-614a-0 Yellow VirtualMachine
|
||||
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]
|
||||
$Resource
|
||||
)
|
||||
process {
|
||||
Foreach ($Entry in $resource) {
|
||||
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
} Else {
|
||||
$Item.ExtensionData.UnmarkResourceAsBeingMaintained()
|
||||
Get-Inventory -Name $Entry | Get-OMResource
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Enable a single host as being in maintenance mode for 1 minute"
|
||||
Enable-OMMaintenance -Resource ESX-01a* -MaintenanceTime 1
|
||||
|
||||
Write-Host "List All Host Resources and their state"
|
||||
Get-OMResource ESX-* | Select Name, State | FT
|
||||
|
||||
Write-Host "Set All VMs with a name as backup as being in maintenance mode for 20 minutes"
|
||||
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||
|
||||
Write-Host "List All Backup VM Resources and their state"
|
||||
Get-VM backup* | Get-OMResource | Select Name, State | FT
|
||||
|
||||
Write-Host "Disable maintenance mode for all VMs with a name as backup as we have completed our scheduled work"
|
||||
Get-VM backup* | Disable-OMMaintenance
|
||||
|
||||
Write-Host "List All VM Resources and their state"
|
||||
Get-VM backup* | Get-OMResource | Select Name, State | FT
|
||||
|
||||
Reference in New Issue
Block a user