Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. <Overview of script>
  4. .DESCRIPTION
  5. <Brief description of script>
  6. .PARAMETER <Parameter_Name>
  7. <Brief description of parameter input required. Repeat this attribute if required>
  8. .INPUTS
  9. <Inputs if any, otherwise state None>
  10. .OUTPUTS Log File
  11. The script log file stored in C:\Windows\Temp\<name>.log
  12. .NOTES
  13. Version: 1.0
  14. Author: <Name>
  15. Creation Date: <Date>
  16. Purpose/Change: Initial script development
  17. .EXAMPLE
  18. <Example explanation goes here>
  19.  
  20. <Example goes here. Repeat this attribute for more than one example>
  21. #>
  22.  
  23. Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
  24. {% for host in groups['vsphere_hosts'] %}
  25. $vi_server="{{ hostvars[host]['ansible_host'] }}"
  26. $vc_user="{{ vsphere_user_info['username'] }}"
  27. $vc_pass="{{ vsphere_user_info['password'] }}"
  28.  
  29. <# Connect to vSphere Host/vCenter #>
  30. Connect-VIServer -Server $vi_server -User $vc_user -Password $vc_pass
  31.  
  32. <# Managing SSH Service #>
  33. $CurrentSSHStatus=$(Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'} | Select-Object -ExpandProperty Running)
  34. {% if hostvars[host]['vsphere_enable_ssh'] %}
  35. if ($CurrentSSHStatus -ne $true) {
  36. Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'} | Start-VMHostService -Confirm:$false
  37. }
  38. {% elif not hostvars[host]['vsphere_enable_ssh'] %}
  39. if ($CurrentSSHStatus -ne $false) {
  40. Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'} | Stop-VMHostService -Confirm:$false
  41. }
  42. {% endif %}
  43.  
  44. <# Managing NTP Service #>
  45. $CurrentNtpServers=@($(Get-VMHostNtpServer))
  46. $NewNtpServers=@($("{{ hostvars[host]['vsphere_ntp_servers']|join('", "') }}"))
  47. Foreach ($i in $NewNtpServers){
  48. if ($CurrentNtpServers -notcontains $i) {
  49. Add-VmHostNtpServer -NtpServer $i -Confirm:$false
  50. $RestartNtp="true"
  51. }
  52. }
  53. Foreach ($i in $CurrentNtpServers) {
  54. if ($NewNtpServers -notcontains $i) {
  55. Remove-VmHostNtpServer -NtpServer $i -Confirm:$false
  56. $RestartNtp="true"
  57. }
  58. }
  59. if ($RestartNtp) {
  60. if ($RestartNtp -eq "true") {
  61. Get-VMHostService | Where-Object { $_.Key -eq 'ntpd' } | Restart-VMHostService -Confirm:$false
  62. }
  63. }
  64.  
  65. <# Managing VSS vSwitch Interfaces #>
  66. {% for vswitch in hostvars[host]['vswitches'] %}
  67. $CurrentNics=@($(Get-VirtualSwitch -Name {{ vswitch['name'] }}| Get-VMHostNetworkAdapter -Physical | Select-Object -ExpandProperty Name))
  68. $NewNics=@($("{{ vswitch['nics']|join('", "') }}"))
  69. Foreach ($i in $NewNics){
  70. if ($CurrentNics -notcontains $i){
  71. $NewNic=$(Get-VMHostNetworkAdapter -Physical -Name $i)
  72. Get-VirtualSwitch -Name {{ vswitch['name'] }} | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $NewNic -Confirm:$false
  73. }
  74. }
  75. $ActiveNics=$(Get-VirtualSwitch -Name {{ vswitch['name'] }} | Get-NicTeamingPolicy | Select-Object -ExpandProperty ActiveNic)
  76. Foreach ($i in $NewNics) {
  77. if ($ActiveNics -notcontains $i){
  78. Get-VirtualSwitch -Name {{ vswitch['name'] }} | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive $i
  79. }
  80. }
  81. {% endfor %}
  82. Disconnect-VIServer * -Confirm:$false
  83. {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement