Use this when PowerShell scripts need credentials.
Credentials · PowerShell Automation
PowerShell credentials are PSCredential objects created with Get-Credential or from SecretManagement, passed to -Credential parameters. Never hard-code passwords in scripts.
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.
secret store → PSCredential → cmdlet
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
- Use PSCredential objects.
- Get from SecretManagement or Get-Credential.
- Never hard-code passwords.
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 }
| Avoid | Instead |
|---|---|
| Plain-text passwords in scripts | SecretManagement vault or gMSA |
ConvertTo-SecureString -AsPlainText with a literal | Retrieve from a vault at run time |
Export-Clixml credentials shared between users | DPAPI files are user- and machine-specific — use a vault |
| Passing passwords on the command line | Parameters 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.
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
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Review target identity, permissions and environment before mutation.
$cred = Get-Credential
# Pass $cred only to a command that explicitly accepts PSCredential.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%Quick lookup tables
Credentials · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | Credentials reference |
|---|---|
| Runtime identity | PowerShell edition/version + command/module source |
| Persistent intent | Script/module/config prerequisites under source control |
| Verification | Read-only discovery → execution evidence → independent target read-back |
| Output contract | Structured objects/streams before formatting |
| Failure boundary | Separate engine/binding from transport/API/native and target-state failures |
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.