Generating Inline Credentials
Scenario/Problem: You need to provide cmdlets with credentials without prompting for them.
Solution: Create a new PSCredential object.
Various cmdlets discussed in this book require SharePoint and/or SQL Server account credentials for proper authentication when performing the desired operations. The examples include using (Get-Credential) as the parameter value, which prompts the user for credentials.
When running these cmdlets in scripts, the prompting for credentials pauses the execution. If you need the script to run straight through, instead of using Get-Credential, you can generate a new PSCredential object inline, as shown in Listing 2.4.
Listing 2.4. Generating Inline Credentials Example
(New-Object System.Management.Automation.PSCredential ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access