Hi
I installed Powercli on Centos & all works well.
pwsh
PowerShell 7.1.0
Copyright (c) Microsoft Corporation.
And get-vm etc works well
Now i added a Jenkin job, as below
Find-Module "VMware.PowerCLI" | Install-Module -Scope "AllUsers" -AllowClobber
Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore" -confirm:$false
Import-Module "VMware.PowerCLI"
connect-viserver -Server xxx.xxx.xxx.com -User xxx@xxx.xxx.com -Password "xxx#"
Get-VM | Get-Snapshot | Where {$_.Created -lt ((Get-Date).AddDays(-3))}| Select-Object VM, Name, Created, SizeGB,@{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}}
#
but the job fails & says it can not find connect-viserver or even get-vm
i saw notes here which talk about the path etc.. any suggestions Please ?
thanks
Did you check what is defined in $env:PSModulePath (from within a Jenkins triggered PS script)?
Most of the issues with Jenkins and PS seem to be originating from incorrect content in $env:PSModulePath.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
for test i change the script to simple write-output & it worked well
Running as SYSTEM Building in workspace /var/lib/jenkins/workspace/Vmware-SnapShots-Reminder [Vmware-SnapShots-Reminder] $ pwsh -NonInteractive -NoProfile -File /tmp/jenkins16290d409644183.ps1 test Finished: SUCCESS
#######################################
in google all i see folks running powershell/powercli on Jenkins running on windows .. not many i saw doing what i am doing ..
i am sure all i am missing something small thing on seting env of path ..
Did you check what is defined in $env:PSModulePath (from within a Jenkins triggered PS script)?
Most of the issues with Jenkins and PS seem to be originating from incorrect content in $env:PSModulePath.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am going to try ...
I worked around this by explicitly adding the path as an environment variable to Jenkins, but I don't know why I had to do that. Anyway it works now
.. My jenkins user's path i will try add powercli .. i have to find where it installed new modules ..
Not sure where i can setup in Linux ... $env:PSModulePath
doing some google on that
find / -name connect-viserver*
giving nothing ... trying to find the path
could be
/opt/microsoft/powershell/7/Modules
i see lot of stuff here ..
/root/.local/share/powershell/Modules/
seems more promising ..
it seems its already setup
PS /root> $env:PSModulePath
/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules
PS /root>
i think i found the issue .. i will rsync the modules to below
PS /var/lib/jenkins> $env:PSModulePath
/var/lib/jenkins/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules
PS /var/lib/jenkins>
The ones i have are with root user ..
@LucD thanks as always it helped.
Any suggestions what i can do for below
WARNING: The command 'Send-MailMessage' is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage at this time. See https://aka.ms/SendMailMessage for more information
NTLM authentication is not possible with default credentials on this platform.
It is still a warning.
And as the message states there is currently no replacement.
Only in a hyper-secure environment, I would consider using an alternative, but then again would I run SMTP in such an environment 🤔
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD thanks for reply, not sure if you saw the other message , it seems Jenkins issue & not Powercli
Basically i did not got the email is the issue
NTLM authentication is not possible with default credentials on this platform.
Ran the script on powershell on windows & it worked so seems Jenkins's powershell plugin issue ...
I wished we had such forum as Powershell for Jenkins ... those folks are no aware near our powercli community ..
I wonder @LucD you seems do manage this community to a great extent single handedly ... ( I/we are fortunately & grateful for that ) is that your passion or this is part of your day job responsibility too 🙂
I am sure this takes some time of yours !
VMware used to be part of my day job, and PowerShell/PowerCLI is a passion 😁
Since the beginning of this year, I'm retired.
As long as I can follow the technology developments, I'll continue participating in this forum.
And yes, I would hope more and more platforms/applications realise that PowerShell is a popular automation tool.
And would support it.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference