Get user credentials securely in PowerShell

#Get user credentials securely
Try {
	$credentials = Get-Credential "$env:username"
Catch {
	$log += "`n- " + $_.Exception.Message

#Get current domain to use for authentication. ADSI = Active Directory
$currentDomain = "LDAP://" + ([ADSI]"").distinguishedName

$activeDirectoryEntry = New-Object System.DirectoryServices.DirectoryEntry($currentDomain,$credentials.GetNetworkCredential().UserName,$credentials.GetNetworkCredential().Password)
if ($ -eq $null)
    $log += "`n- Failed to authenticate that username and password."
} else {
    $log += "`n- Authentication was successful."

#Display Results
$log = "Results:"
function Output-Result {
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > null

Fix “is not digitally signed” powershell error

#Open powershell as administrator
Get-ExecutionPolicy -List
         Scope               ExecutionPolicy
         -----               ---------------
 MachinePolicy               Undefined
    UserPolicy               Undefined
       Process               Unrestricted
   CurrentUser               Unrestricted
  LocalMachine               Unrestricted

#Set all to Unrestricted where allowed. The first two are usually managed by group policy.

Set-ExecutionPolicy Unrestricted -Scope Process
#type Y and press enter