Highlighted
Expert
Expert

Powercli on CentOS7 & Jenkins

Jump to solution

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

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

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

View solution in original post

14 Replies
Highlighted
Expert
Expert

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

#######################################






0 Kudos
Highlighted
Expert
Expert

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 ..

0 Kudos
Highlighted
User Moderator
User Moderator

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

View solution in original post

Highlighted
Expert
Expert

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

0 Kudos
Highlighted
Expert
Expert

find / -name connect-viserver*

 

giving nothing ... trying to find the path

0 Kudos
Highlighted
Expert
Expert

could be

 

/opt/microsoft/powershell/7/Modules

 

i see lot of stuff here ..

0 Kudos
Highlighted
Expert
Expert

/root/.local/share/powershell/Modules/

 

seems more promising ..

0 Kudos
Highlighted
Expert
Expert

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>

 

 

0 Kudos
Highlighted
Expert
Expert

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 ..

 

 

0 Kudos
Highlighted
Expert
Expert

@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.

 

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Expert
Expert

@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.
0 Kudos
Highlighted
Expert
Expert

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 !

 

 

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos