Skip to content

vBlog.nl

All about technology

Menu
  • Home
  • VMware Cloud Director
  • vSphere
  • Automation
    • PowerCLI
    • PowerShell
    • Terraform
  • NSX
  • Horizon DaaS
  • About Us
Menu

Use Windows 11 Credential Manager for PowerCLI credentials

Posted on August 31, 2022

This article demonstrates how to leverage the built-in Credential Manager in Windows 11 for storing your credentials in PowerShell / PowerCLI scripts.

The story behind this article is that I wanted to build some scripts for VM provisioning and such in my homelab without storing my passwords in plain-text in the script.

By leveraging the -credential parameter and the Windows Credential Manager on my Windows 11 system I’m avoiding the use of usernames and passwords in the script.

Table of Contents

  • Windows 11 Credential Manager
  • Install the Credential Manager module in PowerShell
  • Add new credentials to the Credential Manager
  • Use the credentials in our script
  • Remove the credentials from the Windows Credential Manager
  • External resources

Windows 11 Credential Manager

Credential Manager isn’t a new feature, but it’s still very useful on Windows 11 systems.
The Credential Manager on Windows 11 has the following key features:

  • Store a user’s sign-in information for sites and applications.
  • Store sign-in data for networks such as shared drives or mapped network drives.
  • View, add, remove, and create back-ups of all your stored credentials.

In this article I will connect to a VMware vCenter Server 7.0 using the -credential parameter in PowerCLI.

First I will show my current Credential Manager in Windows 11.

Press Win+S and type Credential Manager.

Open the Windows Credential Manager
Open Windows 11 Credential Manager

Switch from the Web Credentials view to the Windows Credentials view.
These are my existing credentials today. Later on in this article we will see a new credential being added here.

Windows 11 Credential Manager
Windows 11 Credential Manager

The benefits of using Windows Credential Manager to store your PowerShell credentials are:

  • Super easy to connect to VMware ESXi hosts and/or vCenter Servers using the -credential parameter
  • No more saving your username and password inside the script.
  • Credentials Stored in the Credential Manager are associated with your Windows user account, which are
    not transferable between other users on the system.
  • Credentials Stored in the Credential Manager are associated with your Windows user account, which are
    not transferable between systems.

Install the Credential Manager module in PowerShell

To save new credentials in the Windows Credential Manager we will use the New-StoredCredential, which is not available by default: A PowerShell Module must be installed first.

The term 'New-StoredCredential' cmdlet is not recognized as a name of a cmdlet, function, script file, or executable program.
The term ‘New-StoredCredential’ cmdlet is not recognized as a name of a cmdlet, function, script file, or executable program.

Run the following command to install the Windows Credential Manager module

Install-Module -Name CredentialManager -force

After installing, the following three new commands will be available:

Get-StoredCredential
New-StoredCredential
Remove-StoredCredential

As with any other PowerShell cmdlet, you can display the syntax for any of these cmdlets by using PowerShell’s Get-Help cmdlet. We have to type Get-Help, followed by the cmdlet’s name that we need help with.

For example, if we wanted to see the syntax for the New-StoredCredential cmdlet, we would type:

Get-Help New-StoredCredential
Get-Help NewStoredCredential
Get-Help NewStoredCredential

Add new credentials to the Credential Manager

Step 1 is to add a new credential to the Credential Manager.
This can be done using the GUI, but in this example I will add new vCenter Server credentials using CLI with the New-StoredCredential command.

New-StoredCredential -Target "vCenter-Server" -Persist "LocalMachine" -Credentials $(Get-Credential)

Fill in your username & password, choose OK and head back to the Windows Credential Manager.
The result will look like the example below.

New-StoredCredential command
New-StoredCredential command

Refresh your Windows Credential Manager and you will see the

Windows 11 Credential Manager
The new vCenter Server credentials have been added to the Credential Manager

Use the credentials in our script

Head back to the PowerShell window and run the following commands:

$VCSA = 'vcsa01.vmroe.local'
$Credential = Get-StoredCredential -Target 'vCenter-Server'
Connect-VIServer $VCSA -Credential $Credential

The result will look like the following figure

Connect-VIServer $VCSA -Credential $Credential
Connect-VIServer $VCSA -Credential $Credential

Remove the credentials from the Windows Credential Manager

If you don’t need the credentials anymore, you can easily remove the credentials from the Windows Credential Manager by running to following command:

$Credential = 'vCenter-Server'
Remove-StoredCredential -Target $Credential

Happy coding!

External resources

