PowerCLI

 View Only
  • 1.  vCheck and storing credentials for scheduled task

    Posted Mar 22, 2018 03:55 PM

    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



  • 2.  RE: vCheck and storing credentials for scheduled task
    Best Answer

    Posted Mar 22, 2018 05:17 PM

    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



  • 3.  RE: vCheck and storing credentials for scheduled task

    Posted Mar 23, 2018 08:42 AM

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



  • 4.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 08:50 AM

    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



  • 5.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 09:13 AM

    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



  • 6.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 09:17 AM

    Thank you LucD.

    Please find the output.

    Thanks

    V



  • 7.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 09:26 AM

    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.



  • 8.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 09:35 AM

    cD,

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

    After adding the line. It still prompt for credential.

    Thanks

    V



  • 9.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 09:48 AM

    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'


  • 10.  RE: vCheck and storing credentials for scheduled task

    Posted Aug 14, 2020 10:37 AM

    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