Merge remote-tracking branch 'refs/remotes/vmware/master'

This commit is contained in:
mycloudrevolution
2016-12-02 18:17:53 +01:00
11 changed files with 5406 additions and 299 deletions

View File

@@ -0,0 +1,85 @@
function Get-VMmaxIOPS {
<#
.SYNOPSIS
Report VM Disk IOPS of VMs
.DESCRIPTION
This Function will Create a VM Disk IOPS Report
.Example
Get-VM TST* | Get-VMmaxIOPS -Minutes 60 | FT -Autosize
.Example
$SampleVMs = Get-VM "TST*"
Get-VMmaxIOPS -VMs $SampleVMs -Minutes 60
.PARAMETER VMs
Specify the VMs
.PARAMETER Minutes
Specify the Minutes to report (10080 is one Week)
.Notes
NAME: Get-VMmaxIOPS.ps1
LASTEDIT: 08/23/2016
VERSION: 1.1
KEYWORDS: VMware, vSphere, ESXi, IOPS
.Link
http://mycloudrevolution.com/
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$True, Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
$VMs,
[Parameter(Mandatory=$false, Position=1)]
[int] $Minutes = 30
)
Process {
#region: Global Definitions
[int]$TimeRange = "-" + $Minutes
#endregion
#region: Creating Metrics
Write-Debug "Starting to Create Metrics..."
$metrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average"
$start = (Get-Date).AddMinutes($TimeRange)
$stats = Get-Stat -Stat $metrics -Entity $VMs -Start $start
#endregion
#region: Creating HD-Tab
Write-Debug "Starting to Create HD-Tab..."
$hdTab = @{}
foreach($hd in (Get-Harddisk -VM $VMs)){
$controllerKey = $hd.Extensiondata.ControllerKey
$controller = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $controllerKey}
$hdTab[$hd.Parent.Name + "/scsi" + $controller.BusNumber + ":" + $hd.Extensiondata.UnitNumber] = $hd.FileName.Split(']')[0].TrimStart('[')
}
#endregion
#region: Creating Reports
Write-Debug "Starting to Process IOPS Report..."
$reportPerf = @()
$reportPerf = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{
New-Object PSObject -Property @{
VM = $_.Values[0]
Disk = $_.Values[1]
IOPSMax = ($_.Group | `
Group-Object -Property Timestamp | `
%{$_.Group[0].Value + $_.Group[1].Value} | `
Measure-Object -Maximum).Maximum
Datastore = $hdTab[$_.Values[0] + "/"+ $_.Values[1]]
}
}
$reportPerf | Select-Object VM, Disk, Datastore, IOPSMax
#endregion
}
}

View File

@@ -8,14 +8,15 @@ function Recommend-Sizing {
=========================================================================== ===========================================================================
Changelog: Changelog:
2016.11 ver 1.0 Base Release 2016.11 ver 1.0 Base Release
2016.11 ver 1.1 Optional Stats Collection. 2016.11 ver 1.1 Optional Stats Collection
2016.11 ver 1.2 VM Stats from Realtime Data and new Counters
=========================================================================== ===========================================================================
External Code Sources: External Code Sources:
http://www.lucd.info/2011/04/22/get-the-maximum-iops/ http://www.lucd.info/2011/04/22/get-the-maximum-iops/
https://communities.vmware.com/thread/485386 https://communities.vmware.com/thread/485386
=========================================================================== ===========================================================================
Tested Against Environment: Tested Against Environment:
vSphere Version: 5.5 U2 vSphere Version: 5.5 U2, 6.0
PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1 PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1
PowerShell Version: 4.0, 5.0 PowerShell Version: 4.0, 5.0
OS Version: Windows 8.1, Server 2012 R2 OS Version: Windows 8.1, Server 2012 R2
@@ -24,7 +25,7 @@ function Recommend-Sizing {
=========================================================================== ===========================================================================
.DESCRIPTION .DESCRIPTION
This Function collects Basic vSphere Informations for a Hardware Sizing Recomamndation. Focus is in Compute Ressources. This Function collects Basic vSphere Informations for a Hardware Sizing Recommandation. Focus is in Compute Ressources.
.Example .Example
Recommend-Sizing -ClusterNames Cluster01, Cluster02 -Stats -StatsRange 60 -Verbose Recommend-Sizing -ClusterNames Cluster01, Cluster02 -Stats -StatsRange 60 -Verbose
@@ -41,7 +42,7 @@ function Recommend-Sizing {
.PARAMETER Stats .PARAMETER Stats
Enables Stats Collection. Enables Stats Collection.
Warning: At the moment this is only tested and supported with vSphere 5.5! Warning: At the moment this is only fully tested with vSphere 5.5 and vSphere 6.5!
.PARAMETER StatsRange .PARAMETER StatsRange
Time Range in Minutes for the Stats Collection. Time Range in Minutes for the Stats Collection.
@@ -55,15 +56,15 @@ function Recommend-Sizing {
param( param(
[Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)] [Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)]
[Array] $ClusterNames, [Array] $ClusterNames,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2)] [Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=1, ParameterSetName = "Stats")]
[switch] $Stats, [switch] $Stats,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2)] [Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2, ParameterSetName = "Stats")]
[int] $StatsRange = 1440 [int] $StatsRange = 1440
) )
Begin { Begin {
if ($Stats) { if ($Stats) {
Write-Warning "Stats Collection enabled.`nAt the moment this is only tested and supported with vSphere 5.5" Write-Warning "Stats Collection requested.`nAt the moment this is only fully tested with vSphere 5.5 and vSphere 6.5"
[int]$TimeRange = "-" + $StatsRange [int]$TimeRange = "-" + $StatsRange
} }
@@ -121,30 +122,38 @@ Process {
#endregion #endregion
if ($Stats) { if ($Stats) {
#region: Creating Disk Metrics #region: Creating VM Stats
Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) IOPS Metrics..." Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) VM Stats..."
$DiskMetrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average" $VMMetrics = "disk.numberwrite.summation","disk.numberread.summation","cpu.usage.average", "mem.usage.average"
$start = (Get-Date).AddMinutes($TimeRange) $Start = (Get-Date).AddMinutes($TimeRange)
$DiskStats = Get-Stat -Stat $DiskMetrics -Entity $ClusterVMsPoweredOn -Start $start -Verbose:$False $VMStats = Get-Stat -Realtime -Stat $VMMetrics -Entity $ClusterVMsPoweredOn -Start $Start -Verbose:$False
Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) IOPS Metrics completed" Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) VM Stats completed"
#endregion #endregion
#region: Creating IOPS Reports #region: Creating VM Stats Report
Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) IOPS Report..." Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) VM Stats Report..."
$reportDiskPerf = @() $ReportVMPerf = @()
$reportDiskPerf = $DiskStats | Group-Object -Property {$_.Entity.Name},Instance | %{ $ReportVMPerf = $VMStats | Group-Object -Property {$_.Entity.Name},Instance | %{
New-Object PSObject -Property @{ New-Object PSObject -Property @{
IOPSMax = ($_.Group | ` IOPSWriteAvg = ($_.Group | `
Group-Object -Property Timestamp | ` where{$_.MetricId -eq "disk.numberwrite.summation"} | `
%{$_.Group[0].Value + $_.Group[1].Value} | ` Measure-Object -Property Value -Average).Average
Measure-Object -Maximum).Maximum IOPSReadAvg = ($_.Group | `
where{$_.MetricId -eq "disk.numberread.summation"} | `
Measure-Object -Property Value -Average).Average
CPUUsageAvg = ($_.Group | `
where{$_.MetricId -eq "cpu.usage.average"} | `
Measure-Object -Property Value -Average).Average
MEMUsageAvg = ($_.Group | `
where{$_.MetricId -eq "mem.usage.average"} | `
Measure-Object -Property Value -Average).Average
} }
} }
Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) IOPS Report completed" Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) VM Stats Report completed"
#endregion #endregion
} }
else { else {
Write-Verbose "$(Get-Date -Format G) Stats Cellocetion skipped..." Write-Verbose "$(Get-Date -Format G) Stats Collection skipped..."
} }
#region: Create VM Disk Space Report #region: Create VM Disk Space Report
@@ -194,8 +203,10 @@ Process {
SumVMDiskSpaceGB = [math]::round( ($reportDiskSpace | Measure-Object -Sum -Property CapacityGB).sum, 1 ) SumVMDiskSpaceGB = [math]::round( ($reportDiskSpace | Measure-Object -Sum -Property CapacityGB).sum, 1 )
SumDatastoreSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property CapacityGB).sum, 1 ) SumDatastoreSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property CapacityGB).sum, 1 )
SumDatastoreUsedSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property UsedSpaceGB).sum, 1 ) SumDatastoreUsedSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property UsedSpaceGB).sum, 1 )
SumMaxVMIOPS = [math]::round( ($reportDiskPerf | Measure-Object -Sum -Property IOPSMax).sum, 1 ) AverageVMIOPSWriteAvg = [math]::round( ($ReportVMPerf | Measure-Object -Average -Property IOPSWriteAvg).Average,1 )
AverageMaxVMIOPs = [math]::round( ($reportDiskPerf | Measure-Object -Average -Property IOPSMax).Average,1 ) AverageVMIOPSReadAvg = [math]::round( ($ReportVMPerf | Measure-Object -Average -Property IOPSReadAvg).Average,1 )
AverageVMCPUUsageAvg = "$([math]::round( ($ReportVMPerf | Measure-Object -Average -Property CPUUsageAvg).Average,1 )) %"
AverageVMMEMUsageAvg = "$([math]::round( ($ReportVMPerf | Measure-Object -Average -Property MEMUsageAvg).Average,1 )) %"
} }
$MyView += $SizingReport $MyView += $SizingReport
Write-Verbose "$(Get-Date -Format G) Process Global Report completed" Write-Verbose "$(Get-Date -Format G) Process Global Report completed"

