If you need to use manual mode to connect to your SharePoint site, you will need to enter your credentials in the script. This can be a concern since anyone that has access to the script will be able to see your credentials. There is a PowerShell alternative that can be used in symbiosis with our Connect-Site command. This command is called Get-Credential. Here is how to use it:
PS C:\> $credentials = Get-Credential
This will show a window where you can enter the credentials for this execution of the script.
You can then use those credentials to connect to your site :
PS C:\> $credentials = Get-Credential PS C:\> $site = Connect-Site -Url http://farm/sites/siteCollection -Credential $credentials
Using this technique, you will never expose your credentials in a script. This way, you will need to enter manually your credentials for every execution of the scripts which make scheduling very difficult. It is possible to output the secure string generated by PowerShell for your password. It is not possible for a user to decrypt your password this way but someone could take the encrypted password and use it to do something else. Anyway, it is possible and here is how. You need to first create a small script to get the encrypted password.
PS C:\> $credentials = Get-Credential PS C:\> ConvertFrom-SecureString $credentials.Password 01000000d08c9ddf0115d1118c7a00c04fc297eb01000000c57ba489a6781343983ef0deba79d0250000000002000000000003660000c0000000100000007ba4ea450748178832c0187a37c513270000000004800000a000000010000000a3fe44ced5ac805a2fcf7a6c3652994510000000ccc7701593bd519546d09f216962fac4140000003904619dc8c320b7fb0cafa6efdd78dd2c69c8e5
Then, you can copy this string which is your password encrypted and put it in your script like this to connect to your site :
PS C:\> $secureString = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000c57ba489a6781343983ef0deba79d0250000000002000000000003660000c0000000100000007ba4ea450748178832c0187a37c513270000000004800000a000000010000000a3fe44ced5ac805a2fcf7a6c3652994510000000ccc7701593bd519546d09f216962fac4140000003904619dc8c320b7fb0cafa6efdd78dd2c69c8e5" PS C:\> $password = ConvertTo-SecureString $secureString PS C:\> $username = firstname.lastname@example.org PS C:\> Connect-Site -Url http://farm/sites/siteCollection -Username $username -Password $password
As you can see, your password will not be shown in plain text, but keep in mind that it would still possible to copy the secure string and use it in another script. However, since secure strings are generated using your local machine encryption key and the current user's permissions, they can only be used on the same machine and cannot be transferred to a script running on a different machine.