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 ...

Get PowerShell™ for SharePoint® 2013 How-To now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.