111
Modules/Set-CBT.psm1 Normal file
View File

@@ -0,0 +1,111 @@
function Set-CBT {
<#
.NOTES
===========================================================================
Created by: Markus Kraus
Twitter: @VMarkus_K
Private Blog: mycloudrevolution.com
===========================================================================
Changelog:
2016.11 ver 1.0 Base Release
===========================================================================
External Code Sources:
http://wahlnetwork.com/2015/12/01/change-block-tracking-cbt-powercli/
===========================================================================
Tested Against Environment:
vSphere Version: 5.5 U2
PowerCLI Version: PowerCLI 6.3 R1
PowerShell Version: 4.0
OS Version: Windows Server 2012 R2
===========================================================================
Keywords vSphere, ESXi, VM, Storage, CBT, Backup
===========================================================================
.DESCRIPTION
This Function enables or disables CBT.
.Example
Get-VN TST* | Set-CBT -DisableCBT
.Example
Get-VN TST* | Set-CBT -EnableCBT
.PARAMETER DisableCBT
Disables CBT for any VMs found with it enabled
.PARAMETER EnableCBT
Enables CBT for any VMs found with it disabled
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage = "VMs to process")]
[ValidateNotNullorEmpty()]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] $myVMs,
[Parameter(Mandatory = $False,ValueFromPipeline=$False, Position = 1, HelpMessage = "Enables CBT for any VMs found with it disabled", ParameterSetName = "EnableCBT")]
[ValidateNotNullorEmpty()]
[Switch]$EnableCBT,
[Parameter(Mandatory = $False,ValueFromPipeline=$False, Position = 1, HelpMessage = "Disables CBT for any VMs found with it enabled", ParameterSetName = "DisableCBT")]
[ValidateNotNullorEmpty()]
[Switch]$DisableCBT
)
Process {
$vmconfigspec = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec
Write-Verbose -Message "Walking through given VMs"
foreach($myVM in $myVMs)
{
if ($DisableCBT -and $myVM.ExtensionData.Config.ChangeTrackingEnabled -eq $true -and $myVM.ExtensionData.Snapshot -eq $null)
{
try
{
Write-Verbose -Message "Reconfiguring $($myVM.name) to disable CBT" -Verbose
$vmconfigspec.ChangeTrackingEnabled = $false
$myVM.ExtensionData.ReconfigVM($vmconfigspec)
if ($myVM.PowerState -eq "PoweredOn" ) {
Write-Verbose -Message "Creating a snapshot on $($myVM.name) to clear CBT file" -Verbose
$SnapShot = New-Snapshot -VM $myVM -Name "CBT Cleanup"
Write-Verbose -Message "Removing snapshot on $($myVM.name)" -Verbose
$SnapShot| Remove-Snapshot -Confirm:$false
}
}
catch
{
throw $myVM
}
}
elseif ($EnableCBT -and $myVM.ExtensionData.Config.ChangeTrackingEnabled -eq $false -and $myVM.ExtensionData.Snapshot -eq $null)
{
Write-Verbose -Message "Reconfiguring $($myVM.name) to enable CBT" -Verbose
$vmconfigspec.ChangeTrackingEnabled = $true
$myVM.ExtensionData.ReconfigVM($vmconfigspec)
if ($myVM.PowerState -eq "PoweredOn" ) {
Write-Verbose -Message "Creating a snapshot on $($myVM.name) to Create CBT file" -Verbose
$SnapShot = New-Snapshot -VM $myVM -Name "CBT Cleanup"
Write-Verbose -Message "Removing snapshot on $($myVM.name)" -Verbose
$SnapShot | Remove-Snapshot -Confirm:$false
}
}
else
{
if ($myVM.ExtensionData.Snapshot -ne $null -and $EnableCBT)
{
Write-Warning -Message "Skipping $($myVM.name) - Snapshots found"
}
elseif ($myVM.ExtensionData.Snapshot -ne $null -and $DisableCBT)
{
Write-Warning -Message "Skipping $($myVM.name) - Snapshots found"
}
}
}
}
}

