---
title: "PowerShell Get-Credential Cmdlet for Managing Credentials"
description: "Discover how to manage credentials using the PowerShell Get-Credential cmdlet and learn more about credential management in this post."
canonical: "https://adamtheautomator.com/powershell-get-credential/"
---

# PowerShell Get-Credential Cmdlet for Managing Credentials

> Discover how to manage credentials using the PowerShell Get-Credential cmdlet and learn more about credential management in this post.

Source: https://adamtheautomator.com/powershell-get-credential/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![PowerShell Get-Credential Cmdlet for Managing Credentials](https://adamtheautomator.com/wp-content/uploads/2019/06/how-to-create-a-powershell-credential-pscredential-PSCredential.png)

# PowerShell Get-Credential Cmdlet for Managing Credentials

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)14 June 20192 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Using Get-Credential](#using-get-credential)
*   [Create a Credential without a Prompt](#create-a-credential-without-a-prompt)
*   [Summary](#summary)

Credentials are a ubiquitous object in PowerShell. Let’s dive right in and learn how we can use the PowerShell Get-Credential cmdlet and also learn how to create PSCredential objects without getting prompted.

PSCredential objects are a creative way to store and pass credentials to various services securely. Many built-in and third-party cmdlets require PSCredential objects on many different commands.

## Using Get-Credential

Typically, to create a _PSCredential_ object, you’d use the `Get-Credential` cmdlet. The `Get-Credential` cmdlet is the most common way that PowerShell receives input to create the _PSCredential_ object like the username and password.

![Get-Credential](https://adamtheautomator.com/content/images/2019/07/img_5b645dc40abc4.png)

Get-Credential

The `Get-Credential` cmdlet works fine and all but it’s interactive. There’s no way to seamless pass values to it. Every time it’s run, it will either prompt for the username and password at the console or pop up a dialog box asking for the username and password.

## Create a Credential without a Prompt

What if you’re working on an automated script that runs in a scheduled task or part of some more significant automation framework? In this case, there’s no one manning the console to type in a username and password. It’s now time to create a _PSCredential_ object from scratch!

To build a _PSCredential_ object with no interaction first requires encrypting the password. The _PSCredential_ object needs a plain-text username and an encrypted string for the password.

To encrypt a password, you will convert a string to a secure string. You do that by using the `ConvertTo-SecureString` cmdlet. Pass a plain-text password to this cmdlet, and because it is plain text, we have to use the `PlainText` and `Force` parameters as well. PowerShell makes it inadvertently clear that you are passing a plain-text password here for sure.

```powershell
$password = ConvertTo-SecureString 'MySecretPassword' -AsPlainText -Force
```

Once you have a secure string created, it’s now time to build the _PSCredential_ object. To do this, use the `New-Object` cmdlet defining an object type of _System.Management.Automation.PSCredential_. The _PSCredential_ class has a constructor that accepts the username and a secure string that we can use by enclosing both in a set of parentheses.

```powershell
$credential = New-Object System.Management.Automation.PSCredential ('root', $password)
```

We now have a _PSCredential_ object saved to do whatever we wish. At this point, we can pass the `$credential` variable to many different commands with a `Credential` parameter, and it’ll work great. To check to see it was created with the expected username and password, we can reference the `UserName` property which should display the username you used earlier.

```powershell
PS> $credential.UserName
root
```

The password is encrypted, but if you read the password on the same computer and logged in user, you can use the `GetNetworkCredential()` method to see the password in plain text. Simply append `GetNetworkCredential()` to the end of the credential object but notice that you won’t immediately see the password.

```powershell
PS> $credential.GetNetworkCredential()

UserName Domain
-------- ------
root
```

To see the password, you’ll need to use the `Password` property on the object that `GetNetworkCredential()` returns.

```powershell
PS51> $credential.GetNetworkCredential().Password
MySecretPassword
```

The password that’s returned should be the same password that you provided early to the _PSCredential_ constructor.

## Summary

You can see that creating a _PSCredential_ object without using the `Get-Credential` cmdlet isn’t too bad at all. In fact, the only task preventing this from being a PowerShell one-liner is just creating the secure string!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-get-credential%2F&text=PowerShell%20Get-Credential%20Cmdlet%20for%20Managing%20Credentials)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-get-credential%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-get-credential%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
