Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Credentials · PowerShell Automation

Direct answer

PowerShell credentials are PSCredential objects created with Get-Credential or from SecretManagement, passed to -Credential parameters. Never hard-code passwords in scripts.

When to use this

Use this when PowerShell scripts need credentials.

First 30 seconds

1. Credentials as PSCredential objects.

2. Never hard-code passwords.

3. Export-Clixml is DPAPI-bound to user/machine — limited use.

4. Prefer SecretManagement/Vault or gMSA.

5. Avoid CredSSP.

Operational verification

secret store → PSCredential → cmdlet

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
PowerShell 7.5/current
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPowerShell 7.5/current · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when PowerShell scripts need credentials.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

Verify which identity the target actually authenticates, not just that a PSCredential object exists. Inspect only metadata such as user name and credential source; do not log secret values. For remoting or API calls, perform a read-only authorization test and then verify the specific resource permissions needed by the automation.

Step 2 Common mistakes Narrow the fault
  • Plain-text passwords in scripts.
Step 3 Where it fails Narrow the fault

SecureString is not a universal secret-storage solution and PSCredential is not evidence of target authorization. Distinguish secret storage, credential construction, transport/authentication, authorization and the audited target operation. Avoid troubleshooting by printing or persisting plaintext secrets.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Use PSCredential objects.
  • Get from SecretManagement or Get-Credential.
  • Never hard-code passwords.
Key checks
  • Get-Credential — interactive prompt
  • PSCredential from SecretManagement — stored securely
  • No plaintext passwords in scripts — security
ReferenceWhy it matters1 section · depth on demand

In depth

PowerShell represents credentials as PSCredential objects (username plus SecureString password). Handling them correctly keeps passwords out of scripts, logs and command history.

$cred = Get-Credential                                  # interactive
$cred = Get-Secret -Name 'svc-netbox' -Vault Corp       # SecretManagement
Invoke-Command -ComputerName srv01 -Credential $cred { hostname }
AvoidInstead
Plain-text passwords in scriptsSecretManagement vault or gMSA
ConvertTo-SecureString -AsPlainText with a literalRetrieve from a vault at run time
Export-Clixml credentials shared between usersDPAPI files are user- and machine-specific — use a vault
Passing passwords on the command lineParameters of type [PSCredential]

On Windows, group-managed service accounts (gMSA) remove the need to store a password at all for scheduled tasks and services.

ReferenceImportant terms & boundaries1 section · depth on demand

PowerShell mechanics

PSCredential packages a user name with a SecureString password for APIs that accept that abstraction. It is an in-memory credential carrier, not a vault or authorization decision. SecureString reduces casual plaintext exposure in some workflows but its protection, serialization and portability depend on platform and mechanism; converting secrets to plaintext for downstream APIs creates a new exposure boundary.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Authoring and lifecycle

Acquire credentials at runtime from an approved secret source, managed identity or interactive prompt appropriate to the execution context. Never embed passwords in source, command lines or logs. Scope credential lifetime and privilege to the target operation, and prefer token/identity mechanisms designed by the target service when available instead of forcing username/password credentials everywhere.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

PowerShell 7.5/current 7.5/currentMinimal authored PowerShell pattern for Credentials

Assumptions: Review target identity, permissions and environment before mutation.

$cred = Get-Credential
# Pass $cred only to a command that explicitly accepts PSCredential.
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docPowerShell 7.5/current 7.5/current

Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://learn.microsoft.com/en-us/powershell/scripting/security/overview?view=powershell-7.5 · confidence 94%
Embedded reference data

Quick lookup tables

Credentials · PowerShell operational reference

Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.

BoundaryCredentials reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

A credential object can be syntactically valid while authentication fails, and successful authentication does not show authorization. Serialization/remoting can alter how secure values are handled, and service accounts can have different network/delegation behavior than interactive users. Capture identity and auth mechanism, never the secret.

Confirmation

Confirm action

Continue?