├── Datastore Migrations ├── Datastoremigrations.ps1 └── README.md ├── Datastore-Report-HTML ├── Data │ └── vcenter.xml └── Datastore-OutHTML.ps1 ├── LICENSE ├── Open-VMConsole ├── Open-VMConsole.psm1 └── README.md ├── README.md ├── Snapshots-Report-Email ├── Data │ ├── snapshot-exemptions.csv │ └── vcenter.xml ├── README.md └── snapshot-report.ps1 └── VC-Menu ├── VC-Menu.psm1 ├── VC-menu-Example.PNG └── readme.md /Datastore Migrations/Datastoremigrations.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Name:Datastore vMotioning.ps1 3 | Version: 1 4 | Author: Tom Unsworth (mail@tomunsworth.net) 5 | Comment: 6 | This script was made to vmotion VMs from a source datastore to a destination,it monitors the tasks and will email a report when all the tasks are done 7 | 8 | Requriments: 9 | PowerCLI 10 | 11 | #> 12 | 13 | <#------------------------------- 14 | Paramaters 15 | --------------------------------#> 16 | Param( 17 | [Parameter(Mandatory=$false,Position=1,helpmessage="vcenter server")] 18 | [string]$VC_Server, 19 | [Parameter(Mandatory=$false,Position=2,helpmessage="Location of CSV File with Souce and Destination Datastores")] 20 | [string]$CSV, 21 | [Parameter(Mandatory=$true,Position=3,helpmessage="SMTP Server to use")] 22 | [string]$SMTPServer, 23 | [Parameter(Mandatory=$true,Position=4,helpmessage="Send From Email Address")] 24 | [string]$SMTPFrom, 25 | [Parameter(Mandatory=$true,Position=5,helpmessage="Send To Email Address(s)")] 26 | [string]$SMTPTo 27 | ) 28 | 29 | #Add PowerCIL Snapin 30 | if ( (Get-PSSnapin -Name vmware.vimautomation.core -ErrorAction SilentlyContinue) -eq $null ) { 31 | Add-PsSnapin vmware.vimautomation.core 32 | } 33 | #starts off by disconncting just in case 34 | if ($global:DefaultVIServers.Count -gt 0) { 35 | Write-Host "... Disconnecting existing VIServer connections ...." 36 | Disconnect-VIServer -Server * -Force -confirm: $false 37 | } 38 | 39 | 40 | <#------------------------------- 41 | Any arrays or custom settings here please 42 | --------------------------------#> 43 | 44 | $locations = Import-Csv "$($CSV)" 45 | 46 | $script:errorreport = @() 47 | $script:successfulreport = @() 48 | $script:report_file = "report.html" 49 | 50 | <#------------------------------- 51 | Function Rerpot Header 52 | -------------------------------#> 53 | Function Report-Header { 54 | 55 | Remove-Item $report_file -ErrorAction SilentlyContinue 56 | 57 | $Report_infomration = " 58 | 63 | 64 |

Vmotions List

65 | " 66 | 67 | $Report = $Report_infomration 68 | $Report | Out-File -Append $report_file 69 | 70 | } 71 | 72 | 73 | <#------------------------------- 74 | Function Report Body 75 | -------------------------------#> 76 | Function Report-Body { 77 | #Get all the Successful vmotions 78 | $report_infomration ="

Successful vmotions

" 79 | $Report = $Report_infomration 80 | $Report | Out-File -Append $report_file 81 | 82 | $Report = $script:successfulreport | select @{Expression={(get-vm -id $($_.ObjectId)).name};label="VM"},StartTime,FinishTime | ConvertTo-Html 83 | $Report | Out-File -Append $report_file 84 | 85 | #Get all the Failed vmotions 86 | 87 | $report_infomration ="

Failed vmotions

