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.
(New-Object System.Management.Automation.PSCredential "domainuser",
(ConvertTo-SecureString "password" -AsPlainText -Force))
Therefore, simply substitute (Get-Credential)
for the text shown in Listing 2.4 with the proper username and password when using a cmdlet with authentication requirements.
3.147.89.24