VMware Developer page for Connect-VIServer

Microsoft Support page for Credential Manager

Other articles on vBlog related to automation

 337 total views,  5 views today

Share on Social Media
twitter facebook linkedin reddit emailwhatsapptelegram

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent articles

  • VMware Cloud on AWS with FSx for NetApp ONTAP December 28, 2022
  • Workspace ONE Access – Change certificate December 22, 2022
  • UI themes for VMware Cloud Director 10.4.1 and later December 16, 2022
  • VMware Tanzu Kubernetes Grid December 15, 2022
  • Workspace One Access – Not logged in to server FQDN. Please invoke Save before Sync December 12, 2022
  • NSX Edge configuration has failed. 1G hugepage support required. December 7, 2022
  • Horizon DaaS – Unable to connect to Desktop November 24, 2022
  • How to: Request and Install a Lets Encrypt Wildcard SSL on VMware Cloud Director 10.4 October 17, 2022
  • New and improved vSAN 8 explained September 24, 2022
  • How to update a stand alone ESXi host September 13, 2022

Tags

Automation bootstrapping Container Service Extension Credential Manager Desktone.log ESXi EUC EXi GPU Horizon DaaS Instant-Clone Logging NSX nsx-t PowerCLI PowerShell Putty Raspberry PI SSL Tanzu Terraform update vcd-cli vCenter vCloud vCloud Availability vCloud Director VDI vGPU VMware VMworld vSAN vSphere vVols workspace one Zerto

VMware Cloud Provider Blog

  • Usage Meter Registration and Usage Report APIs are now part of Cloud Provider APIs on developer.vmware.com
    by Galina Slavova on February 3, 2023 at 1:12 pm

    We have an important announcement to make – Usage Meter and Usage Report APIs are now part of the Cloud Provider Navigator and can be accessed from the Cloud Provider section on developer.vmware.com. Furthermore, there is a new API for registering Usage Meter with a contract in the VCPP Commerce Portal. Here is how the … Continued The post Usage Meter Registration and Usage Report APIs are now part of Cloud Provider APIs on developer.vmware.com appeared first on VMware Cloud Provider Blog.

  • Introducing Sovereign Cloud Compliance Pack for Aria Operations
    by Amith Vijayanand on February 2, 2023 at 6:30 am

    We are happy to announce the availability of Sovereign Cloud Compliance pack for Aria Operations for our Sovereign Cloud Partners as on 31st January 2023. Introduction of the sovereign cloud compliance pack allows VMware sovereign cloud providers an extended ability to maintain their sovereign posture and allows them to expand their services in to the … Continued The post Introducing Sovereign Cloud Compliance Pack for Aria Operations appeared first on VMware Cloud Provider Blog.

  • VMware Cloud Director extension for VMware Data Solutions 1.1
    by Amith Vijayanand on February 1, 2023 at 6:30 am

    We are glad to announce the general availability of VMware Cloud Director extension for VMware Data Solutions (DSE) version 1.1 as of January 31, 2023. We announced the DSE 1.0, in November 2022, where we introduced the support for data services starting with VMware RabbitMQ (supporting version 1.3) in the VMware Data Solutions portfolio. Today, we announce … Continued The post VMware Cloud Director extension for VMware Data Solutions 1.1 appeared first on VMware Cloud Provider Blog.

  • Introducing A New TechZone Section for VMware Sovereign Cloud
    by Cory Allen on January 31, 2023 at 2:30 pm

    The VMware Sovereign Cloud initiative gives our Cloud Providers the ability to offer flexible, secure, and scalable environments aimed at protecting data sovereignty. We are happy to announce the launch of a new section on our VMware Cloud Tech Zone website for VMware Sovereign Cloud. This site brings together all technical-related content to help our Cloud … Continued The post Introducing A New TechZone Section for VMware Sovereign Cloud appeared first on VMware Cloud Provider Blog.

  • Managed IDS/IPS for VMware Cloud Director
    by Romain Decker on January 30, 2023 at 7:34 pm

    Want to add IDS/IPS services with VMware Cloud Director™ using VMware NSX? There’s a white paper for that! Many VMware Cloud Providers are interested in offering VMware NSX IDS/IPS in their multi-tenant environments managed by VMware Cloud Director. Intrusion Detection Systems (IDS) emerged in the late 1990s to detect traffic patterns indicative of incoming attacks. … Continued The post Managed IDS/IPS for VMware Cloud Director appeared first on VMware Cloud Provider Blog.

©2023 vBlog.nl | Design: Newspaperly WordPress Theme