99
Modules/Start-UNMAP.psm1 Normal file
View File

@@ -0,0 +1,99 @@
function Start-UNMAP {
<#
.SYNOPSIS
Process SCSI UNMAP on VMware Datastores
.DESCRIPTION
This Function will process SCSI UNMAP on VMware Datastores via ESXCLI -V2
.Example
Start-UNMAP -ClusterName myCluster -DSWildcard *RAID5*
.Example
Start-UNMAP -ClusterName myCluster -DSWildcard *RAID5* -Verbose -WhatIf
.Notes
NAME: Start-UNMAP.psm1
AUTHOR: Markus Kraus
LASTEDIT: 23.09.2016
VERSION: 1.0
KEYWORDS: VMware, vSphere, ESXi, SCSI, VAAI, UNMAP
.Link
http://mycloudrevolution.com/
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
param(
[Parameter(Mandatory=$true, Position=0)]
[String]$ClusterName,
[Parameter(Mandatory=$true, Position=1)]
[String]$DSWildcard
)
Process {
$Validate = $true
#region: PowerCLI Session Timeout
Write-Verbose "Set Session Timeout ..."
$initialTimeout = (Get-PowerCLIConfiguration -Scope Session).WebOperationTimeoutSeconds
Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds -1 -Confirm:$False | Out-Null
#endregion
#region: Get Cluster
$Cluster = Get-Cluster -Name $ClusterName -ErrorAction SilentlyContinue
Write-Verbose "vSphere Cluster: $Cluster"
if (!$Cluster){Write-Error "No Cluster found!"; $Validate = $false}
#endregion
#region: Get Hosts
$ClusterHosts = $Cluster | Get-VMHost -ErrorAction SilentlyContinue | where {$_.ConnectionState -eq "Connected" -and $_.PowerState -eq "PoweredOn"}
Write-Verbose "vSphere Cluster Hosts: $ClusterHosts"
if (!$ClusterHosts){Write-Error "No Hosts found!"; $Validate = $false}
#endregion
#region: Get Datastores
$ClusterDataStores = $Cluster | Get-Datastore -ErrorAction SilentlyContinue | where {$_.Name -like $DSWildcard -and $_.State -eq "Available" -and $_.Accessible -eq "True"}
Write-Verbose "vSphere Cluster Datastores: $ClusterDataStores"
if (!$ClusterDataStores){Write-Error "No Datastores found!"; $Validate = $false}
#endregion
#region: Process Datastores
if ($Validate -eq $true) {
Write-Verbose "Starting Loop..."
foreach ($ClusterDataStore in $ClusterDataStores) {
Write-Verbose "vSphere Datastore to Process: $ClusterDataStore"
$myHost = $ClusterHosts[(Get-Random -Maximum ($ClusterHosts).count)]
Write-Verbose "vSphere Host to Process: $myHost"
$esxcli2 = $myHost | Get-ESXCLI -V2
$arguments = $esxcli2.storage.vmfs.unmap.CreateArgs()
$arguments.volumelabel = $ClusterDataStore
$arguments.reclaimunit = "256"
if ($PSCmdlet.ShouldProcess( $ClusterDataStore,"Starting UNMAP on $myHost")) {
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
try {
Write-Output "Starting UNMAP for $ClusterDataStore on $myHost..."
$esxcli2.storage.vmfs.unmap.Invoke($arguments)
}
catch {
Write-Output "A Error occured: " "" $error[0] ""
}
$stopwatch.Stop()
Write-Output "UNMAP duration: $($stopwatch.Elapsed.Minutes)"
}
}
}
else {
Write-Error "Validation Failed. Processing Loop Skipped!"
}
#endregion
#region: Revert PowerCLI Session Timeout
Write-Verbose "Revert Session Timeout ..."
Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds $initialTimeout -Confirm:$False | Out-Null
#endregion
}
}

