VMware Cloud Community
devs159
Contributor
Contributor
Jump to solution

vCheck and storing credentials for scheduled task

I'm trying to setup vCheck as a scheduled task but it keeps prompting for credentials when running as a batch file.

I've added the credential using the following command.

New-VICredentialStoreItem -Host myvc -User administrator@vsphere.local -Password password - File c:\scripts\vcpwd.xml

In the connection plugin for vcenter, I've added the following lines to pull the credentials but it's not working. Am I missing further steps here or what is the cause?

$Credfile = "C:\scripts\vcpwd.xml"

$Creds = Get-VICredentialStoreItem -Host $VIServer -File "C:\scripts\vcpwd.xml"

The .bat file string is as follows: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -File "C:\scripts\vCheck-vSphere-master\vCheck.ps1

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

And you using that on the Connect-VIServer cmdlet?

$Creds = Get-VICredentialStoreItem -Host $VIServer -File "C:\scripts\vcpwd.xml"

$VIConnection = Connect-VIServer -Server $VIServer -User $Creds.User -Password $Creds.Password-Port $Port


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

And you using that on the Connect-VIServer cmdlet?

$Creds = Get-VICredentialStoreItem -Host $VIServer -File "C:\scripts\vcpwd.xml"

$VIConnection = Connect-VIServer -Server $VIServer -User $Creds.User -Password $Creds.Password-Port $Port


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
devs159
Contributor
Contributor
Jump to solution

Thanks LucD​!!. I've updated to your string in the connection plugins and it's now working successfully.

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Hi LucD,

Need your help. I did try to add the following line to connection 00 Connection Plugin for vCenter but it throws an error. Can you please let me know where i need to add the following line in connection 00 Connection Plugin.

$Creds = Get-VICredentialStoreItem -Host $VIServer -File "C:\scripts\vcpwd.xml"

$VIConnection = Connect-VIServer -Server $VIServer -User $Creds.User -Password $Creds.Password-Port $Port

Error

[04:43:27] ..start calculating Connection settings for vCenter by Alan Renouf v1.20 [1 of 22]

Get-VICredentialStoreItem : The term 'Get-VICredentialStoreItem' is not recognized as the name of a cmdlet, function,

script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is

correct and try again.

At D:\Scripts\vCheck-sin1vm\Plugins\00 Initialize\00 Connection Plugin for vCenter.ps1:1 char:10

+ $Creds = Get-VICredentialStoreItem -Host $VIServer -File "D:\Scripts\ ...

+          ~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Get-VICredentialStoreItem:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

Connect-VIServer : The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or

operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try

again.

At D:\Scripts\vCheck-sin1vm\Plugins\00 Initialize\00 Connection Plugin for vCenter.ps1:3 char:17

+ $VIConnection = Connect-VIServer -Server $VIServer -User $Creds.User  ...

+                 ~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

Thanks

V

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like PowerShell can not find the PowerCLI modules.

Which PowerShell and PowerCLI version and in which folder?

$PSVersionTable

$env:PSModulePath.Split(';')

Get-Module -Name VMware.PowerCLI -ListAvailable


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Thank you LucD.

Please find the output.

pastedImage_0.png

Thanks

V

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like you might be using an older PowerCLI version.
Most probably an MSI based installation.

Can you upgrade?

See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates for instructions.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

cD,

Let me try from workstation and i have updated version power cli installed. Let me know if still require updated version.

pastedImage_0.png

After adding the line. It still prompt for credential.

Thanks

V

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In Plugin 00 you should have set the vCenter.

$Title = "Connection settings for vCenter"

$Author = "Alan Renouf"

$PluginVersion = 1.20

$Header = "Connection Settings"

$Comments = "Connection Plugin for connecting to vSphere"

$Display = "None"

$PluginCategory = "vSphere"


# Start of Settings

# Please Specify the address (and optional port) of the vCenter server to connect to [servername(:port)]

$Server = "vcsa.local.lab"

# End of Settings


And there should be a VICredentialStoreItem entry on the station where you are running this.

Get-VICredentialStoreItem -Host 'vcsa.local.lab'


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

yes, it definitely helped me, once suggested where to add the line, but i still noticed that it was throwing a port error message and prompting me for credential, then i just tweaked the line of your script

using the blog - Login to vCenter via PowerCLI without entering Credentials | VMMaster

$Credentials = Get-VICredentialStoreItem -Host vcsa.vmmaster.local -File D:\pwd.xml

Connect-VIServer vcsa.vmmaster.local -User $Credentials.User -Password $Credentials.Password

and it is working now. Not sure why it is not working with the other command.  Thanks for your help once again.

Thanks

V

Reply
0 Kudos