├── .gitignore ├── Cisco UCS └── Set-LocatorLED.ps1 ├── LICENSE ├── README.md ├── Slack ├── Post-ToSlack.ps1 └── token.txt ├── VMware NSX └── Get-NSXController.ps1 ├── VMware View └── Remove-ViewPoolOwnership.ps1 ├── VMware vSphere ├── Add-VMTemplate.ps1 ├── Balance-VM.ps1 ├── Clone-VM.ps1 ├── Get-PSP.ps1 ├── Get-vCenterPlurinURL.ps1 ├── Reset-CBT.ps1 ├── Search-CapacityPlanner.ps1 ├── Search-RVToolsReport.ps1 ├── Set-CustomizationSpec.ps1 ├── Set-NTPServer.ps1 ├── Set-vSphereReplicationLimit.ps1 ├── Update-ResourcePool.ps1 └── Update-VMwareTools.ps1 └── WahlNetwork ├── Load-Scripts.psm1 ├── README.md └── WahlNetwork.psd1 /.gitignore: -------------------------------------------------------------------------------- 1 | *.db -------------------------------------------------------------------------------- /Cisco UCS/Set-LocatorLED.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/Cisco UCS/Set-LocatorLED.ps1 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Wahl Network Scripts Repository 2 | ================ 3 | 4 | This repository contains a number of scripts that I have written or enhanced to make day-to-day life easier for administrators, engineers, and architects. These are provided for free to the community under an [Apache License v2](http://www.apache.org/licenses/LICENSE-2.0.html). I also have a number of [PowerShell related blog posts](http://wahlnetwork.com/?s=powershell) at Wahl Network for those interested. 5 | 6 | # Installation 7 | 8 | Make sure you have PowerShell version 4 or higher installed on your workstation. I'd also suggest installing PowerCLI version 6 or higher. 9 | 10 | 1. Download the contents of this repository to your workstation. 11 | 2. Copy over the scripts found in any of the directories (such as `Slack`, `VMware NSX`, `VMware vSphere`, or others) into the `WahlNetwork` folder. 12 | 2. Copy the contents of the `WahlNetwork` folder onto your workstation into the path `$Home\Documents\WindowsPowerShell\Modules\` 13 | 14 | Launch PowerShell and make sure `Set-ExecutionPolicy` is set to `RemoteSigned` or `Bypass`. To load the module, use `Import-Module WahlNetwork`. 15 | 16 | # Usage Instructions 17 | 18 | To see all of the imported commands, use `Get-Command -Module WahlNetwork`. 19 | 20 | # Future 21 | 22 | Any PowerShell related scripts will be added here over time as I write them. There is no grand scheme here. 23 | 24 | # Contribution 25 | 26 | Create a fork of the project into your own reposity. Make all your necessary changes and create a pull request with a description on what was added or removed and details explaining the changes in lines of code. If approved, project owners will merge it. 27 | 28 | # Licensing 29 | 30 | Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 31 | 32 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 33 | -------------------------------------------------------------------------------- /Slack/Post-ToSlack.ps1: -------------------------------------------------------------------------------- 1 | #requires -Version 3 2 | 3 | function Post-ToSlack 4 | { 5 | <# 6 | .SYNOPSIS 7 | Sends a chat message to a Slack organization 8 | .DESCRIPTION 9 | The Post-ToSlack cmdlet is used to send a chat message to a Slack channel, group, or person. 10 | Slack requires a token to authenticate to an org. Either place a file named token.txt in the same directory as this cmdlet, 11 | or provide the token using the -token parameter. For more details on Slack tokens, use Get-Help with the -Full arg. 12 | .NOTES 13 | Written by Chris Wahl for community usage 14 | Twitter: @ChrisWahl 15 | GitHub: chriswahl 16 | .EXAMPLE 17 | Post-ToSlack -channel '#general' -message 'Hello everyone!' -botname 'The Borg' 18 | This will send a message to the #General channel, and the bot's name will be The Borg. 19 | .EXAMPLE 20 | Post-ToSlack -channel '#general' -message 'Hello everyone!' -token '1234567890' 21 | This will send a message to the #General channel using a specific token 1234567890, and the bot's name will be default (PowerShell Bot). 22 | .LINK 23 | Validate or update your Slack tokens: 24 | https://api.slack.com/tokens 25 | Create a Slack token: 26 | https://api.slack.com/web 27 | More information on Bot Users: 28 | https://api.slack.com/bot-users 29 | #> 30 | 31 | Param( 32 | [Parameter(Mandatory = $true,Position = 0,HelpMessage = 'Slack channel')] 33 | [ValidateNotNullorEmpty()] 34 | [String]$Channel, 35 | [Parameter(Mandatory = $true,Position = 1,HelpMessage = 'Chat message')] 36 | [ValidateNotNullorEmpty()] 37 | [String]$Message, 38 | [Parameter(Mandatory = $false,Position = 2,HelpMessage = 'Slack API token')] 39 | [ValidateNotNullorEmpty()] 40 | [String]$token, 41 | [Parameter(Mandatory = $false,Position = 3,HelpMessage = 'Optional name for the bot')] 42 | [String]$BotName = 'PowerShell Bot' 43 | ) 44 | 45 | Process { 46 | 47 | # Static parameters 48 | if (!$token) 49 | { 50 | $token = Get-Content -Path "$PSScriptRoot\token.txt" 51 | } 52 | $uri = 'https://slack.com/api/chat.postMessage' 53 | 54 | # Build the body as per https://api.slack.com/methods/chat.postMessage 55 | $body = @{ 56 | token = $token 57 | channel = $Channel 58 | text = $Message 59 | username = $BotName 60 | parse = 'full' 61 | } 62 | 63 | # Call the API 64 | try 65 | { 66 | Invoke-RestMethod -Uri $uri -Body $body 67 | } 68 | catch 69 | { 70 | throw 'Unable to call the API' 71 | } 72 | 73 | } # End of process 74 | } # End of function -------------------------------------------------------------------------------- /Slack/token.txt: -------------------------------------------------------------------------------- 1 | Put your token in here and remove all other text! 2 | 3 | Validate or update your Slack tokens: 4 | https://api.slack.com/tokens 5 | Create a Slack token: 6 | https://api.slack.com/web -------------------------------------------------------------------------------- /VMware NSX/Get-NSXController.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware NSX/Get-NSXController.ps1 -------------------------------------------------------------------------------- /VMware View/Remove-ViewPoolOwnership.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware View/Remove-ViewPoolOwnership.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Add-VMTemplate.ps1: -------------------------------------------------------------------------------- 1 | #requires -Version 2 2 | 3 | # Variables 4 | 5 | $vcenter = 'vc1.glacier.local' # Connects to this vCenter Server. 6 | $Cluster = 'Lab' # Adds templates to this cluster. 7 | $Datastores = 'NAS2-Lab' # Searches these datastores for templates. 8 | $VMFolder = 'Staging' # Imports templates into this folder. 9 | 10 | # Import modules or snapins 11 | $powercli = Get-PSSnapin -Name VMware.VimAutomation.Core -Registered 12 | 13 | try 14 | { 15 | switch ($powercli.Version.Major) { 16 | { 17 | $_ -ge 6 18 | } 19 | { 20 | Import-Module -Name VMware.VimAutomation.Core -ErrorAction Stop 21 | Write-Host -Object 'PowerCLI 6+ module imported' 22 | } 23 | 5 24 | { 25 | Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction Stop 26 | Write-Warning -Message 'PowerCLI 5 snapin added; recommend upgrading your PowerCLI version' 27 | } 28 | default 29 | { 30 | throw 'This script requires PowerCLI version 5 or later' 31 | } 32 | } 33 | } 34 | catch 35 | { 36 | throw 'Could not load the required VMware.VimAutomation.Core cmdlets' 37 | } 38 | 39 | # Ignore self-signed SSL certificates for vCenter Server (optional) 40 | Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false 41 | 42 | # Connect to vCenter 43 | try 44 | { 45 | $null = Connect-VIServer $vcenter -ErrorAction Stop 46 | } 47 | catch 48 | { 49 | throw 'Could not connect to vCenter' 50 | } 51 | 52 | # Select an ESXi host to own the templates for the import process 53 | $ESXHost = Get-Cluster $Cluster | Get-VMHost | Select-Object -First 1 54 | 55 | foreach($Datastore in Get-Datastore $Datastores) 56 | { 57 | # Collect .vmtx paths of registered VMs on the datastore 58 | $registered = @{} 59 | Get-Template -Datastore $Datastore | ForEach-Object -Process { 60 | $registered.Add($_.Name+'.vmtx',$true) 61 | } 62 | 63 | # Set up Search for .VMTX Files in Datastore 64 | $null = New-PSDrive -Name TgtDS -Location $Datastore -PSProvider VimDatastore -Root '\' 65 | $unregistered = @(Get-ChildItem -Path TgtDS: -Recurse | ` 66 | Where-Object -FilterScript { 67 | $_.FolderPath -notmatch '.snapshot' -and $_.Name -like '*.vmtx' -and !$registered.ContainsKey($_.Name) 68 | } 69 | ) 70 | Remove-PSDrive -Name TgtDS 71 | 72 | #Register all .vmtx Files as VMs on the datastore 73 | foreach($vmtxFile in $unregistered) 74 | { 75 | New-Template -Name $vmtxFile.Name -TemplateFilePath $vmtxFile.DatastoreFullPath -VMHost $ESXHost -Location $VMFolder -RunAsync 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /VMware vSphere/Balance-VM.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Balance-VM.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Clone-VM.ps1: -------------------------------------------------------------------------------- 1 | # Variables 2 | $vc = "vc1.glacier.local" 3 | $newvm = "Example VM" 4 | $template = "Server 2012 R2 Template" 5 | $custspec = "2012R2_DataCenter_PowerCLI" 6 | $portgroup = "VLAN20-Servers" 7 | 8 | # Add the required PowerCLI snapin/module 9 | try 10 | { 11 | Import-Module VMware.VimAutomation.Vds -ErrorAction Stop 12 | Write-Host -ForegroundColor Yellow -BackgroundColor Black "Status: PowerCLI version 6.0+ found." 13 | } 14 | catch 15 | { 16 | try {Add-PSSnapin VMware.VimAutomation.Vds -ErrorAction Stop} catch {throw "You are missing the VMware.VimAutomation.Vds snapin"} 17 | Write-Host -ForegroundColor Yellow -BackgroundColor Black "Status: PowerCLI prior to version 6.0 found." 18 | } 19 | 20 | # Connect to vCenter 21 | Connect-VIServer $vc | Out-Null 22 | 23 | # Update the Customization Specification 24 | Get-OSCustomizationSpec $custspec ` 25 | | Get-OSCustomizationNicMapping ` 26 | | Set-OSCustomizationNicMapping ` 27 | -IpMode:UseStaticIP ` 28 | -IpAddress (Read-Host "IP Address: ") ` 29 | -SubnetMask (Read-Host "Subnet Mask: ") ` 30 | -Dns (Read-Host "DNS Server IP: ") ` 31 | -DefaultGateway (Read-Host "Default Gateway IP: ") 32 | 33 | # Clone the VM 34 | New-VM -VM $template -Name $newvm -LinkedClone -ReferenceSnapshot "LinkedClone" -Location (Get-Folder Staging) -ResourcePool (Get-Cluster Lab) -OSCustomizationSpec $custspec 35 | 36 | # Move VM to correct port group 37 | try {Get-VM $newvm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $portgroup -Confirm:$false -ErrorAction Stop} 38 | catch {break} -------------------------------------------------------------------------------- /VMware vSphere/Get-PSP.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Get-PSP.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Get-vCenterPlurinURL.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Get-vCenterPlurinURL.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Reset-CBT.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Version 2 2 | function Reset-CBT 3 | { 4 | <# 5 | .SYNOPSIS 6 | Resets the Change Block Tracking (CBT) file for affected Virtual Machines 7 | .DESCRIPTION 8 | The Reset-CBT cmdlet will reset the Change Block Tracking (CBT) file for a Virtual Machine affected by issues or corruption with the CBT file. 9 | .NOTES 10 | Written by Chris Wahl for community usage 11 | Twitter: @ChrisWahl 12 | GitHub: chriswahl 13 | .LINK 14 | https://github.com/WahlNetwork/powershell-scripts 15 | .EXAMPLE 16 | Reset-CBT -VM 'WAHLNETWORK' -vCenter VCENTER.DOMAIN.LOCAL 17 | Disables CBT for a VM named WAHLNETWORK, then creates and consolidates (remove) a snapshot to flush the CBT file. The assumption here is that your backup software will then re-enable CBT during the next backup job. 18 | .EXAMPLE 19 | Reset-CBT -VM 'WAHLNETWORK' -vCenter VCENTER.DOMAIN.LOCAL -NoSnapshots 20 | Disables CBT for a VM named WAHLNETWORK but will not use a snapshot to flush the CBT file. This is useful for environments where you simply want to disable CBT and do not have backup software that will go back and re-enable CBT. 21 | .EXAMPLE 22 | Reset-CBT -VM $VMlist -vCenter VCENTER.DOMAIN.LOCAL 23 | Disables CBT for all VMs in the list $VMlist, which can be useful for more targeted lists of virtual machines that don't easily match a regular expression. 24 | Here are some methods to build $VMlist 25 | 26 | $VMlist = Get-VM -Location (Get-Folder 'Test Servers') 27 | $VMlist = Get-VM -Location (Get-DataCenter 'Austin') 28 | .EXAMPLE 29 | Get-VM -Location (Get-Folder 'Test Servers') | Reset-CBT -vCenter VCENTER.DOMAIN.LOCAL 30 | Similar to the previous example, except that it uses a pipeline for the list of virtual machines. 31 | .EXAMPLE 32 | Reset-CBT -VM 'WAHLNETWORK' -vCenter VCENTER.DOMAIN.LOCAL -EnableCBT 33 | Enables CBT for a VM named WAHLNETWORK. No other activities are performed. This is useful for when you want to enable CBT for one or more virtual machines. 34 | #> 35 | 36 | [CmdletBinding()] 37 | Param( 38 | [Parameter(Mandatory = $true,Position = 0,HelpMessage = 'Virtual Machine',ValueFromPipeline = $true)] 39 | [Alias('Name')] 40 | [ValidateNotNullorEmpty()] 41 | $VM, 42 | [Parameter(Mandatory = $true,Position = 1,HelpMessage = 'vCenter FQDN or IP address')] 43 | [ValidateNotNullorEmpty()] 44 | [String]$vCenter, 45 | [Parameter(Mandatory = $false,Position = 2,HelpMessage = 'Enables CBT for any VMs found with it disabled')] 46 | [ValidateNotNullorEmpty()] 47 | [Switch]$EnableCBT, 48 | [Parameter(Mandatory = $false,Position = 3,HelpMessage = 'Prevents usings snapshots from flushing the CBT file')] 49 | [ValidateNotNullorEmpty()] 50 | [Switch]$NoSnapshots 51 | ) 52 | 53 | Process { 54 | 55 | Write-Verbose -Message 'Importing required modules and snapins' 56 | $powercli = Get-PSSnapin -Name VMware.VimAutomation.Core -Registered 57 | try 58 | { 59 | switch ($powercli.Version.Major) { 60 | { 61 | $_ -ge 6 62 | } 63 | { 64 | Import-Module -Name VMware.VimAutomation.Core -ErrorAction Stop 65 | Write-Verbose -Message 'PowerCLI 6+ module imported' 66 | } 67 | 5 68 | { 69 | Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction Stop 70 | Write-Warning -Message 'PowerCLI 5 snapin added; recommend upgrading your PowerCLI version' 71 | } 72 | default 73 | { 74 | throw 'This script requires PowerCLI version 5 or later' 75 | } 76 | } 77 | } 78 | catch 79 | { 80 | throw $_ 81 | } 82 | 83 | 84 | Write-Verbose -Message 'Ignoring self-signed SSL certificates for vCenter Server (optional)' 85 | $null = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false 86 | 87 | Write-Verbose -Message 'Connecting to vCenter' 88 | try 89 | { 90 | $null = Connect-VIServer -Server $vCenter -ErrorAction Stop -Session ($global:DefaultVIServers | Where-Object -FilterScript { 91 | $_.name -eq $vCenter 92 | }).sessionId 93 | } 94 | catch 95 | { 96 | throw 'Could not connect to vCenter' 97 | } 98 | 99 | Write-Verbose -Message 'Gathering data on VM inventory' 100 | $fixvm = Get-VM $VM 101 | [array]$notfixedvm = $null 102 | 103 | Write-Verbose -Message 'Creating configuration specification' 104 | $vmconfigspec = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec 105 | 106 | Write-Verbose -Message 'Walking through VM inventory' 107 | foreach($_ in $fixvm) 108 | { 109 | if ($EnableCBT -ne $true -and $_.ExtensionData.Config.ChangeTrackingEnabled -eq $true -and $_.PowerState -eq 'PoweredOn' -and $_.ExtensionData.Snapshot -eq $null) 110 | { 111 | try 112 | { 113 | Write-Verbose -Message "Reconfiguring $($_.name) to disable CBT" -Verbose 114 | $vmconfigspec.ChangeTrackingEnabled = $false 115 | $_.ExtensionData.ReconfigVM($vmconfigspec) 116 | 117 | if ($NoSnapshots -ne $true) 118 | { 119 | Write-Verbose -Message "Creating a snapshot on $($_.name) to clear CBT file" -Verbose 120 | $null = New-Snapshot -VM $_ -Name 'CBT Cleanup' 121 | 122 | Write-Verbose -Message "Removing snapshot on $($_.name)" -Verbose 123 | $null = $_ | 124 | Get-Snapshot | 125 | Remove-Snapshot -RemoveChildren -Confirm:$false 126 | } 127 | } 128 | catch 129 | { 130 | throw $_ 131 | } 132 | } 133 | elseif ($EnableCBT -and $_.ExtensionData.Config.ChangeTrackingEnabled -eq $false) 134 | { 135 | Write-Verbose -Message "Reconfiguring $($_.name) to enable CBT" -Verbose 136 | $vmconfigspec.ChangeTrackingEnabled = $true 137 | $_.ExtensionData.ReconfigVM($vmconfigspec) 138 | } 139 | else 140 | { 141 | if ($_.PowerState -ne 'PoweredOn' -and $EnableCBT -ne $true) 142 | { 143 | Write-Warning -Message "Skipping $_ - Not powered on" 144 | $notfixedvm += $_ 145 | } 146 | if ($_.ExtensionData.Snapshot -ne $null -and $EnableCBT -ne $true) 147 | { 148 | Write-Warning -Message "Skipping $_ - Snapshots found" 149 | $notfixedvm += $_ 150 | } 151 | } 152 | } 153 | 154 | if ($notfixedvm -ne $null) 155 | { 156 | Write-Warning -Message 'The following VMs were not altered' 157 | $notfixedvm | Format-Table -AutoSize 158 | } 159 | 160 | } # End of process 161 | } # End of function -------------------------------------------------------------------------------- /VMware vSphere/Search-CapacityPlanner.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Search-CapacityPlanner.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Search-RVToolsReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Search-RVToolsReport.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Set-CustomizationSpec.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Set-CustomizationSpec.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Set-NTPServer.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Set-NTPServer.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Set-vSphereReplicationLimit.ps1: -------------------------------------------------------------------------------- 1 | cls 2 | <# 3 | vSphere Replication Limits 4 | Scriptable way to toggle your VR bandwidth cap for day, night, weekend, or whatever 5 | Args usage = PSfile "vcenter name" "VDS name to configure" "Mbps limit value" 6 | #> 7 | 8 | # Variables 9 | $vcenter = $args[0] 10 | $dvsName = $args[1] 11 | $rpName = "vSphere Replication" 12 | # Set to -1 to go back to unlimited 13 | $newLimit = $args[2] 14 | 15 | # Connect to vCenter 16 | If (-not $global:DefaultVIServer) {Connect-VIServer -Server $vcenter} 17 | 18 | # Check args 19 | if (-not $args[2]) 20 | { 21 | throw "Incorrect format. Provide the vCenter name, VDS name, and limit in Mbps. Example: `"script.ps1 `"vCenter.FQDN`" `"VDS1`" 500`" would set VR bandwidth on VDS1 to 500 Mbps" 22 | exit 23 | } 24 | 25 | # Get the VDS details 26 | $dvs = Get-VDSwitch -Name $dvsName 27 | 28 | # Set the VR network pool to the value provided in args 29 | # The section below was written by Luc Dekens (@LucD22), all credit to him 30 | $rp = $dvs.ExtensionData.NetworkResourcePool | Where {$_.Name -match $rpName} 31 | if($rp){ 32 | $spec = New-Object VMware.Vim.DVSNetworkResourcePoolConfigSpec 33 | $spec.AllocationInfo = $rp.AllocationInfo 34 | $spec.AllocationInfo.Limit = [long]$newLimit 35 | $spec.ConfigVersion = $rp.ConfigVersion 36 | $spec.Key = $rp.Key 37 | $dvs.ExtensionData.UpdateNetworkResourcePool(@($spec)) 38 | } 39 | 40 | # Verify 41 | $rp = $dvs.ExtensionData.NetworkResourcePool | Where {$_.Name -match $rpName} 42 | Write-Host "A limit of" $rp.AllocationInfo.Limit "Mbps has been set on $dvs" 43 | -------------------------------------------------------------------------------- /VMware vSphere/Update-ResourcePool.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Update-ResourcePool.ps1 -------------------------------------------------------------------------------- /VMware vSphere/Update-VMwareTools.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/VMware vSphere/Update-VMwareTools.ps1 -------------------------------------------------------------------------------- /WahlNetwork/Load-Scripts.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/WahlNetwork/Load-Scripts.psm1 -------------------------------------------------------------------------------- /WahlNetwork/README.md: -------------------------------------------------------------------------------- 1 | This is the Wahl Network module folder. To use it, copy the folder along with any of my cmdlets to your PowerShell module path. This is typically: 2 | 3 | C:\Windows\System32\WindowsPowerShell\v1.0\Modules 4 | 5 | Then, import the module: 6 | 7 | Import-Module WahlNetwork 8 | 9 | You can now use any of the cmdlets that you copied over. For a full list, use this command: 10 | 11 | Get-Command -Module WahlNetwork 12 | 13 | Enjoy. 14 | -------------------------------------------------------------------------------- /WahlNetwork/WahlNetwork.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WahlNetwork/powershell-scripts/6cb492b93bcd4ee7e8c0ea9567740eecd91de281/WahlNetwork/WahlNetwork.psd1 --------------------------------------------------------------------------------