Advertisement
MichaelRyom

SSH_status.ps1

Nov 28th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3.     SSH_Status.ps1
  4. .DESCRIPTION
  5.     This script makes it possible to enable/disable SSH-TSM policy and start/stop SSH-TSM service, aswell as get SSH-TSM status
  6. .PARAMETER Command
  7.     Specifies the command you want to execute, chooses are:
  8.         ViewServiceSSH - Output Current status:
  9.            
  10.             VMHost              Key                             Running Policy
  11.             ------              ---                             ------- ------
  12.             VMhost01            TSM-SSH                           False off
  13.    
  14.         StartServiceSSH - Startes the SSH-TSM service on all host
  15.         StopServiceSSH - Stops the SSH-TSM service on all host
  16.         DisableServiceSSH - Disables the SSH-TSM service on all host
  17.         EnableServiceSSH - Enables the SSH-TSM service on all host
  18. .PARAMETER $vcenterserver
  19.     Specifies the vCenter to which you want to connect to, in order to get data from.
  20. .EXAMPLE
  21.     C:\PS>SSH_Status.ps1 ViewServiceSSH vcenter.local.domain
  22.         or
  23.        
  24.     C:\PS>SSH_Status.ps1 "StopServiceSSH;DisableServiceSSH;ViewServiceSSH" vcenter.local.domain
  25. .OUTPUTS
  26.  
  27.             VMHost              Key                             Running Policy
  28.             ------              ---                             ------- ------
  29.             VMhost01            TSM-SSH                           False off
  30.  
  31. .NOTES
  32.     Author: Michael Ryom
  33.     Date:   November 28, 2012    
  34. #>
  35. param(
  36. [Parameter(Mandatory=$false)]
  37. [string]$Command = 'get-help $MyInvocation.MyCommand.Definition -full',
  38. [Parameter(Mandatory=$false)]
  39. [string]$vcenterserver)
  40.  
  41. #ADD VMWARE SNAPIN
  42.     if(!(Get-PSSnapin | where {$_.Name -eq "VMware.VimAutomation.Core"})){
  43.         add-pssnapin VMware.VimAutomation.Core
  44.     }
  45.    
  46. #If not already logged in to vCenter, login
  47.     if($vcenterserver -ne ($global:DefaultVIServers | %{$_.Name}) -and $vcenterserver){
  48.     Connect-VIServer $vcenterserver}
  49.  
  50.     write-host
  51.     write-host
  52.  
  53.     if($vcenterserver -eq ($global:DefaultVIServers | %{$_.Name})){
  54.     $VMHost = Get-VMHost
  55.     }
  56.  
  57. function ViewServiceSSH {
  58.  foreach ($VMHost in $VMHost) {
  59.    Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "TSM-SSH"} | Select @{N="VMHost";E={$VMHost.Name}},Key,Running,Policy
  60.   }
  61. }
  62.  
  63. function StartServiceSSH {
  64.  foreach ($VMHost in $VMHost) {
  65.    Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "TSM-SSH" -and $_.running -ne $true} | Start-VMHostService -confirm:$false | Select @{N="VMHost";E={$VMHost.Name}},Key,Running,Policy | FT
  66.   }
  67. }
  68.  
  69. function StopServiceSSH {
  70.  foreach ($VMHost in $VMHost) {
  71.    Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "TSM-SSH" -and $_.running -ne $false} | Stop-VMHostService -confirm:$false | Select @{N="VMHost";E={$VMHost.Name}},Key,Running,Policy | FT
  72.   }
  73. }
  74.  
  75. function DisableServiceSSH {
  76.  foreach ($VMHost in $VMHost) {
  77.    Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "TSM-SSH" -and $_.Policy -ne "off"} | Set-VMHostService -Policy "off" -confirm:$false | Select @{N="VMHost";E={$VMHost.Name}},Key,Running,Policy | FT
  78.   }
  79. }
  80.  
  81. function EnableServiceSSH {
  82. param(
  83. [Parameter(Mandatory=$true)]
  84. [string]$policy = "on")
  85.  
  86.  foreach ($VMHost in $VMHost) {
  87.    Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "TSM-SSH" -and $_.Policy -ne $policy} | Set-VMHostService -Policy $policy -confirm:$false | Select @{N="VMHost";E={$VMHost.Name}},Key,Running,Policy | FT
  88.   }
  89. }
  90.  
  91. Invoke-Expression $Command
  92.  
  93. Write-Host "Press any key to continue ..."
  94. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")   
  95. if($vcenterserver -eq ($global:DefaultVIServers | %{$_.Name})){
  96. Disconnect-VIServer -confirm:$false
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement