I continue to get an error when trying to create a new-spwebapplication in powershell for sharepoint.

The error message says Cannot bind parametre "databasecredentials".  "Cannot convert the domain\username value of type "system.string" to type "".

I am fairly new at this powershell thing so any help that I could get would be really appreciated.

asked 12/09/2011 04:48

mockweb's gravatar image

mockweb ♦♦

2 Answers:
What this is saying is that you are not providing your credentials in a secure format. You have to first encrypt the password and then call it. One way to do this is with a password file. You can create one by issuing the following command:
read-host -assecurestring | convertfrom-securestring | out-file C:Scriptscred.txt

It will give you a blank line, at that point, type in the password of the account you are wanting to use to create the spwebapplication and hit enter.

After that you can write the secured password to a variable like this:
$password = get-content C:scriptscred.txt | convertto-securestring

Then you can set the full credential like this (replace domain\username with your administrative username:
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "domainusername",$password

Now all that is left is to create the spwebapplicaion. You should be able to use -databasecredentials $credentials in the new-spwebapplication cmdlet. So it would look something like:
new-spwebapplication "applicationName" -DatabaseCredentials $credentials ....

You can reuse the password file as often you want as long as it is running from the same computer under the same user and the password has not changed.


GusGallows's gravatar image


With the steps outlined above you can create a persistent instance of the Credential object.  My only caveat here is that SecureString is not really secure.  It really just prevents people who don't know Powershell from doing anything with it.  If you need to just do this once in a while use the second example from above and pass the $credentials object as outlined in code snippet 4 above.  My point is solely about: 1) security - don't use files if you can and 2) frequency of use - if you only do this once in a while just type in your credential (authority\identity) and password to get the same thing to work.

answered 2011-12-09 at 13:14:46

wls3's gravatar image


Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



Asked: 12/09/2011 04:48

Seen: 193 times

Last updated: 12/13/2011 03:26