VMware Cloud Community
zhaodiwx
Contributor
Contributor

Credential for ps1 scripts

I have a question about Credential in my xxx.ps1 file:

First:I have already connected to my vcenter, and use the following command to create the Credential in the PS shell:

New-VICredentialStoreItem -File "D:\Temp\myvc_cred.xml"

for example:

# xxx.ps1 content:

Add-PSSnapin -Name *vmware*

$vcenterip = '192.168.0.99'

$myCred = Get-VICredentialStoreItem -File 'D:\Temp\myvc_cred.xml'

Connect-VIServer $vcenterip -Credential $myCred

bu only get error when I run above commands:

Connect-VIServer : Cannot bind parameter 'Credential'. Cannot convert the "VMware.VimAutomation.ViCore.Cmdlets.Commands.Framework.VICredentialStoreItemImpl" value of type "VMware.

VimAutomation.ViCore.Cmdlets.Commands.Framework.VICredentialStoreItemImpl" to type "System.Management.Automation.PSCredential".

At line:1 char:41

+ ... -Credential (Get-VICredentialStoreItem -File 'D:\TEMP\myvc_cred.xml ...

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

    + CategoryInfo          : InvalidArgument: (:) [Connect-VIServer], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

and before run above xxx.ps1 file,I also see the reference article:storing credentials for Alans vCheck script

but I haven't find the command in my PS Shell: Import-PSCredential and Export-PSCredential, the link for "Import/Export PSCredentials functions" was invalid in that reference article.

My Question:

How to Use Credential in my xxx.ps1 file?

I want to use the encrypted password to keep the password safe.

Thanks a lot!

0 Kudos
1 Reply
zhaodiwx
Contributor
Contributor

0 Kudos