<# .SYNOPSIS A short one-line action-based description, e.g. 'Tests if a function is valid' .DESCRIPTION A longer description of the function, its purpose, common use cases, etc. .NOTES Information or caveats about the function e.g. 'This function is not supported in Linux' .LINK Specify a URI to a help page, this will show when Get-Help -Online is used. .EXAMPLE Test-MyTestFunction -Verbose Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines #> function Set-ITDVMwareVMHardening { [CmdletBinding()] param( [string[]] $Name ) Begin { } Process { If ($Name) { $VMs = Get-VM -Name $Name | Where-Object { $_.ExtensionData.Summary.Config.ManagedBy.Type -ne "placeholderVm" } } Else { $VMs = Get-VM -Name $Name | Where-Object { $_.ExtensionData.Summary.Config.ManagedBy.Type -ne "placeholderVm" } } $SettingName = @( "tools.setInfo.sizeLimit", "isolation.device.edit.disable", "isolation.device.connectable.disable", "isolation.tools.copy.disable", "isolation.tools.dnd.disable", "isolation.tools.setGUIOptions.enable", "isolation.tools.paste.disable", "isolation.tools.diskShrink.disable", "isolation.tools.diskWiper.disable", "log.keepOld", "log.rotateSize" ) $Result = [System.Collections.ArrayList]@() ForEach ($VM in $VMs) { $GetAdvSetting = Get-AdvancedSetting -Entity $VM -Name $SettingName | select Entity, Name, Value $obj = [PSCustomObject]@{ 'Entity' = $VM.Name 'Uid' = $VM.Uid.split('@')[1].split(':')[0] "tools.setInfo.sizeLimit" = ($GetAdvSetting | Where-Object Name -EQ 'tools.setInfo.sizeLimit').Value "isolation.device.edit.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.device.edit.disable').Value "isolation.device.connectable.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.device.connectable.disable').Value "isolation.tools.copy.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.tools.copy.disable').Value "isolation.tools.dnd.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.tools.dnd.disable').Value "isolation.tools.setGUIOptions.enable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.tools.setGUIOptions.enable').Value "isolation.tools.paste.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.tools.paste.disable').Value "isolation.tools.diskShrink.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.tools.diskShrink.disable').Value "isolation.tools.diskWiper.disable" = ($GetAdvSetting | Where-Object Name -EQ 'isolation.tools.diskWiper.disable').Value "log.keepOld" = ($GetAdvSetting | Where-Object Name -EQ 'log.keepOld').Value "log.rotateSize" = ($GetAdvSetting | Where-Object Name -EQ 'log.rotateSize').Value } $Result.Add($obj) } $Result # remediate VMs ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'tools.setInfo.sizeLimit' -ne 1048576 }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'tools.setInfo.sizeLimit' -Value '1048576' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.device.edit.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.device.edit.disable' -Value 'TRUE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.device.connectable.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.device.connectable.disable' -Value TRUE -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.tools.copy.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.tools.copy.disable' -Value 'TRUE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.tools.dnd.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.tools.dnd.disable' -Value 'TRUE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.tools.setGUIOptions.enable' -ne "FALSE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.tools.setGUIOptions.enable' -Value 'FALSE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.tools.paste.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.tools.paste.disable' -Value 'TRUE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.tools.diskShrink.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.tools.diskShrink.disable' -Value 'TRUE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'isolation.tools.diskWiper.disable' -ne "TRUE" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'isolation.tools.diskWiper.disable' -Value 'TRUE' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'log.keepOld' -ne "10" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'log.keepOld' -Value '10' -Confirm:$false -Force:$true } ForEach ($VM in ($Result | Where-Object { $_.Entity -notlike "vCLS*" -and $_.'log.rotateSize' -ne "1024000" }) ) { Get-VM -Name $VM.Entity -Server $VM.Uid | New-AdvancedSetting -Name 'log.rotateSize' -Value '10' -Confirm:$false -Force:$true } } End { } }