Skip to content

Commit 86e0043

Browse files
authored
Merge pull request #11 from mothe-at/v1.5.2
V1.5.2
2 parents 4cf28f7 + 415da84 commit 86e0043

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# v1.5.1 (2016-09-29)
1+
# v1.5.2 (2016-11-30)
2+
* **[FIXED]** Fixed a problem with PowerCLI 6.5. Fixed [#8] (https://github.com/mothe-at/VMPerf-To-Graphite-PowerShell-Script/issues/8)
3+
* **[ADDED]** Ability to omit the "-User" and "-Password" switches to log in to the vCenter server using current credentials. Fixed [#9] (https://github.com/mothe-at/VMPerf-To-Graphite-PowerShell-Script/issues/9)
4+
5+
# v1.5.1 (2016-09-29)
26
* **[FIXED]** Changed Encoding of Script to UTF-8
37
* **[FIXED]** Fixed a bug that causes wrong number of IOPS and KBs with multiple vDisks
48
* **[FIXED]** Calculate the weighted average of the read and write latency of all disks instead of the simple average

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ To call the script to run infinitely, waiting 5 minutes between each iteration,
7171
7272
-User <String>
7373
Specifies the user name you want to use for authenticating with the vCenter server.
74-
74+
If this parameter is omitted, the currently logged on user will be used to authenticate with vCenter server.
7575
Required? false
7676
Position? 2
7777
Default value vcenter_user

VMPerf-To-Graphite.ps1

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Run the cmdlet just once, but do not send the metrics to Graphite, instead open
2828
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
2929
It is free-of-charge and it comes without any warranty, to the extent permitted by applicable law.
3030
Matthias Rettl, 2016
31-
Script Version 1.5.1 (2016-09-29)
31+
Script Version 1.5.2 (2016-11-30)
3232
.LINK
3333
https://github.com/mothe-at/VMPerf-To-Graphite-PowerShell-Script
3434
http://rettl.org/scripts/
@@ -39,9 +39,10 @@ param(
3939
# Specifies the IP address or the DNS name of the vCenter server to which you want to connect.
4040
[string]$Server = "your_default_vcenter_server",
4141
# Specifies the user name you want to use for authenticating with the vCenter server.
42-
[string]$User = "vcenter_user",
42+
# If this parameter is omitted, the currently logged on user will try to authenticate with the vCenter server.
43+
[string]$User = "",
4344
# Specifies the password you want to use for authenticating with the vCenter server.
44-
[string]$Password = "vcenter_password",
45+
[string]$Password = "",
4546
# Specifies the Internet protocol you want to use for the connection. It can be either http or https.
4647
[ValidateSet("http","https")][string]$Protocol = "https",
4748
# Specifies the VMWare Datacenters you want to receive data from. Default is to read all Clusters managed by VCenter server.
@@ -206,12 +207,20 @@ function connectviserver($stoponerror)
206207
if ($stoponerror) { $erroraction = "Stop" } else { $erroraction = "Continue" }
207208

208209
do {
209-
$msg = "Connecting to vCenter Server $server as $user"
210+
if ($user -ne "") {
211+
$msg = "Connecting to vCenter Server $server as $user"
212+
} else {
213+
$msg = "Connecting to vCenter Server $server as currently logged on user " + [Environment]::UserDomainName + "\" + [Environment]::UserName
214+
}
210215
Write-Verbose "$(Get-Date -format G) $msg"
211216
Write-To-Windows-EventLog "Information" 1002 $msg
212217

213-
[void] ( $vcc = Connect-VIServer -Server $server -User $user -Password $password -Protocol $protocol -ErrorAction $erroraction -ErrorVariable err -Verbose:$false )
214-
218+
if ($user -ne "") {
219+
[void] ( $vcc = Connect-VIServer -Server $server -User $user -Password $password -Protocol $protocol -ErrorAction $erroraction -ErrorVariable err -Verbose:$false )
220+
} else {
221+
[void] ( $vcc = Connect-VIServer -Server $server -Protocol $protocol -ErrorAction $erroraction -ErrorVariable err -Verbose:$false )
222+
}
223+
215224
if ($err) {
216225
$msg = "Connection to $server failed! Will retry in 10 seconds"
217226
Write-Warning "$(Get-Date -format G) $msg"
@@ -271,18 +280,17 @@ if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)
271280
$oldverbosepreference = $VerbosePreference
272281
$VerbosePreference = "SilentlyContinue"
273282

274-
# Read the Install-Path of PowerCLI from the Registry
275-
$ikey = 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\VMware.VimAutomation.Core'
276-
$idir = (Get-ItemProperty -Path $ikey -Name ApplicationBase -ErrorAction SilentlyContinue -ErrorVariable err).ApplicationBase
277-
278-
if ($err) {
283+
# Get the Install-Path of PowerCLI. If null then PowerCLI may not be installed.
284+
$idir = (Get-Module -ListAvailable -Name VMware.VimAutomation.Core).ModuleBase # Usually something like "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VimAutomation.Core"
285+
286+
if ($idir -eq $null) {
279287
$msg="Error initializing VMWare PowerCLI environment. Cannot find path to VMWare PowerCLI in Registry. Make sure VMWare PowerCLI is installed on this host!"
280288
Write-Error $msg
281289
Write-To-Windows-EventLog "Error" 3001 $msg
282290
Exit
283291
}
284292

285-
. "$idir\Scripts\Initialize-PowerCLIEnvironment.ps1"
293+
. "$idir\..\..\Scripts\Initialize-PowerCLIEnvironment.ps1"
286294

287295
# Reset the Verbose setting to its previously value
288296
$VerbosePreference = $oldverbosepreference

0 commit comments

Comments
 (0)