View File

@@ -0,0 +1,228 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>VMware.HV.DesktopSummaryView</Name>
<ViewSelectedBy>
<TypeName>VMware.HV.DesktopSummaryView</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>12</Width>
<Label>Name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
<Label>DisplayName</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>12</Width>
<Label>Type</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>18</Width>
<Label>Source</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
<Label>User Assignment</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>8</Width>
<Label>Enabled</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
<Label>Sessions</Label>
<Alignment>Right</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.name</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.displayName</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.type</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.source</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.userAssignment</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.enabled</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.desktopSummaryData.numSessions</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>VMware.HV.DesktopSummaryViewList</Name>
<ViewSelectedBy>
<TypeName>VMware.HV.DesktopSummaryView</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<ScriptBlock>$_.desktopSummaryData.name</ScriptBlock>
</ListItem>
<ListItem>
<Label>DisplayName</Label>
<ScriptBlock>$_.desktopSummaryData.displayName</ScriptBlock>
</ListItem>
<ListItem>
<Label>Type</Label>
<ScriptBlock>$_.desktopSummaryData.type</ScriptBlock>
</ListItem>
<ListItem>
<Label>Source</Label>
<ScriptBlock>$_.desktopSummaryData.source</ScriptBlock>
</ListItem>
<ListItem>
<Label>User Assignment</Label>
<ScriptBlock>$_.desktopSummaryData.userAssignment</ScriptBlock>
</ListItem>
<ListItem>
<Label>Enabled</Label>
<ScriptBlock>$_.desktopSummaryData.enabled</ScriptBlock>
</ListItem>
<ListItem>
<Label>Sessions</Label>
<ScriptBlock>$_.desktopSummaryData.numSessions</ScriptBlock>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>VMware.HV.MachineNamesView</Name>
<ViewSelectedBy>
<TypeName>VMware.HV.MachineNamesView</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>16</Width>
<Label>Machine</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
<Label>DesktopPool</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
<Label>DNS Name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
<Label>User</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
<Label>Host</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>8</Width>
<Label>Agent</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
<Label>Datastore</Label>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
<Label>Status</Label>
<Alignment>Right</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.Base.Name</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.NamesData.desktopName</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Base.DnsName</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.NamesData.UserName</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.ManagedMachineNamesData.HostName</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Data.AgentVersion</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.ManagedMachineNamesData.DatastorePaths</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Data.BasicState</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>VMware.HV.MachineNamesViewList</Name>
<ViewSelectedBy>
<TypeName>VMware.HV.MachineNamesView</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<ScriptBlock>$_.Base.Name</ScriptBlock>
</ListItem>
<ListItem>
<Label>DisplayName</Label>
<ScriptBlock>$_.NamesData.desktopName</ScriptBlock>
</ListItem>
<ListItem>
<Label>Type</Label>
<ScriptBlock>$_.Base.DnsName</ScriptBlock>
</ListItem>
<ListItem>
<Label>Source</Label>
<ScriptBlock>$_.NamesData.UserName</ScriptBlock>
</ListItem>
<ListItem>
<Label>User Assignment</Label>
<ScriptBlock>$_.ManagedMachineNamesData.HostName</ScriptBlock>
</ListItem>
<ListItem>
<Label>Enabled</Label>
<ScriptBlock>$_.ManagedMachineNamesData.DatastorePaths</ScriptBlock>
</ListItem>
<ListItem>
<Label>Sessions</Label>
<ScriptBlock>$_.Data.BasicState</ScriptBlock>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>