" 88 | $Report = $Report_infomration 89 | $Report | Out-File -Append $report_file 90 | 91 | $Report = $script:errorreport | select @{Expression={(get-vm -id $($_.ObjectId)).name};label="VM"},StartTime,FinishTime | ConvertTo-Html 92 | $Report | Out-File -Append $report_file 93 | } 94 | 95 | 96 | <#------------------------------- 97 | Function Email Report 98 | -------------------------------#> 99 | Function Report_Email { 100 | $messageSubject = "Datastore vMotion Report" 101 | $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto 102 | $message.Subject = $messageSubject 103 | $message.IsBodyHTML = $true 104 | $message.Body = Get-Content $script:report_file 105 | 106 | $smtp = New-Object Net.Mail.SmtpClient($smtpServer) 107 | $smtp.Send($message) 108 | } 109 | 110 | <#------------------------------- 111 | Function to connect to VCs 112 | -------------------------------#> 113 | Function VC-Connect { 114 | if ($global:DefaultVIServers.Count -gt 0) {Disconnect-VIServer -Server * -Force -confirm: $false} 115 | Try {Connect-VIServer $VC_Server -User "user" -Password "passowrd" -WarningAction SilentlyContinue -ErrorAction stop | Out-Null 116 | Write-output "Successfully conncted to vCenter"} 117 | Catch {Write-Error $(throw "Failed to connect")} 118 | } 119 | 120 | <#------------------------------ 121 | In this scetion Put the code you want to excute 122 | -------------------------------#> 123 | Function Vmotions { 124 | $tasklist = @() 125 | 126 | foreach ($location in $locations){ 127 | $vmlist = get-datastore $location.source | get-vm 128 | foreach ($vm in $vmlist){ 129 | $vmid = (get-vm $vm).Id 130 | move-vm $vm -Datastore $location.destination -RunAsync 131 | $task = get-task | where {$_.ObjectId -eq $vmid} 132 | $tasklist += $task 133 | } 134 | } 135 | 136 | $Collection = {$tasklist}.Invoke() 137 | 138 | $erroredvms = @() 139 | $successfulvms = @() 140 | 141 | do { 142 | foreach ($watched in $tasklist){ 143 | if($Collection -notcontains $watched){continue} 144 | try {$currentstate = get-task -id $watched.id -ErrorAction SilentlyContinue} 145 | catch {$Collection.Remove($watched);continue} 146 | 147 | if (($currentstate).State -eq "Success"){ 148 | if ($successfulvms -contains $watched) {continue} 149 | else{$successfulvms += $currentstate;$Collection.Remove($watched)} 150 | } 151 | 152 | if (($currentstate).State -eq "Error"){ 153 | if($erroredvms -contains $watched){continue} 154 | else{$erroredvms += $currentstate;$Collection.Remove($watched)} 155 | } 156 | 157 | #Write-host "Collection Count $($Collection.count)" 158 | sleep 5 159 | } 160 | }until ($Collection.count -eq "0") 161 | 162 | write-host "end of Collection finished" 163 | 164 | $script:errorreport += $erroredvms 165 | $script:successfulreport += $successfulvms 166 | 167 | } 168 | <#----------------------------- 169 | End of your section 170 | ------------------------------#> 171 | 172 | Report-Header 173 | #Connect to VC 174 | VC-Connect 175 | #Code to Process 176 | Vmotions 177 | Report-Body 178 | Report_Email 179 | #End of VC Look -------------------------------------------------------------------------------- /Datastore Migrations/README.md: -------------------------------------------------------------------------------- 1 | #Datastore Migrations 2 | ##A Simple script that uses a CSV to migrate VMs from one datastore to another, it will email results. 3 | 4 | **Requriments:** 5 | - **Powershell 3.0** 6 | - Powershell 3.0 Required - https://www.microsoft.com/en-gb/download/details.aspx?id=34595 7 | - **PowerCLI 6.0** 8 | - https://blogs.vmware.com/PowerCLI/2015/03/powercli-6-0-r1-now-generally-available.html 9 | -------------------------------------------------------------------------------- /Datastore-Report-HTML/Data/vcenter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Datastore-Report-HTML/Datastore-OutHTML.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Name:Datastore-OutHTML.ps1 3 | Version: 1 4 | Download Link: 5 | Author: Tom Unsworth (mail@tomunsworth.net) 6 | Comment: 7 | This script will output your current datastore usage levels and show any overprovising into a HTMl file and a CSV 8 | #> 9 | if ( (Get-PSSnapin -Name vmware.vimautomation.core -ErrorAction SilentlyContinue) -eq $null ) { 10 | Add-PsSnapin vmware.vimautomation.core 11 | } 12 | #starts off by disconncting just in case 13 | if ($global:DefaultVIServers.Count -gt 0) { 14 | Write-Host "... Disconnecting existing VIServer connections ...." 15 | Disconnect-VIServer -Server * -Force -confirm: $false 16 | } 17 | #Pulls the Vcenter list from an xml file 18 | $folder = get-location 19 | #Pulls the Vcenter list from an xml file 20 | [xml]$VC_list = Get-Content ($folder.path +"\Data\vcenter.xml") 21 | 22 | $script:output = @() 23 | <#------------------------------- 24 | Any arrays or custom settings here please 25 | --------------------------------#> 26 | $CSS = " 27 | 118 | 119 |
120 |
Key
121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 |
Used:  
Free:  
Over Provisioned:  
138 |
139 | " 140 | 141 | 142 | 143 | 144 | 145 | <#------------------------------- 146 | Function to connect to VCs 147 | -------------------------------#> 148 | Function VC-Connect { 149 | if ($global:DefaultVIServers.Count -gt 0) {Disconnect-VIServer -Server * -Force -confirm: $false} 150 | Try {Connect-VIServer $VC_Server.fqdn -user $VC_Server.user -password $VC_Server.pass -WarningAction SilentlyContinue -ErrorAction stop | Out-Null 151 | Write-output "Successfully conncted to vCenter"} 152 | Catch {Write-Error $(throw "Failed to connect")} 153 | } 154 | 155 | <#------------------------------- 156 | Function to disconnect VCs 157 | -------------------------------#> 158 | Function VC-Disconnect { 159 | if ($global:DefaultVIServers.Count -gt 0) { 160 | try {Disconnect-VIServer -Server * -Force -confirm: $false 161 | Write-output "Disconected from VC"} 162 | catch { write-error $(throw"Problem Disconnecting from VC")} 163 | } 164 | } 165 | <#------------------------------ 166 | In this scetion Put the code you want to excute 167 | -------------------------------#> 168 | Function VC-Process { 169 | #Gather Datastore Information 170 | foreach ($datastore in Get-Datastore) { 171 | #make numbers easier 172 | $capacity = [math]::round($datastore.ExtensionData.Summary.capacity/1GB,2) 173 | $uncommited = [math]::round(($datastore.ExtensionData.Summary.Uncommitted)/1GB,2) 174 | $free = [math]::round($datastore.ExtensionData.Summary.Freespace/1GB,2) 175 | $provisined = [math]::round(($datastore.CapacityGB – $datastore.FreespaceGB +($datastore.extensiondata.summary.uncommitted/1GB)),2) 176 | $provisinedper = [math]::round(($provisined / $Capacity)*100,2) 177 | $used = [math]::round(($datastore.ExtensionData.Summary.capacity - $datastore.ExtensionData.Summary.Freespace)/1GB,2) 178 | $freePer = [math]::round(($free / $Capacity)*100,2) 179 | $usedper = [math]::round(($used / $Capacity)*100,2) 180 | if ($provisined -ge $capacity){ 181 | $overprovisend = [math]::round($provisined - $Capacity,2) 182 | } 183 | Else { 184 | $overprovisend = "0" 185 | } 186 | if ($used -eq "0"){ 187 | $freeusedcode = "
" 188 | } 189 | if ($free -eq "0") { 190 | $freeusedcode = "
" 191 | } 192 | if ($used -ne "0") { 193 | $freeusedcode = "
194 |
195 | " 196 | } 197 | if ($overprovisend -eq "0") { 198 | $freeusedcode = "
199 |
200 | " 201 | } 202 | 203 | if ($provisined -ge $Capacity) { 204 | $capacitywidth = [math]::round(($Capacity / $provisined)*100,2) 205 | $Provisonedwidth = 100 - $capacitywidth 206 | $capprocode ="
207 | $($freeusedcode) 208 |
209 |
210 | " 211 | } 212 | Else { 213 | $capacitywidth = [math]::Round((100 - $freeper),2) 214 | $Provisonedwidth = $provisinedper 215 | $capprocode = " 216 |
217 | $($freeusedcode) 218 | " 219 | } 220 | if ($provisined -eq $Capacity) { 221 | $capacitywidth = 100 222 | $capprocode = " 223 |
224 | $($freeusedcode) 225 |
226 | " 227 | } 228 | 229 | $info = "" | select VC,DSName,Provisioned,Used,Free,Code,overprovisioned,capacity,Uncommitted 230 | $info.VC = $VC_Server.fqdn 231 | $info.DSName = $datastore.name 232 | $info.Provisioned = $provisined 233 | $info.capacity = $capacity 234 | $info.overprovisioned = $overprovisend 235 | $info.Used = $used 236 | $info.free = $free 237 | $info.Uncommitted = $uncommited 238 | $info.code = 239 | "
240 |
$($VC_Server.name) - Datastore - $($datastore.name)
241 | 242 | 243 | 250 | 256 | 257 |
244 | Used:$($used)GB
245 | Free:$($free)GB
246 | Over Provisioned:$($overprovisend)GB
247 | Capacity:$($Capacity)GB
248 | Provisioned:$($provisined)GB 249 |
251 |
252 | $($capprocode) 253 |
254 | 255 |
258 |
259 | " 260 | 261 | $script:output += $info 262 | } 263 | 264 | 265 | <#----------------------------- 266 | End of your section 267 | ------------------------------#> 268 | } 269 | 270 | #Start of Vcenter login loop 271 | foreach ($VC_Server in $VC_list.vcenter_servers.server) { 272 | #Connect to VC 273 | VC-Connect 274 | #Code to Process 275 | VC-Process 276 | #Disconnet before end of loop 277 | VC-Disconnect 278 | } 279 | $CSS | Out-File $folder\datastore.html 280 | $script:output | select VC,DSName,Provisioned,Used,Free,overprovisioned,capacity,Uncommitted | Export-Csv -NoTypeInformation $folder\datastore.csv 281 | $graphout = @() 282 | $graphout = $script:output | Sort -Descending VC, overprovisioned 283 | $graphout.code | Out-File -Append $folder\datastore.html 284 | #End of VC Look -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /Open-VMConsole/Open-VMConsole.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | Name:Open-VMConsole.psm1 3 | Version: 1 4 | Download Link: https://github.com/Tunsworthy/PowerCLI/Open-VMConsole 5 | Author: Tom Unsworth (mail@tomunsworth.net) 6 | Comment: 7 | Since Open-VMConsoleWindow stopped working for me (today) i had to come with another way of connecting to VM consoles (rather then opening the fat client or using a differnt browser) 8 | Currertly piping to the commad works, next update i will include adding paramters. 9 | Requriments: 10 | PowerCLI 11 | VMware RC - https://my.vmware.com/web/vmware/details?downloadGroup=VMRC70&productId=353 12 | Usage: 13 | Get-VM | Open-VMConsole 14 | Install: 15 | **To Load:** 16 | - Place VC-Menu Folder in -> C:\Users\\Documents\WindowsPowerShell\Modules\ 17 | - Open Powershell and run - Get-Command -Module VC-Menu (this is just an output to make sure you have put it in the correct location) 18 | - Run - Import-module VC-Menu 19 | - Run - VC-Menu-CredStore (this will add your username and password to the VC Credential store). 20 | ########### 21 | URL-Only Option 22 | Author: https://github.com/jpsider (feel free to reach out if you have questions) 23 | Comment: 24 | Absolutely open to input and improvements! 25 | This script will produce a shareable URL to a VM's console. 26 | I've only tested this with vCenter 5.5 and 6.0 27 | This page said I could use &sessionTicket=cst-VCT (http://vmnick0.me/?p=75) but I never got it to work 28 | So you might need to update the thumbprint to your vcenter. 29 | 30 | Usage: 31 | Get-ConsoleURL UrlOnly $vm 32 | 33 | Assumptions: 34 | 1. You are already connected to Vcenter! 35 | 2. $vCenter, $VCenterUN, $VCenterPW are defined 36 | ########### 37 | 38 | #> 39 | $option=$args[0] 40 | Function Open-VMConsole($option, $vm) { 41 | 42 | <#------------------------ 43 | Generate all the settings to pass through to the launching command 44 | --------------------------#> 45 | Function OVC-Settings ($vm) { 46 | $Session = Get-View -Id Sessionmanager 47 | $script:vcenter = $DefaultVIServer.serviceuri.Host 48 | $script:vmid = ($vm).ExtensionData.moref.value 49 | $Script:ticket = $Session.AcquireCloneTicket() 50 | } 51 | <#------------------------ 52 | Command to Launch VMRC 53 | --------------------------#> 54 | Function OVC-LaunchConsole { 55 | try {Start-Process -FilePath "C:\Program Files (x86)\VMware\VMware Remote Console\vmrc.exe" -ArgumentList "vmrc://clone:$($ticket)@$($vcenter)/?moid=$($vmid)"} 56 | catch {write-host $ErrorMessage} 57 | } 58 | 59 | <#------------------------ 60 | This section exists for when i do the next part of allowing you to enter params 61 | --------------------------#> 62 | if ($input){ 63 | OVC-Settings $input 64 | OVC-LaunchConsole 65 | } 66 | 67 | if ($option -eq "UrlOnly"){ 68 | #Determine vCenter version 69 | $vCenterVersion = $global:DefaultVIServer.ExtensionData.Content.About.Version 70 | if ($vCenterVersion -Like "6.*"){ 71 | $ConsolePort = 9443 72 | $myVM = Get-VM $vm 73 | $VMMoRef = $myVM.ExtensionData.MoRef.Value 74 | 75 | #Get Vcenter from advanced settings 76 | $UUID = ((Connect-VIServer $vCenter -user $vCenterUN -Password $vCenterPW -ErrorAction SilentlyContinue).InstanceUUID) 77 | $SettingsMgr = Get-View $global:DefaultVIServer.ExtensionData.Client.ServiceContent.Setting 78 | $Settings = $SettingsMgr.Setting.GetEnumerator() 79 | $AdvancedSettingsFQDN = ($Settings | Where {$_.Key -eq "VirtualCenter.FQDN" }).Value 80 | 81 | #Get vCenter ticket 82 | $SessionMgr = Get-View $global:DefaultVIServer.ExtensionData.Client.ServiceContent.SessionManager 83 | $Session = $SessionMgr.AcquireCloneTicket() 84 | 85 | #Create URL and place it in the Database 86 | $ConsoleLink = "https://$($Vcenter):$($ConsolePort)/vsphere-client/webconsole.html?vmId=$($VMMoRef)&vm=$($myVM.Name)&serverGuid=${UUID}&host=$($AdvancedSettingsFQDN)&sessionTicket=$($Session)&thumbprint=5A:AB:D4:75:29:E8:D5:94:09:8F:D2:91:CF:DC:AB:C0:69:03:37:42" 87 | return $ConsoleLink 88 | } 89 | Elseif ($vCenterVersion -Like "5.*") { 90 | #Create URL and place it in the Database 91 | $myVM = Get-VM $vm 92 | $UUID = ((Connect-VIServer $Vcenter -user $VCenterUN -Password $VCenterPW -ErrorAction SilentlyContinue).InstanceUUID).ToUpper() 93 | $MoRef = $myVM.ExtensionData.MoRef.Value 94 | $ConsoleLink = "https://${Vcenter}:9443/vsphere-client/vmrc/vmrc.jsp?vm=urn:vmomi:VirtualMachine:${MoRef}:${UUID}" 95 | return $ConsoleLink 96 | } 97 | Else { 98 | write-host "Unable to determine Hypervisor Version." 99 | } 100 | } 101 | 102 | <#------------------------ 103 | End of Main Function 104 | --------------------------#> 105 | } 106 | -------------------------------------------------------------------------------- /Open-VMConsole/README.md: -------------------------------------------------------------------------------- 1 | #Open-VMConsole 2 | ##Since Open-VMConsoleWindow stopped working for me (today) i had to come with another way of connecting to VM consoles (rather then opening the fat client or using a differnt browser) 3 | Currertly piping to the commad works, next update i will include adding paramters. 4 | 5 | **Requriments:** 6 | - **Powershell 3.0** 7 | - Powershell 3.0 Required - https://www.microsoft.com/en-gb/download/details.aspx?id=34595 8 | - **PowerCLI 6.0** 9 | - https://blogs.vmware.com/PowerCLI/2015/03/powercli-6-0-r1-now-generally-available.html 10 | - **VMware RC** 11 | - https://my.vmware.com/web/vmware/details?downloadGroup=VMRC70&productId=353 12 | 13 | **To Load:** 14 | - Place Open-VMConsole Folder in -> C:\Users\\Documents\WindowsPowerShell\Modules\ 15 | - Open Powershell and run - Get-Command -Module Open-VMConsole 16 | - Run - Import-module Open-VMConsole 17 | 18 | **Usage** 19 | - Get-VM | Open-VMConsole 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerCLI 2 | A Collection of things I've written for Power CLI 3 | -------------------------------------------------------------------------------- /Snapshots-Report-Email/Data/snapshot-exemptions.csv: -------------------------------------------------------------------------------- 1 | vmname,snapname,createdby,vivantioid -------------------------------------------------------------------------------- /Snapshots-Report-Email/Data/vcenter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Snapshots-Report-Email/README.md: -------------------------------------------------------------------------------- 1 | # PowerCLI-VMware-Snapshots-Report 2 | Another Snapshot report with exemptions and multi-vCenter support
3 | Usage:
4 | snapshot-report.ps1 -snapreportage -snapreportsize -SMTPServer -SMTPFrom -SMTPTo -companyname 5 | -------------------------------------------------------------------------------- /Snapshots-Report-Email/snapshot-report.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Name:snapshot-report.ps1 3 | Version: 2 4 | Download Link: https://github.com/Tunsworthy/PowerCLI-VMware-Snapshots-Report/ 5 | Author: Tom Unsworth (mail@tomunsworth.net) 6 | Comment: 7 | This script produces a weekly report of snapshots from a list of vcenter servers, it can also handel exclutions 8 | Make sure the user that is running this script has access to create files in the Datafolder 9 | Requriments: 10 | PowerCLI 11 | 12 | V2 Updates: 13 | ---Major--- 14 | *Added in Exemptions ability 15 | -Any snapshots with "Exempt" in the discription won't be shown 16 | -Any snapshot in the csv from the data folder will not be shown 17 | *Prameters for SMTP settings 18 | *Found a shorter (and stronger) way of getting the created user - http://www.vstrong.info/2013/08/20/who-created-these-vm-snapshots/ (Thanks Mark Strong) 19 | *Used Functions 20 | *Major Code Clean up 21 | *Also there was a bug where some snapshots were not showing...i don't know why but this is now fixed. 22 | *Prameters to be able to set your Minimum snapshot age and reporting size 23 | ---Minor--- 24 | *Created nice looking table - because its important i tell you - Although outlook sucks and dosen't render it... so you also get an attachment of the file. 25 | *Change the font from Times New Romans to Arial (As per Adams Request) 26 | *Dynamic Company Name 27 | *Commneted my code and added in this section 28 | #> 29 | <#------------------------------- 30 | Paramaters 31 | --------------------------------#> 32 | Param( 33 | [Parameter(Mandatory=$false,Position=0,helpmessage="Minimum Snapshot age to report (Default is 7 days old)")] 34 | [int]$SnapReportAge = 7, 35 | [Parameter(Mandatory=$false,Position=1,helpmessage="Size at which the snapshot will be reported no matter how old (Default is 15GB)")] 36 | [int]$SnapReportSize = 15, 37 | [Parameter(Mandatory=$true,Position=3,helpmessage="SMTP Server to use")] 38 | [string]$SMTPServer, 39 | [Parameter(Mandatory=$true,Position=4,helpmessage="Send From Email Address")] 40 | [string]$SMTPFrom, 41 | [Parameter(Mandatory=$true,Position=5,helpmessage="Send To Email Address(s)")] 42 | [string]$SMTPTo, 43 | [Parameter(Mandatory=$false,Position=6,helpmessage="Your Companies Name")] 44 | [string]$companyname = "Taco corp" 45 | 46 | ) 47 | 48 | 49 | #Add PowerCIL Snapin 50 | if ( (Get-PSSnapin -Name vmware.vimautomation.core -ErrorAction SilentlyContinue) -eq $null ) { 51 | Add-PsSnapin vmware.vimautomation.core 52 | } 53 | #starts off by disconncting just in case 54 | if ($global:DefaultVIServers.Count -gt 0) { 55 | Write-Host "... Disconnecting existing VIServer connections ...." 56 | Disconnect-VIServer -Server * -Force -confirm: $false 57 | } 58 | 59 | <#------------------------------- 60 | Any arrays or custom settings here please 61 | --------------------------------#> 62 | $folder = get-location 63 | #Pulls the Vcenter list from an xml file 64 | [xml]$VC_list = Get-Content ($folder.path +"\Data\vcenter.xml") 65 | $Snap_exmpt = Import-Csv ($folder.path +"\Data\snapshot-exemptions.csv") 66 | $script:resultsarray = @() 67 | $script:Report_file = ($folder.path +"\Data\snapshot-txt.html") 68 | <#------------------------------- 69 | Function Rerpot Header 70 | -------------------------------#> 71 | Function Report-Header { 72 | 73 | Remove-Item $script:report_file 74 | $date = Get-Date 75 | $script:Report_Header = " 76 | 90 |

