<#
.SYNOPSIS
disables SSH/techsupport shell and Disables timeouts
.DESCRIPTION
disables SSH/techsupport shell and Disables timeouts
.PARAMETER VIserver
The name of a the Viserver.
.EXAMPLE
lock-vceEsxihosts -viserver vc.somedomain.com
#>
function lock-VCESXiHosts {
param ([Parameter(Position=0, Mandatory=$true)][System.String]$viserver)
[System.Collections.ArrayList]$ArrResults=@()
if ((Get-Module -Name VMware.VimAutomation.Core) -eq $null){import-module -Name VMware.VimAutomation.Core}
if (($global:DefaultVIServer.name -eq $viserver -and $global:DefaultVIServer.IsConnected -eq $false) -or ($global:DefaultVIServer.name -eq $null))
{try{connect-viserver $viserver -ea stop | Out-Null} catch { write-host $viserver "failed to connect";break }}
foreach ($hostentity in (get-vmhost -Server $viserver)){
$ESXCli=Get-EsxCli -VMHost $hostentity
$ESXiShellInteractiveTimeout="";$ESXiShellTimeout="";$setESXiST="";$setESXiSiT=""
#shell Timeouts
$ESXiShellInteractiveTimeout=$hostentity|Get-AdvancedSetting|where {$_.name -eq 'UserVars.ESXiShellInteractiveTimeout'}
if ($ESXiShellInteractiveTimeout.Value -ne 300){
$setESXiSIT=$ESXiShellInteractiveTimeout| Set-AdvancedSetting -Value "300" -Confirm:$false
write-host $hostentity.name ":" $setESXiSIT.name ":" $setESXiSIT.value
}
$ESXiShellTimeout=$hostentity| Get-AdvancedSetting|where {$_.name -eq 'uservars.esxishelltimeout'}
if ($ESXiShellTimeout.Value -ne 300){
$setESXiST=$ESXiShellTimeout|Set-AdvancedSetting -Value "300" -Confirm:$false
write-host $hostentity.name ":" $setESXiST.name ":" $setESXiST.value
}
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'SSH'}|Stop-VMHostService -Confirm:$false|Out-Null
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'ESXi Shell'}|Stop-VMHostService -Confirm:$false|Out-Null
}
}
<#
.SYNOPSIS
Enables SSH/techsupport shell and Disables timeouts
.DESCRIPTION
Enables SSH/techsupport shell and Disables timeouts
.PARAMETER VIserver
The name of a the Viserver.
.EXAMPLE
lock-vceEsxihosts -viserver vc.somedomain.com
#>
function Unlock-VCESXiHosts {
param ([Parameter(Position=0, Mandatory=$true)][System.String]$viserver)
[System.Collections.ArrayList]$ArrResults=@()
if ((Get-Module -Name VMware.VimAutomation.Core) -eq $null){import-module -Name VMware.VimAutomation.Core}
if (($global:DefaultVIServer.name -eq $viserver -and $global:DefaultVIServer.IsConnected -eq $false) -or ($global:DefaultVIServer.name -eq $null))
{try{connect-viserver $viserver -ea stop | Out-Null} catch { write-host $viserver "failed to connect";break }}
foreach ($hostentity in (get-vmhost -Server $viserver )){
$ESXCli=Get-EsxCli -VMHost $hostentity
$ESXiShellInteractiveTimeout="";$ESXiShellTimeout="";$setESXiST="";$setESXiSiT=""
#shell Timeouts
$ESXiShellInteractiveTimeout=$hostentity|Get-AdvancedSetting|where {$_.name -eq 'UserVars.ESXiShellInteractiveTimeout'}
if ($ESXiShellInteractiveTimeout.Value -eq 300){
$setESXiSIT=$ESXiShellInteractiveTimeout| Set-AdvancedSetting -Value "0" -Confirm:$false
write-host $hostentity.name ":" $setESXiSIT.name ":" $setESXiSIT.value
}
$ESXiShellTimeout=$hostentity| Get-AdvancedSetting|where {$_.name -eq 'uservars.esxishelltimeout'}
if ($ESXiShellTimeout.Value -eq 300){
$setESXiST=$ESXiShellTimeout|Set-AdvancedSetting -Value "0" -Confirm:$false
write-host $hostentity.name ":" $setESXiST.name ":" $setESXiST.value
}
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'SSH'}|Start-VMHostService -Confirm:$false|Out-Null
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'ESXi Shell'}|Start-VMHostService -Confirm:$false|Out-Null
}
}
<#
.SYNOPSIS
Enables SSH/techsupport shell and Disables timeouts
.DESCRIPTION
Enables SSH/techsupport shell and Disables timeouts
.PARAMETER VIserver
The name of a the Viserver.
.PARAMETER esxhost
The name of a the esxhost.
.EXAMPLE
unlock-vceEsxihosts -viserver vc.somedomain.com
#>
function UNlock-ESXiHost {
param ([Parameter(Position=0, Mandatory=$true)][System.String]$viserver,
[Parameter(Position=1, Mandatory=$true)][System.String]$esxhost
)
[System.Collections.ArrayList]$ArrResults=@()
if ((Get-Module -Name VMware.VimAutomation.Core) -eq $null){import-module -Name VMware.VimAutomation.Core}
if (($global:DefaultVIServer.name -eq $viserver -and $global:DefaultVIServer.IsConnected -eq $false) -or ($global:DefaultVIServer.name -eq $null))
{try{connect-viserver $viserver -ea stop | Out-Null} catch { write-host $viserver "failed to connect";break }}
$hostentity=get-vmhost -Server $viserver -Name $esxhost
$ESXCli=Get-EsxCli -VMHost $hostentity
$ESXiShellInteractiveTimeout="";$ESXiShellTimeout="";$setESXiST="";$setESXiSiT=""
#shell Timeouts
$ESXiShellInteractiveTimeout=$hostentity|Get-AdvancedSetting|where {$_.name -eq 'UserVars.ESXiShellInteractiveTimeout'}
if ($ESXiShellInteractiveTimeout.Value -eq 300){
$setESXiSIT=$ESXiShellInteractiveTimeout| Set-AdvancedSetting -Value "0" -Confirm:$false
write-host $hostentity.name ":" $setESXiSIT.name ":" $setESXiSIT.value
}
$ESXiShellTimeout=$hostentity| Get-AdvancedSetting|where {$_.name -eq 'uservars.esxishelltimeout'}
if ($ESXiShellTimeout.Value -eq 300){
$setESXiST=$ESXiShellTimeout|Set-AdvancedSetting -Value "0" -Confirm:$false
write-host $hostentity.name ":" $setESXiST.name ":" $setESXiST.value
}
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'SSH'}|Start-VMHostService -Confirm:$false|Out-Null
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'ESXi Shell'}|Start-VMHostService -Confirm:$false|Out-Null
}
<#
.SYNOPSIS
disables SSH/techsupport shell and Disables timeouts
.DESCRIPTION
disables SSH/techsupport shell and Disables timeouts
.PARAMETER VIserver
The name of a the Viserver.
.PARAMETER esxhost
The name of a the esxhost.
.EXAMPLE
lock-vceEsxihosts -viserver vc.somedomain.com -esxhost host.example.com
#>
function lock-ESXiHost {
param ([Parameter(Position=0, Mandatory=$true)][System.String]$viserver,
[Parameter(Position=1, Mandatory=$true)][System.String]$esxhost
)
[System.Collections.ArrayList]$ArrResults=@()
if ((Get-Module -Name VMware.VimAutomation.Core) -eq $null){import-module -Name VMware.VimAutomation.Core}
if (($global:DefaultVIServer.name -eq $viserver -and $global:DefaultVIServer.IsConnected -eq $false) -or ($global:DefaultVIServer.name -eq $null))
{try{connect-viserver $viserver -ea stop | Out-Null} catch { write-host $viserver "failed to connect";break }}
$hostentity=get-vmhost -Server $viserver -Name $esxhost
$ESXCli=Get-EsxCli -VMHost $hostentity
$ESXiShellInteractiveTimeout="";$ESXiShellTimeout="";$setESXiST="";$setESXiSiT=""
#shell Timeouts
$ESXiShellInteractiveTimeout=$hostentity|Get-AdvancedSetting|where {$_.name -eq 'UserVars.ESXiShellInteractiveTimeout'}
if ($ESXiShellInteractiveTimeout.Value -eq 0){
$setESXiSIT=$ESXiShellInteractiveTimeout| Set-AdvancedSetting -Value "300" -Confirm:$false
write-host $hostentity.name ":" $setESXiSIT.name ":" $setESXiSIT.value
}
$ESXiShellTimeout=$hostentity| Get-AdvancedSetting|where {$_.name -eq 'uservars.esxishelltimeout'}
if ($ESXiShellTimeout.Value -eq 0){
$setESXiST=$ESXiShellTimeout|Set-AdvancedSetting -Value "300" -Confirm:$false
write-host $hostentity.name ":" $setESXiST.name ":" $setESXiST.value
}
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'ESXi Shell'}|Stop-VMHostService -Confirm:$false|Out-Null
Get-VMHostService -VMHost $hostentity.name|?{$_.Label -eq 'SSH'}|Stop-VMHostService -Confirm:$false|Out-Null
}
<#
.SYNOPSIS
Pings an IP through a specific kernal port
.DESCRIPTION
Pings an IP through a specific kernal port
.PARAMETER VIserver
The name of a the Viserver.
.PARAMETER esxserver
The name of a the esxhost.
.EXAMPLE
esxi-VMKPing -viserver vc.somedomain.com -esxhost host.example.com -pingip 192.168.1.1 -vmkinterface vmk0
#>
Function esxi-VMKPing {
Param(
[Parameter(Position=0, Mandatory=$true)][System.String]$viServer,
[Parameter(Position=1, Mandatory=$true)][System.String]$esxhost,
[Parameter(Position=2, Mandatory=$true)][System.String]$pingIP,
[Parameter(Position=3, Mandatory=$true)]$vmkinterface,
$Count=3, $vmkdebug=$false, $DFbit=$true, $Interval = 1, $ipv4=$true,$ipv6=$false
)
if ((Get-Module -Name VMware.VimAutomation.Core) -eq $null){import-module -Name VMware.VimAutomation.Core}
try {connect-viserver $ViServer -ea Stop | Out-Null } catch {write-host $error[0] -ForegroundColor RED;break}
$hostentity=get-vmhost $esxhost -server $viserver
$ESXCli=Get-EsxCli -VMHost $hostentity
$PingResult=$ESXCli.network.diag.ping($Count,$vmkdebug,$DFbit,$PingIP,$vmkinterface,$Interval,$ipv4,$ipv6).summary
Write-Host "Pinged Host:" $PingResult.HostAddr
if ($PingResult.PacketLost -ne 0) {Write-Host "PacketLost:" $PingResult.PacketLost -ForegroundColor RED} Else {Write-Host "PacketLost:" $PingResult.PacketLost -ForegroundColor Green}
Write-Host "Recieved:" $PingResult.Recieved
Write-Host "RoundtripAvgMS:" $PingResult.RoundtripAvgMS
Write-Host "RoundtripMaxMS:" $PingResult.RoundtripMaxMS
Write-Host "RoundtripMinMS:" $PingResult.RoundtripMinMS
Write-Host "Transmitted:" $PingResult.Transmitted
}