PowerShell Credentials

After playing with powershell for a while I got tired of typing the username and password every time I wanted to access a remote PC or server. There is an attriubute called PSScredentials and allow you to cache your credentials and passthem to your scripts. Here is a basic example

[sourcecode language=”css”]
# Define the Credentials
# Define the Username
$user = Read-host -Prompt "Type your username. Ex user1 or Domainuser1 or user@domain.com"
# Define the secure password
$pass = Read-host -Prompt "Type your password" -AsSecureString
# Define Credentials
$mycreds = New-Object System.Management.Automation.PSCredential ($user,$pass)
# Pass $mycreds variable to any PowerShell Commandlet that support PScredentials value.
[/sourcecode]

Subscribe For Latest Updates

Sign up for best of digital marketing, livestream and technology opinions on what matters to you.

Invalid email address
We promise not to spam you. You can unsubscribe at any time.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: