Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- <Overview of script>
- .DESCRIPTION
- <Brief description of script>
- .PARAMETER <Parameter_Name>
- <Brief description of parameter input required. Repeat this attribute if required>
- .INPUTS
- <Inputs if any, otherwise state None>
- .OUTPUTS Log File
- The script log file stored in C:\Windows\Temp\<name>.log
- .NOTES
- Version: 1.0
- Author: <Name>
- Creation Date: <Date>
- Purpose/Change: Initial script development
- .EXAMPLE
- <Example explanation goes here>
- <Example goes here. Repeat this attribute for more than one example>
- #>
- Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
- {% for host in groups['vsphere_hosts'] %}
- $vi_server="{{ hostvars[host]['ansible_host'] }}"
- $vc_user="{{ vsphere_user_info['username'] }}"
- $vc_pass="{{ vsphere_user_info['password'] }}"
- <# Connect to vSphere Host/vCenter #>
- Connect-VIServer -Server $vi_server -User $vc_user -Password $vc_pass
- <# Managing SSH Service #>
- $CurrentSSHStatus=$(Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'} | Select-Object -ExpandProperty Running)
- {% if hostvars[host]['vsphere_enable_ssh'] %}
- if ($CurrentSSHStatus -ne $true) {
- Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'} | Start-VMHostService -Confirm:$false
- }
- {% elif not hostvars[host]['vsphere_enable_ssh'] %}
- if ($CurrentSSHStatus -ne $false) {
- Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'} | Stop-VMHostService -Confirm:$false
- }
- {% endif %}
- <# Managing NTP Service #>
- $CurrentNtpServers=@($(Get-VMHostNtpServer))
- $NewNtpServers=@($("{{ hostvars[host]['vsphere_ntp_servers']|join('", "') }}"))
- Foreach ($i in $NewNtpServers){
- if ($CurrentNtpServers -notcontains $i) {
- Add-VmHostNtpServer -NtpServer $i -Confirm:$false
- $RestartNtp="true"
- }
- }
- Foreach ($i in $CurrentNtpServers) {
- if ($NewNtpServers -notcontains $i) {
- Remove-VmHostNtpServer -NtpServer $i -Confirm:$false
- $RestartNtp="true"
- }
- }
- if ($RestartNtp) {
- if ($RestartNtp -eq "true") {
- Get-VMHostService | Where-Object { $_.Key -eq 'ntpd' } | Restart-VMHostService -Confirm:$false
- }
- }
- <# Managing VSS vSwitch Interfaces #>
- {% for vswitch in hostvars[host]['vswitches'] %}
- $CurrentNics=@($(Get-VirtualSwitch -Name {{ vswitch['name'] }}| Get-VMHostNetworkAdapter -Physical | Select-Object -ExpandProperty Name))
- $NewNics=@($("{{ vswitch['nics']|join('", "') }}"))
- Foreach ($i in $NewNics){
- if ($CurrentNics -notcontains $i){
- $NewNic=$(Get-VMHostNetworkAdapter -Physical -Name $i)
- Get-VirtualSwitch -Name {{ vswitch['name'] }} | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $NewNic -Confirm:$false
- }
- }
- $ActiveNics=$(Get-VirtualSwitch -Name {{ vswitch['name'] }} | Get-NicTeamingPolicy | Select-Object -ExpandProperty ActiveNic)
- Foreach ($i in $NewNics) {
- if ($ActiveNics -notcontains $i){
- Get-VirtualSwitch -Name {{ vswitch['name'] }} | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive $i
- }
- }
- {% endfor %}
- Disconnect-VIServer * -Confirm:$false
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement