Tag: credentials

Import your own module into a PowerShell Script

I wrote a script to get the mac address off of several servers, so it required my username and password. I don’t like to put my password in a script, but the credentials pop-up box for me to enter my password got a bit cumbersome. I decided to put it an a separate file for 2 reasons, 1) so my password is not saved in a script (I delete from the file once I’m done) and 2) making scripts modular is what it’s all about.

Import-Module C:\Users\username\Documents\WindowsPowerShell\cred.ps1
$servers= @('sugar', 'milk', 'eggs', 'server7', 'buttons')

foreach ($server in $servers) {
    Get-WmiObject -ClassName Win32_NetworkAdapterConfiguration -Filter "IPEnabled='True'" -ComputerName $server | 
    Select-Object -Property MACAddress, Description
    Write-host $server

I wrote my script in one file and my password in a variable in another.


To import it into my script, I added the Import-Module command and the path to my password file and ran the script. No more password prompts.

User Powershell to test a password

Sometimes you need to test to make sure you’re entering the correct the right password. Be it a service account while installing a app or testing a password reset.

The start-process cmdlet is used to start one or more processes on a local computer. Get-Credential gets an object based on username and password. Use it to open an application and test the credentials.

Open a Powershell prompt:

start-process notepad.exe -credential (Get-Credential acme\johnquser)


Enter the credentials you’re trying to test. If you’re correct, notepad will open.



If not, a password reset is in order.



Social media & sharing icons powered by UltimatelySocial