View File

@@ -60,7 +60,7 @@ RequiredModules = @('VMware.VimAutomation.HorizonView')
# TypesToProcess = @() # TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module # Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @() FormatsToProcess = @('VMware.HV.Helper.format.ps1xml')
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @('VMware.HV.Helper.psm1') NestedModules = @('VMware.HV.Helper.psm1')

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
function Apply-Hardening {
<#
.NOTES
===========================================================================
Created by: Markus Kraus
Twitter: @VMarkus_K
Private Blog: mycloudrevolution.com
===========================================================================
Changelog:
2016.11 ver 2.0 Base Release
===========================================================================
External Code Sources:
===========================================================================
Tested Against Environment:
vSphere Version: 5.5 U2
PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1
PowerShell Version: 4.0, 5.0
OS Version: Windows 8.1, Server 2012 R2
Keyword: VM, Hardening, Security
===========================================================================
.DESCRIPTION
Applys a set of Hardening options to your VMs
.Example
Get-VM TST* | Apply-Hardening
.Example
$SampleVMs = Get-VM "TST*"
Apply-Hardening -VMs $SampleVMs
.PARAMETER VMs
Specify the VMs
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$True,
Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
$VMs
)
Process {
#region: Create Options
$ExtraOptions = @{
"isolation.tools.diskShrink.disable"="true";
"isolation.tools.diskWiper.disable"="true";
"isolation.tools.copy.disable"="true";
"isolation.tools.paste.disable"="true";
"isolation.tools.dnd.disable"="true";
"isolation.tools.setGUIOptions.enable"="false";
"log.keepOld"="10";
"log.rotateSize"="100000"
"RemoteDisplay.maxConnections"="2";
"RemoteDisplay.vnc.enabled"="false";
}
if ($DebugPreference -eq "Inquire") {
Write-Output "VM Hardening Options:"
$ExtraOptions | Format-Table -AutoSize
}
$VMConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
Foreach ($Option in $ExtraOptions.GetEnumerator()) {
$OptionValue = New-Object VMware.Vim.optionvalue
$OptionValue.Key = $Option.Key
$OptionValue.Value = $Option.Value
$VMConfigSpec.extraconfig += $OptionValue
}
#endregion
#region: Apply Options
ForEach ($VM in $VMs){
$VMv = Get-VM $VM | Get-View
$state = $VMv.Summary.Runtime.PowerState
Write-Output "...Starting Reconfiguring VM: $VM "
$TaskConf = ($VMv).ReconfigVM_Task($VMConfigSpec)
if ($state -eq "poweredOn") {
Write-Output "...Migrating VM: $VM "
$TaskMig = $VMv.MigrateVM_Task($null, $_.Runtime.Host, 'highPriority', $null)
}
}
}
#endregion
}

