I need help with below code I am writing to automate sql server install
param(
#Name of SQL Server host
[parameter(Mandatory=$true,
HelpMessage="Enter Server Name/machine name",Position=0)]
[String]
[ValidateNotNullOrEmpty()]
$server = $(throw "server parameter is required."),
#MS Install folder name
[parameter(Mandatory=$true,
HelpMessage="Enter Install folder name",Position=1)]
[String]
[ValidateNotNullOrEmpty()]
$folder = $(throw "Install folder name is required."),
#MS SQL Server edition, std or ent
[parameter(Mandatory=$true,
HelpMessage="Enter SQL Server STD or ENT Edition",Position=2)]
[String]
[ValidateNotNullOrEmpty()]
$edition = $(throw "edition parameter is required."),
#MS SQL Server service pack install
[parameter(Mandatory=$true,
HelpMessage="Install service pack YES or NO",Position=3)]
[String]
[ValidateNotNullOrEmpty()]
$servpk = $(throw "Service pack YES or NO is required."),
#Enter Environment PROD, QA, DR or DEV
[parameter(Mandatory=$true,
HelpMessage="Enter Environment PROD, QA, DR or DEV",Position=4)]
[String]
[ValidateNotNullOrEmpty()]
$environment = $(throw "Environment parameter PROD, QA, DR or DEV is required."),
#Instance name , null for default
[parameter(Mandatory=$true, HelpMessage="Enter Instance name, null for default", Position=5)]
[String]
[AllowEmptyString()]
$instance
)
###Variables
# map network drive to Z drive
Remove-PSDrive -Name Z
New-PSDrive –Name Z –Root "\\nylimrps-fs1\vol2\wp" -Persist -PSProvider FileSystem
# set to default scripts directory
$scriptsHome = 'Z:\AN0413\SQL\DBStandards\SQL Server 2008 Silent install\InstallFolder\'
cd 'Z:\AN0413\SQL\DBStandards\SQL Server 2008 Silent install\InstallFolder\'
New-Item $folder -type directory
cd $folder
$logFile = $PWD.Path + '\SQLDeploy_Log.txt'
Write-Host "Your log file is ",$logFile
#Initialize log file
Get-Date | Out-File $logFile
If ($edition -eq 'STD')
{
If $instance -eq "" -or $instance -eq $null
{
Copy-Item 'Z:\AN0413\SQL\DBStandards\SQL Server 2008 Silent install\Default Instance Install\ConfigurationFile.ini'
Copy-Item 'Z:\AN0413\SQL\DBStandards\SQL Server 2008 Silent install\Default Instance Install\InstallSQL2008R2_STD_default.bat'
}
ELSE
{
Copy-Item 'Z:\AN0413\SQL\DBStandards\SQL Server 2008 Silent install\Named Instance Install\ConfigurationFile_NamedInstance.ini'
Copy-Item 'Z:\AN0413\SQL\DBStandards\SQL Server 2008 Silent install\Named Instance Install\InstallSQL2008R2_STD_NamedInstance.bat'
}
}
The above code snipet is saved as InstallSQL1.ps1 under C:\Silent install testing\
I am running this
cd 'C:\Silent install testing\'
set-executionpolicy unrestricted
powershell.exe -NoProfile -Command .\InstallSQL1.ps1 [-server] 'test' [-folder] 'test1' [-edition] 'STD' [-servpk] 'NO' [-environment] 'DEV' [-instance] 'TEST1'
I get below error, about positional paramter [-servpk] but I am passing it so I am not sure why its giving this error
powershell.exe : C:\Silent install testing\InstallSQL.ps1 : A positional parameter cannot beAt line:3 char:1
+ powershell.exe -NoProfile -Command .\InstallSQL.ps1 [-server] 'test' [-folder] ' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (C:\Silent insta...eter cannot be :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
found that accepts argument '[-servpk]'.
At line:1 char:1
+ .\InstallSQL.ps1 [-server] test [-folder] test1 [-edition] STD [-servpk] NO
[-en ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidArgument: (:) [InstallSQL.ps1], Parameter
BindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,InstallSQL.ps1
powershell.exe : C:\Silent install testing\InstallSQL1.ps1 : A positional parameter cannot be
At line:4 char:1
+ powershell.exe -NoProfile -Command .\InstallSQL1.ps1 [-server] 'test' [-folder] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (C:\Silent insta...eter cannot be :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
found that accepts argument '[-servpk]'.
At line:1 char:1
+ .\InstallSQL1.ps1 [-server] test [-folder] test1 [-edition] STD [-servpk] NO
[-e ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidArgument: (:) [InstallSQL1.ps1], Paramete
rBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,InstallSQL1.ps1
RPSAdmin