Closed meoso closed 7 years ago
I gave up on embedded script parameters when calling PowerShell from Scheduled Tasks years ago. It was too frustrating figuring out how to nest quotation marks and such. Initially, I used Scheduled Tasks to call a batch script with the string I wanted to use in Scheduled Tasks. I've since moved on to launching powershell.exe from Scheduled Tasks but using a PowerShell script to init the environment I need. (powershell.exe -noprofile -file "path\to\init_script.ps1")
After my upgrade to PowerCLI 6.5 R1, I stopped calling the Initialize-PowerCLIEnvironment.ps1 script and switched to "Get-Module -ListAvailable -Name VMware.* | Import-Module -Global".
Sorry this doesn't give you a simple command to try instead but hopefully this gives you some ideas for alternate methods to kick off a scheduled vCheck.
vCheck will load any required modules anyway, so you can just call vCheck.ps1
e.g. The commandline for one of my vCheck reports:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "& 'C:\Scripts\Powershell\vCheck\vcheck.ps1' -Job vcenter.xml -Outputpath C:\Scripts\Powershell\vCheck\Archives\vcenter"
As for your path issues, maybe check the "Start in" path is correct, there's possibly some relative paths used somewhere
Hate to admit it, but i purged 6.5, installed 5.1, then upgraded to 6.5. The tips above look proper according to other resources, but I postponed creating a custom powershell profile which would probably have worked. Also did not want to edit vCheck code.
I wound up adding this into my Microsoft.PowerShell_profile.ps1:
$PowerCLI_Root = "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\" $PowerCLI_Base = $PowerCLI_Root + "Modules\" $PowerCLI_Home = "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts" $PowerCLI_Init = $PowerCLI_Home+"/Initialize-PowerCLIEnvironment.ps1" $env:PsModulePath += ";$PowerCLI_Base"
Robert Boyd Sr. Systems Engineer PeopleFluent p. 919-645-2972 | c. 919-306-4681 e. Robert.Boyd@PeopleFluent.commailto:robert.boyd@peoplefluent.com
[http://mktg.peoplefluent.com/rs/peopleclick/images/140410_PF4colorLOGOx150.png]http://www.peoplefluent.com/ Click herehttp://www.peoplefluent.com/ to experience the power of the new PeopleFluent Mirror Suite ™ Visit: www.peoplefluent.comhttp://www.peoplefluent.com/ | Read: PeopleFluent Bloghttp://peoplefluent.com/resources/peoplefluent-blog | Follow: @PeopleFluenthttp://twitter.com/peoplefluent
From: meoso [mailto:notifications@github.com] Sent: Wednesday, March 22, 2017 8:54 AM To: alanrenouf/vCheck-vSphere vCheck-vSphere@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [alanrenouf/vCheck-vSphere] commandline with fresh PowerCLI 6.5 fails. (#547)
Hate to admit it, but i purged 6.5, installed 5.1, then upgraded to 6.5. The tips above look proper according to other resources, but I postponed creating a custom powershell profile which would probably have worked. Also did not want to edit vCheck code.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/alanrenouf/vCheck-vSphere/issues/547#issuecomment-288389124, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGBUEx0Ly9MPwP5kwTlSyHrtJwQbq3vjks5roRnPgaJpZM4MgxKW.
Personally, I prefer a custom function that will load PowerCLI using native PowerShell constructs (Add-PSSnapin
/ Import-Module
). I've had this function (below) in my PS Profile for years and it's been resilient through all the PowerCLI version changes:
https://gist.github.com/vScripter/b27a62cc5710a154db87fa2da3870fca
function Start-PowerCLI {
<#
.NOTES
Loads PowerCLI, depending on what version you have installed. Set the default -Version parameter, depending in your environment.
#>
[cmdletbinding()]
param (
[parameter(Mandatory = $false, Position = 0)]
[ValidateSet('5', '6')]
[System.Int32]$Version = 6
)
BEGIN {
} # end BEGIN block
PROCESS {
switch ($Version) {
5 {
$powerCliSnapins = $null
$powerCliSnapins = (Get-PSSnapin -Registered | Where-Object { $_.Name -like '*vmware*' }).Name
foreach ($visnapin in $powerCLI) {
try {
Write-Verbose -Message "Adding '$visnapin' PSSnapin"
Add-PSSnapin -Name $visnapin
} catch {
Write-Warning -Message "Could not add VMware PSSnapin '$visnapin'"
} # end try/catch
} # end foreach $visnapin
} # end 5
6 {
$powerCliSnapins = $null
$powerCliSnapins = (Get-PSSnapin -Registered | Where-Object { $_.Name -like '*vmware*' }).Name
foreach ($visnapin in $powerCliSnapins) {
try {
Write-Verbose "Adding '$visnapin' PSSnapin"
Add-PSSnapin -Name $visnapin
} catch {
Write-Warning -Message "Could not add VMware PSSnapin '$visnapin'"
} # end try/catch
} # end foreach $visnapin
$powerCliModules = $null
$powerCliModules = (Get-Module -List | Where-Object { $_.Name -like '*vmware*' }).Name
foreach ($vimodule in $powerCliModules) {
try {
Write-Verbose "Importing '$vimodule' PS Module"
Import-Module -Name $vimodule
} catch {
Write-Warning -Message "Could not import PS Module '$vimodule'"
} # end try/catch
} # end foreach $vimodule
} # end 6
} # end switch
} # end PROCESS block
END {
} # end END block
} # end function Start-PowerCLI
I can't launch from schedule anymore with a fresh install of Win10 + PowerCLI 6.5 as vim.psc1 is not included in 6.5. I tried the workaround from https://communities.vmware.com/message/2632242#2632242 but it insists on changing directory to c:\ instead of the staying in the check-vsphere-master folder.
Has anyone gotten this to work without installing the older PowerCLI 5.1?
My failing commandline:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\" $true; "C:\vCheck-vSphere-master\vCheck.ps1 -Job C:\vCheck-vSphere-master\Mini.xml"
called from
C:\vCheck-vSphere-master
, but when run the PowerCLI environment is suddenly inC:\
and vCheck is asking for new confgiurations.