View File

@@ -0,0 +1,31 @@
<#
.NOTES
===========================================================================
Script name: Start-VMHostSsh.ps1
Created on: 2016-07-01
Author: Peter D. Jorgensen (@pjorg, pjorg.com)
Dependencies: None known
===Tested Against Environment====
vSphere Version: 5.5, 6.0
PowerCLI Version: PowerCLI 6.5R1
PowerShell Version: 5.0
OS Version: Windows 10, Windows 7
===========================================================================
.DESCRIPTION
Starts the TSM-SSH service on VMHosts.
.Example
.\Start-VMHostSsh -VMHost (Get-VMHost -Name 'esxi-001.lab.local')
.Example
$OddHosts = Get-VMHost | ?{ $_.Name -match 'esxi-\d*[13579]+.\lab\.local' }
.\Start-VMHost -VMHost $OddHosts
#>
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$True,Mandatory=$True,Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]$VMHost
)
Process {
$svcSys = Get-View $VMHost.ExtensionData.ConfigManager.ServiceSystem
$svcSys.StartService('TSM-SSH')
}

View File

@@ -0,0 +1,31 @@
<#
.NOTES
===========================================================================
Script name: Stop-VMHostSsh.ps1
Created on: 2016-07-01
Author: Peter D. Jorgensen (@pjorg, pjorg.com)
Dependencies: None known
===Tested Against Environment====
vSphere Version: 5.5, 6.0
PowerCLI Version: PowerCLI 6.5R1
PowerShell Version: 5.0
OS Version: Windows 10, Windows 7
===========================================================================
.DESCRIPTION
Stops the TSM-SSH service on VMHosts.
.Example
.\Stop-VMHostSsh -VMHost (Get-VMHost -Name 'esxi-001.lab.local')
.Example
$EvenHosts = Get-VMHost | ?{ $_.Name -match 'esxi-\d*[02468]+.\lab\.local' }
.\Stop-VMHost -VMHost $EvenHosts
#>
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$True,Mandatory=$True,Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]$VMHost
)
Process {
$svcSys = Get-View $VMHost.ExtensionData.ConfigManager.ServiceSystem
$svcSys.StopService('TSM-SSH')
}

4215
Scripts/vTool_2016aug.ps1 Normal file

File diff suppressed because it is too large Load Diff