Specifying credentials

You can use Set-CdmCredential cmdlet to specify a credential that you want to cache in the form of a PSCredential object. You can create the PSCredential object using the Get‑Credential cmdlet. The Get-Credential cmdlet will prompt user interactively to specify a user name and password. You can also pass the user name as a parameter to the Get-Credential cmdlet to have the cmdlet prompt the user for the password.

If you want to specify the credentials to establish a connection with Active Directory without prompting for a password, you can hard code the user name and password for the PSCredential object into your script. For example:

$SecurePassword = "p@ssw0rd" | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential 
  -ArgumentList "DOMAIN\user", $SecurePassword

In most cases, hard coding a password into a script is not a secure practice and is not recommended. However, it does allow you to write scripts that run without user interaction.