$($companyname) - $($date.day)/$($date.Month)/$($date.Year)

91 |

This Report is Generated from $($env:COMPUTERNAME) using account $($env:USERDOMAIN)\$($env:USERNAME)
92 | Script Location: $($folder)\snapshots-report.ps1
93 | 94 | Please Log an Incident to the respective customer using the VMWare Snapshot Removal template for all snapshots in the list
95 |

Note: Snapshots will not be shown if they are: 96 |

  • Younger then $($SnapReportAge) Days & Smaller then $($SnapReportSize) GB
  • 97 |


    98 | If the snapshot has been created by $($companyname) employee please log an incident to them directly.
    99 | Exemptions can be added via the exemptions file located in $($folder)\data\snapshot-exemptions.csv

    100 | " 101 | 102 | 103 | } 104 | <#------------------------------- 105 | Function Report Body 106 | -------------------------------#> 107 | Function Report-Body { 108 | if ($script:resultsarray -ne $null){ 109 | $Report = $script:resultsarray | Select vCenter,VM,Name,Description,Size,Created,CreatedBy | ConvertTo-Html -head $script:Report_Header | Out-File -Append $script:report_file 110 | } 111 | else { 112 | $output = "

    No Snapshots to report

    " | Out-String 113 | $Report = $output | ConvertTo-Html -head $script:Report_Header | Out-File -Append $script:report_file 114 | } 115 | 116 | } 117 | <#------------------------------- 118 | Function Email Report 119 | -------------------------------#> 120 | Function Report_Email { 121 | $messageSubject = "$companyname Snapshot report - $($date).day/$($date).month/$($date).year" 122 | $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto 123 | $message.Subject = $messageSubject 124 | $message.IsBodyHTML = $true 125 | $message.Body = Get-Content $script:report_file 126 | $message.Attachments.Add($script:report_file) 127 | $smtp = New-Object Net.Mail.SmtpClient($smtpServer) 128 | $smtp.Send($message) 129 | } 130 | <#------------------------------- 131 | Function to connect to VCs 132 | -------------------------------#> 133 | Function VC-Connect { 134 | if ($global:DefaultVIServers.Count -gt 0) {Disconnect-VIServer -Server * -Force -confirm: $false} 135 | Try {Connect-VIServer $VC_Server.fqdn -user $VC_Server.user -password $VC_Server.pass -WarningAction SilentlyContinue -ErrorAction stop | Out-Null 136 | Write-host "Successfully conncted to vCenter"$VC_Server.name} 137 | Catch {Write-Error $(throw "Failed to connect")} 138 | } 139 | 140 | <#------------------------------- 141 | Function to disconnect VCs 142 | -------------------------------#> 143 | Function VC-Disconnect { 144 | if ($global:DefaultVIServers.Count -gt 0) { 145 | try {Disconnect-VIServer -Server * -Force -confirm: $false 146 | Write-output "Disconected from VC"} 147 | catch { write-error $(throw"Problem Disconnecting from VC")} 148 | } 149 | } 150 | 151 | <#------------------------------ 152 | Checking for Snapshots 153 | -------------------------------#> 154 | Function VC-Process { 155 | $snapshots = Get-VM | Get-Snapshot 156 | if ($snapshots -eq $null){return} 157 | foreach ($snapshot in $snapshots) { 158 | #Check to see if the snapshot meets the threshold critera 159 | if (($snapshot.created -ge (get-date).adddays(-$SnapReportAge)) -and ($snapshot.sizeGB -le $SnapReportSize)){continue} 160 | #Check Descriptions for Exemption tag 161 | if ($snapshot.description -like "Exempt*"){continue} 162 | #Check Exemptions file 163 | foreach ($exemption in $Snap_exmpt) { 164 | if (($snapshot.name -like $exemption.snapname) -and ($snapshot.vm -match $exemption.vmname)) {$exempt = $true 165 | break} 166 | else {$exempt = $false} 167 | } 168 | if ($exempt) {continue} 169 | $snapevent = Get-VIEvent -Entity $snapshot.VM -Types Info -Finish $snapshot.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'} 170 | if ($snapevent -eq $null){ 171 | $Snapshot | Add-Member –MemberType NoteProperty –Name 'CreatedBy' –Value "Unable to find user" 172 | } 173 | else { 174 | $Snapshot | Add-Member –MemberType NoteProperty –Name 'CreatedBy' –Value $snapevent.username 175 | } 176 | $Snapshot | Add-Member -MemberType NoteProperty -Name 'vCenter' -Value $VC_Server.name 177 | $script:resultsarray += $snapshot | Select vCenter,VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created,CreatedBy 178 | } 179 | } 180 | <#----------------------------- 181 | End of your section 182 | ------------------------------#> 183 | 184 | Report-Header 185 | #Start of Vcenter login loop 186 | foreach ($VC_Server in $VC_list.vcenter_servers.server) { 187 | #Connect to VC 188 | VC-Connect 189 | #Code to Process 190 | VC-Process 191 | #Disconnet before end of loop 192 | VC-Disconnect 193 | } 194 | Report-Body 195 | Report_Email 196 | #End of VC Look 197 | -------------------------------------------------------------------------------- /VC-Menu/VC-Menu.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | Name:VC-Menu.psm1 3 | Version: 1 4 | Download 5 | Author: Tom Unsworth (mail@tomunsworth.net) 6 | Comment: 7 | A Module built to make connecting to many VCenter Enviroments easier. 8 | This module will only allow you to be connected to one VC at a time. 9 | Requriments: 10 | Powershell 3.0 11 | Powershell 3.0 Required - https://www.microsoft.com/en-gb/download/details.aspx?id=34595 12 | Windows 7 Service Pack 1 13 | 64-bit versions: Windows6.1-KB2506143-x64.msu 14 | PowerCLI 6.0 15 | https://blogs.vmware.com/PowerCLI/2015/03/powercli-6-0-r1-now-generally-available.html 16 | 17 | To Load: 18 | Place VC-Menu Folder in -> C:\Users\\Documents\WindowsPowerShell\Modules\ 19 | Open Powershell and run - Get-Command -Module VC-Menu (this is just an output to make sure you have put it in the correct location) 20 | Run - Import-module VC-Menu 21 | Run - VC-Menu-CredStore (this will add your username and password to the VC Credential store). 22 | 23 | Usage - run VC-Menu - input number or Customer code when prompted. 24 | 25 | #> 26 | <#------------------------------- 27 | Arrays For menu options 28 | Enter your FQDN and Short Codes (make sure they are in the same order) 29 | --------------------------------#> 30 | $VC_FQDN = "FakeVC.Madeup.net","Its.a.VC","VC.Menu.example" 31 | $VC_scode = "Fake","Its","Menu" 32 | Function VC-Menu { 33 | if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { 34 | . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" 35 | } 36 | 37 | <#------------------------------- 38 | Any arrays or custom settings here please 39 | --------------------------------#> 40 | $script:loopnum = 0 41 | $script:VC_List = @() 42 | <#------------------------------- 43 | Function to connect to VCs 44 | -------------------------------#> 45 | Function Connect ($VC_server) { 46 | if ($global:DefaultVIServers.Count -gt 0) {Disconnect-VIServer -Server * -Force -confirm: $false} 47 | Try {Connect-VIServer $VC_Server -WarningAction SilentlyContinue -ErrorAction stop | Out-Null 48 | Write-output "Successfully conncted to vCenter $($global:DefaultVIServers.name)"} 49 | Catch {Write-Error "Failed to connect"} 50 | } 51 | <#------------------------------- 52 | Displaying the menu 53 | --------------------------------#> 54 | Function MenuDisplay { 55 | 56 | 57 | foreach ($VC in $VC_FQDN){ 58 | $info = New-Object System.Object 59 | $info | Add-Member -type NoteProperty -name ID -Value $loopnum 60 | $info | Add-Member -type NoteProperty -name ShortCode -Value $VC_scode[[int]$loopnum] 61 | $info | Add-Member -type NoteProperty -name VCFQDN -Value $VC 62 | $script:VC_List += $info 63 | $script:loopnum ++ 64 | } 65 | $script:VC_List | ft -AutoSize 66 | } 67 | 68 | Function Selection { 69 | Param( 70 | [Parameter(Mandatory=$true,Position=0,helpmessage="Selection - Enter the ID or Short Code of the VC you would like to connect")] 71 | $Selection 72 | ) 73 | 74 | if($Selection -in 0..$script:loopnum){ 75 | try { 76 | Connect $VC_List.VCFQDN[[int]$Selection] 77 | } 78 | catch { 79 | write-host $ErrorMessage 80 | } 81 | } 82 | if ($Selection -in $VC_List.ShortCode){ 83 | foreach ($VC in $VC_list){ 84 | if ($Selection -match $VC.ShortCode){ 85 | $connect = $VC.VCFQDN 86 | break 87 | } 88 | } 89 | try { 90 | Connect $connect 91 | } 92 | catch { 93 | write-host $ErrorMessage 94 | } 95 | } 96 | } 97 | 98 | 99 | MenuDisplay 100 | Selection 101 | } 102 | Function VC-Menu-CredStore { 103 | Param( 104 | [Parameter( 105 | Mandatory=$true, 106 | Position=2, 107 | HelpMessage="Username and Password for vCenter" 108 | )] 109 | [ValidateNotNullOrEmpty()] 110 | [System.Management.Automation.PSCredential]$Credential 111 | ) 112 | if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { 113 | . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" 114 | } 115 | if ( (Get-PSSnapin -Name vmware.vimautomation.core -ErrorAction SilentlyContinue) -eq $null ) { 116 | Add-PsSnapin vmware.vimautomation.core 117 | } 118 | 119 | foreach ($VC in $VC_FQDN) { 120 | New-VICredentialStoreItem -host $VC -User $Credential.GetNetworkCredential().username -Password $Credential.GetNetworkCredential().Password 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /VC-Menu/VC-menu-Example.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tunsworthy/PowerCLI/0827031e4e9eae8765c0ee880dc89f83a3a573a5/VC-Menu/VC-menu-Example.PNG -------------------------------------------------------------------------------- /VC-Menu/readme.md: -------------------------------------------------------------------------------- 1 | #VC-Menu 2 | ##I'm Very lazy, so i created a menu for connecting to my VC servers. 3 | See the example image 4 | **Note:**This module will only allow you to be connected to one VC at a time. 5 | 6 | **Requriments:** 7 | - **Powershell 3.0** 8 | - Powershell 3.0 Required - https://www.microsoft.com/en-gb/download/details.aspx?id=34595 9 | - **PowerCLI 6.0** 10 | - https://blogs.vmware.com/PowerCLI/2015/03/powercli-6-0-r1-now-generally-available.html 11 | 12 | **To Load:** 13 | - Place VC-Menu Folder in -> C:\Users\\Documents\WindowsPowerShell\Modules\ 14 | - Open Powershell and run - Get-Command -Module VC-Menu (this is just an output to make sure you have put it in the correct location) 15 | - Run - Import-module VC-Menu 16 | - Run - VC-Menu-CredStore (this will add your username and password to the VC Credential store). 17 | 18 | **Usage** 19 | - run VC-Menu - input number or Customer code when prompted. 20 | --------------------------------------------------------------------------------