?
Solved

Error on parameters format in a function that installs a SharePoint Farm

Posted on 2011-04-20
11
Medium Priority
?
1,565 Views
Last Modified: 2012-05-11
In my mainscript I use a param for user input of the parameters, after the param I read in my module with the functions, and then I call my functions. In this example I have problems with my function SPInstall. I get errors like the parameters are`nt i in the correct format, or PassPhrase is null, etc. I didn´t post full function, because the it looks like the problem is in the creating a PSCredential object code segment and secure-password transformation.
I got this error for example:

ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it
is an empty string.
At C:\Install\Script\SharePointModule.psm1:86 char:55
+     $securePassPhrase = ConvertTo-SecureString -String <<<<  $passPhrase -AsP
lainText –Force
    + CategoryInfo          : InvalidData: (:) [ConvertTo-SecureString], Param
   eterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
   lowed,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand

Can´t I write like that or what am I missing?
 I´ve called the method from PowerShell console for example:

New-SPInstallation databseName databaseServer centralAdminDatabase 5000 NTLM passPhrase domain\farm password

I can call parameters like that, I don´t have to use quotes around paramers like when hardcoding values direct into the script??

Her´s the param for user input for the function below and the function call:
 
param (
 $databaseName = (Read-Host "Specify Farm database name"),   
   $databaseServer = (Read-Host "Database server"), 
  $centralAdminDatabase = (Read-Host "Specify central administration database"),
  $CAport = (Read-Host "Specify Central Administration port"),
  $windowsAuthenticationProvider = (Read-Host "Specify Windows Authentication Provider value"),
    $passPhrase = (Read-Host "Password Phrase"),
   $user = (Read-Host "User"),
  $password = (Read-Host "Specify Farm Password")
)

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
New-SPInstallation $databaseName $databaseServer $centralAdminDatabase $CAport $windowsAuthenticationProvider $passPhrase $user $password 

Open in new window


And here´s the function[a part of the function, where I get the errors]:
## Install SharePoint 
function New-SPInstallation {
  Param
    (
      [String]$databaseName,
		
      [String]$databaseServer,
	  
      [String]$centralAdminDatabase,
	 
      [String]$CAport,
	 
      [String]$windowsAuthenticationProvider,
	 
      [String]$passPhrase,
	 $user,
	 $password
    )
	# Converting password strings to secure strings
	$securePwd = ConvertTo-SecureString -String $password -AsPlainText –Force
    $securePassPhrase = ConvertTo-SecureString -String $passPhrase -AsPlainText –Force
	# Creating a PSCredential object
	$mrFarmAdmin = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $securePwd
    
	#Etc, etc, more function code.......

Open in new window

0
Comment
Question by:MickMorg
  • 7
  • 4
11 Comments
 
LVL 2

Expert Comment

by:gcitron
ID: 35431358
The error cause is that passPhrase is an empty string. That string was requested from console:
$passPhrase = (Read-Host "Password Phrase")

If you like to permit empty password replace
$securePassPhrase = ConvertTo-SecureString -String $passPhrase -AsPlainText –Force
with somethiong like that:

$securePassPhrase = new-object System.Security.SecureString
If ( $passPhrase.length > 0 ) {
    $securePassPhrase = ConvertTo-SecureString -String $passPhrase -AsPlainText –Force
}
0
 

Author Comment

by:MickMorg
ID: 35439182
But I have not leaved an empty string for $passPhrase when prompted for it...
In the post, I´ve written my function call, no empty parameters there..!

So I don´t understand WHY I get that error, is the converting thing for secure password and passPhrase correct?
0
 
LVL 2

Expert Comment

by:gcitron
ID: 35439288
Can you test with "write-host $passPhrase" if what you type on prompt is what you get in variable? Maybe is some special char in password...
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:MickMorg
ID: 35439392
I get error on the $password parameter. If I type: !zyxzapr3 , I get a prompted message from the system, that " !zyxzapr1 cannot be recognizes as a valid prompt command.
And I get promped for that parameter again, and then the installation fails for that function.

for the test Write-Host $passPhrase, I get the value I entered for the parameter $password ( !zyxzapr1)




0
 

Author Comment

by:MickMorg
ID: 35439424
This is the code after above code in the same function that fails, iI get the error here from the Write-Warning in database configuration, do I send correct parameters to New-SPConfiguration Database?

# Converting password strings to secure strings
 $securePwd = ConvertTo-SecureString -String $password -AsPlainText –Force
  $securePassPhrase = ConvertTo-SecureString -String $passPhrase -AsPlainText –Force
# Creating a PSCredential object
$mrFarmAdmin = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $securePwd
    


 Write-Host "Installing Configuration Database" -ForegroundColor Green
  Try {
    # New Configuration Database
New-SPConfigurationDatabase -DatabaseName $databaseName -DatabaseServer $databaseServer -AdministrationContentDatabaseName $centralAdminDatabase -Passphrase $securePassPhrase -FarmCredentials $mrFarmAdmin -ErrorAction Stop | Out-Null
    Write-Host "SPConfigurationDatabase: $databaseName installed" -ForegroundColor Green
  }
  Catch {
    Write-Warning "Unable to Create ConfigurationDatabase: $databaseName"
    $error
    Continue
}

Open in new window

0
 
LVL 2

Accepted Solution

by:
gcitron earned 2000 total points
ID: 35439504
Hmm, that's the problem - the password is beginning with !. You can type two !! instead one at beginning and in variable you will get only one. Or read password directly as SecureString, but then you must remove conversion from New-SPInstallation function, change name and type of variable in declaration etc:
$passPhrase = (Read-Host "Password Phrase" -AsSecureString)
0
 
LVL 2

Expert Comment

by:gcitron
ID: 35439531
Just tested without the prompt and is working wih one !. That's strange, must be a bug!
You can use as workaround:
$passPhrase = ((Write-host "Password Phrase:" -NoNewline)+(Read-Host))
0
 

Author Comment

by:MickMorg
ID: 35460054
Look at  this fun for the function above, New_SPInstallation, I get some error I can´t make any sense from:


Read-Host : An error of type "System.Management.Automation.Host.PromptingException" has occurred.
At C:\Script\FullScript.ps1:10 char:31
+     $databaseName = (Read-Host <<<<  "Specify Farm database name [not optional]"),  
    + CategoryInfo          : ResourceUnavailable: (:) [Read-Host], PromptingException
    + FullyQualifiedErrorId : System.Management.Automation.Host.PromptingException,Microsoft.PowerShell.Commands.ReadHostCommand
 
Installing Configuration Database
WARNING: Unable to Create ConfigurationDatabase: SharePoint_Config
PS C:\Windows\SysWOW64> $Error[0] | fl -Force


NodeToken      : continue
Argument       :
Label          :
Message        : System error.
Data           : {}
InnerException :
TargetSite     : System.Array SynchronousExecuteEnumerate(System.Object, System.Collections.Hashtable, Boolean)
StackTrace     :    at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable e
                 rrorResults, Boolean enumerate)
                    at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
HelpLink       :
Source         : System.Management.Automation
0
 

Author Comment

by:MickMorg
ID: 35460123
Sorry for the misstype in my post above: "Look at  this fun for the function above, New_SPInstallation, I get some error I can´t make any sense from"

But you know what I mean...

Anyone know what that error is?
0
 

Author Comment

by:MickMorg
ID: 35477736
I solved my errors my self, the function ran without any modifications. The problem were some AD account rights...I tested it in some strange environment I didn´t know much about. When I built my own test env.the script run.

Thanks for trying to help anyway gcitron :)
0
 

Author Closing Comment

by:MickMorg
ID: 35735780
The problem were technical rather than code problems I solved it myself. But i want this expert to get credit for the help anyway :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question