![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
Scripted Installation with PowerShell
All,
I am really sorry, but I am obviously missing something REALLY basic here. I am trying to create a scripted installaiton for an application that has a lot of dependancies and moving parts. I have been successful using CMD but PoSH is the future so I figured this would be a good way to learn it. The script has to call an installation with parameters, then call SQL with parameters...etc. I need to call several external applications from my PoSH script. It does not work! In CMD I might call: %installdir% application.exe /foo bar How the heck do you do that in PowerShell? (And don't get me started about having spaces in the directory names!!! )I have tried various versions of Invoke-Expression but that crashes when I use command line parameters. I understand that PoSH has amazing abilites, but this seemingly simple task has me stumped! Can anyone point me in the right direction? Even just an example that WORKS! Thanks in advance! -- Matthew McDermott, MVP Principal Consultant Catapult Systems, Inc. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Hi Matthew, Try with the call operator (ampersand): & <pathToApplication>\application.exe /foo bar If you need the command to wait for completion before moving to the next line of code then pipe it to out-null: & <pathToApplication>\application.exe /foo bar | out-null PowerShell also has a DOS %ErrorLevel% equivalent, check this post for more information: http://blogs.msdn.com/powershell/arc...quivalent.aspx Hope this helps --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com > All, > > I am really sorry, but I am obviously missing something REALLY basic > here. > > I am trying to create a scripted installaiton for an application that > has a lot of dependancies and moving parts. I have been successful > using CMD but PoSH is the future so I figured this would be a good way > to learn it. The script has to call an installation with parameters, > then call SQL with parameters...etc. > > I need to call several external applications from my PoSH script. It > does not work! > > In CMD I might call: > > %installdir% application.exe /foo bar > > How the heck do you do that in PowerShell? (And don't get me started > about having spaces in the directory names!!! )> > I have tried various versions of Invoke-Expression but that crashes > when I use command line parameters. > > I understand that PoSH has amazing abilites, but this seemingly simple > task has me stumped! > > Can anyone point me in the right direction? Even just an example that > WORKS! > > Thanks in advance! > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Thanks for the reply.
Let me add a better example: The applications and command line params will change, so I made them variables: $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" $execSql = "`"$sqlExec`" -S MOSS1 -i DB_Create_Script.txt" I need the double quotes (I think) so that the line will work. Then I am trying to execute $execSql: Invoke-Expression -Command $execSql And I get the following: The term '"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" -S MOSS1 -i DB_Create_Script.txt' is not rognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At C:\PoSH\farmbuild.ps1:31 char:2 + & <<<< $execSql | Out-Null Does that help? I am really struggling... -- Matthew McDermott, MVP Principal Consultant Catapult Systems, Inc. "Shay Levi" wrote: > > Hi Matthew, > > > Try with the call operator (ampersand): > > & <pathToApplication>\application.exe /foo bar > > > > If you need the command to wait for completion before moving to the next > line of code then pipe it to out-null: > > & <pathToApplication>\application.exe /foo bar | out-null > > > > PowerShell also has a DOS %ErrorLevel% equivalent, check this post for more > information: > > http://blogs.msdn.com/powershell/arc...quivalent.aspx > > > > > Hope this helps > > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > > > All, > > > > I am really sorry, but I am obviously missing something REALLY basic > > here. > > > > I am trying to create a scripted installaiton for an application that > > has a lot of dependancies and moving parts. I have been successful > > using CMD but PoSH is the future so I figured this would be a good way > > to learn it. The script has to call an installation with parameters, > > then call SQL with parameters...etc. > > > > I need to call several external applications from my PoSH script. It > > does not work! > > > > In CMD I might call: > > > > %installdir% application.exe /foo bar > > > > How the heck do you do that in PowerShell? (And don't get me started > > about having spaces in the directory names!!! )> > > > I have tried various versions of Invoke-Expression but that crashes > > when I use command line parameters. > > > > I understand that PoSH has amazing abilites, but this seemingly simple > > task has me stumped! > > > > Can anyone point me in the right direction? Even just an example that > > WORKS! > > > > Thanks in advance! > > > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
> I am really struggling... > Yeah, I struggled with something similar recently. I couldn't find a solution. I'm thinking there might be another way to go about this... I'm assuming you're "commands" like $sqlExec will be a small limited number, but your variables passed like what you tagged on to create $execSql will vary a lot? Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Hi Matt,
I think I can help here, with some examples. At the PS command prompt, if you enter somecommand.exe PS will interprete "somecommand" as a command and you'll get what you want. if you enter "somecommand.exe" PS will interpret it as simple string, and just echo that string back to you. It does not execute the program. if you enter & "somecommand.exe" PS will execute the string as a command, and you'll get what you want. If the command you want to execute requires a space in the name, you MUST quote it, and you MUST use the & so that it will be executed instead of interpreted as a simple string. c:\program files\myfolder\somecommand.exe gives the error "The term 'C:\Program' is not recognized as a cmdlet, ..." and "c:\program files\myfolder\somecommand.exe" just echoes the string, while & "c:\program files\myfolder\somecommand.exe" executes the program identified by the string. invoke-expression interprets a string the same way the command line interpreter does. So $cmd = "c:\program files\myfolder\somecommand.exe" invoke-expression $cmd interprets $cmd as if you had entered that string (which does not have embedded quotes, right?) as a command, and gives the "not recognized as a cmdlet" error. Embedding quotes in the string like this: $cmd = "c:\program files\myfolder\somecommand.exe" invoke-expression $cmd will just echo the string back at you. This would work: $cmd = '& "c:\program files\myfolder\somecommand.exe"' invoke-expression $cmd (Note that I'm now using single-quote on the outside so that I can embed the double-quotes without escaping that character. ) so this should work for you: $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" $execSql = "& `"$sqlExec`" -S MOSS1 -i DB_Create_Script.txt" invoke-expression $execSql It was confusing to me tool. Hope this helps. - Leo "Matthew McDermott" wrote: > Thanks for the reply. > > Let me add a better example: > > The applications and command line params will change, so I made them > variables: > > $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" > $execSql = "`"$sqlExec`" -S MOSS1 -i DB_Create_Script.txt" > > I need the double quotes (I think) so that the line will work. > > Then I am trying to execute $execSql: > > Invoke-Expression -Command $execSql > > And I get the following: > > The term '"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" > -S MOSS1 -i DB_Create_Script.txt' is not rognized as a cmdlet, function, > operable program, or script file. Verify the term and try again. > At C:\PoSH\farmbuild.ps1:31 char:2 > + & <<<< $execSql | Out-Null > > Does that help? > > I am really struggling... > > -- > Matthew McDermott, MVP > Principal Consultant > Catapult Systems, Inc. > > > "Shay Levi" wrote: > > > > > Hi Matthew, > > > > > > Try with the call operator (ampersand): > > > > & <pathToApplication>\application.exe /foo bar > > > > > > > > If you need the command to wait for completion before moving to the next > > line of code then pipe it to out-null: > > > > & <pathToApplication>\application.exe /foo bar | out-null > > > > > > > > PowerShell also has a DOS %ErrorLevel% equivalent, check this post for more > > information: > > > > http://blogs.msdn.com/powershell/arc...quivalent.aspx > > > > > > > > > > Hope this helps > > > > > > --- > > Shay Levi > > $cript Fanatic > > http://scriptolog.blogspot.com > > > > > All, > > > > > > I am really sorry, but I am obviously missing something REALLY basic > > > here. > > > > > > I am trying to create a scripted installaiton for an application that > > > has a lot of dependancies and moving parts. I have been successful > > > using CMD but PoSH is the future so I figured this would be a good way > > > to learn it. The script has to call an installation with parameters, > > > then call SQL with parameters...etc. > > > > > > I need to call several external applications from my PoSH script. It > > > does not work! > > > > > > In CMD I might call: > > > > > > %installdir% application.exe /foo bar > > > > > > How the heck do you do that in PowerShell? (And don't get me started > > > about having spaces in the directory names!!! )> > > > > > I have tried various versions of Invoke-Expression but that crashes > > > when I use command line parameters. > > > > > > I understand that PoSH has amazing abilites, but this seemingly simple > > > task has me stumped! > > > > > > Can anyone point me in the right direction? Even just an example that > > > WORKS! > > > > > > Thanks in advance! > > > > > > > > > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Hi Matthew,
The spaces in the PE32's path are the problem. First use Get-Command to see if the PE32 can be accessed directly from the Environment's Path, if so you can call it straight out. If not, assign its path by escaping the spaces in a single-quoted string: # see if the PE32 is in $env ath$sqlExec = gcm sqlCmd -c Application -ea 0 $sqlExec -ne $null # if previous statement is $true execute directly sqlCmd -S MOSS1 -i DB_Create_Script.txt # not in $env ath, single-quote the path and scape the spaces$sqlExec = 'C:\Program` Files\Microsoft` SQL` Server\90\Tools\Binn\sqlcmd.exe' $execSql = "$sqlExec -S MOSS1 -i DB_Create_Script.txt" iex $execSql # tricky quotes and the ` $s1 = "`one back tick gets expanded in double-quoted strings" $s2 = "``only one back tick gets expanded in double-quoted strings" $s3 = '`one back tick does not get expanded in single-quoted strings' "$s1`n$s2`n$s3" -- Kiron |
|
|
|
#7 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Hi Matthew,
I can't see any reason why this won't work: $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" & $sqlExec -S MOSS1 -i DB_Create_Script.txt --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com MM> Thanks for the reply. MM> MM> Let me add a better example: MM> MM> The applications and command line params will change, so I made them MM> variables: MM> MM> $sqlExec = "C:\Program Files\Microsoft SQL MM> Server\90\Tools\Binn\sqlcmd.exe" $execSql = "`"$sqlExec`" -S MOSS1 MM> -i DB_Create_Script.txt" MM> MM> I need the double quotes (I think) so that the line will work. MM> MM> Then I am trying to execute $execSql: MM> MM> Invoke-Expression -Command $execSql MM> MM> And I get the following: MM> MM> The term '"C:\Program Files\Microsoft SQL MM> Server\90\Tools\Binn\sqlcmd.exe" MM> -S MOSS1 -i DB_Create_Script.txt' is not rognized as a cmdlet, MM> function, MM> operable program, or script file. Verify the term and try again. MM> At C:\PoSH\farmbuild.ps1:31 char:2 MM> + & <<<< $execSql | Out-Null MM> Does that help? MM> MM> I am really struggling... MM> MM> "Shay Levi" wrote: MM> >> Hi Matthew, >> >> Try with the call operator (ampersand): >> >> & <pathToApplication>\application.exe /foo bar >> >> If you need the command to wait for completion before moving to the >> next line of code then pipe it to out-null: >> >> & <pathToApplication>\application.exe /foo bar | out-null >> >> PowerShell also has a DOS %ErrorLevel% equivalent, check this post >> for more information: >> >> http://blogs.msdn.com/powershell/arc...orLevel-equiva >> lent.aspx >> >> Hope this helps >> >> --- >> Shay Levi >> $cript Fanatic >> http://scriptolog.blogspot.com >>> All, >>> >>> I am really sorry, but I am obviously missing something REALLY basic >>> here. >>> >>> I am trying to create a scripted installaiton for an application >>> that has a lot of dependancies and moving parts. I have been >>> successful using CMD but PoSH is the future so I figured this would >>> be a good way to learn it. The script has to call an installation >>> with parameters, then call SQL with parameters...etc. >>> >>> I need to call several external applications from my PoSH script. It >>> does not work! >>> >>> In CMD I might call: >>> >>> %installdir% application.exe /foo bar >>> >>> How the heck do you do that in PowerShell? (And don't get me started >>> about having spaces in the directory names!!! )>>> >>> I have tried various versions of Invoke-Expression but that crashes >>> when I use command line parameters. >>> >>> I understand that PoSH has amazing abilites, but this seemingly >>> simple task has me stumped! >>> >>> Can anyone point me in the right direction? Even just an example >>> that WORKS! >>> >>> Thanks in advance! >>> |
|
|
|
#8 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Shay,
I don't understand either, but as I said I have to run it as params in variables so my expression is: $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" $sqlParams = "-S MOSS1 -i DB_Create_Script.txt" & $sqlExec $sqlParams And sqlcmd returns a parameter error. If I run it your way it works...BUT the command fails because the sqlcmd process cannot "SEE" the directories I created from PoSH. I simply execute a mkdir and create the data and log locations. When I do this manually (or via CMD) the databases are created in the directories, but when I use PoSH to create the directories I get: Directory lookup for the file "c:\MSSQL\Log\SharePoint_Config.ldf" failed with the operating system error 2(The system cannot find the file specified.). Msg 1802, Level 16, State 1, Line 1 CREATE DATABASE failed. Some file names listed could not be created. Check related errors. But the directories exist and I can write to them. One step forward two steps back...the only thing I can figure is there is more security on PoSH getting in the way of doing the kind of simple scripting I want to do. Is it ME? Is this simple activity not what PoSH is designed to do? -- Matthew McDermott, MVP Principal Consultant Catapult Systems, Inc. "Shay Levi" wrote: > Hi Matthew, > > > I can't see any reason why this won't work: > > $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" > & $sqlExec -S MOSS1 -i DB_Create_Script.txt > > > > > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > > MM> Thanks for the reply. > MM> > MM> Let me add a better example: > MM> > MM> The applications and command line params will change, so I made them > MM> variables: > MM> > MM> $sqlExec = "C:\Program Files\Microsoft SQL > MM> Server\90\Tools\Binn\sqlcmd.exe" $execSql = "`"$sqlExec`" -S MOSS1 > MM> -i DB_Create_Script.txt" > MM> > MM> I need the double quotes (I think) so that the line will work. > MM> > MM> Then I am trying to execute $execSql: > MM> > MM> Invoke-Expression -Command $execSql > MM> > MM> And I get the following: > MM> > MM> The term '"C:\Program Files\Microsoft SQL > MM> Server\90\Tools\Binn\sqlcmd.exe" > MM> -S MOSS1 -i DB_Create_Script.txt' is not rognized as a cmdlet, > MM> function, > MM> operable program, or script file. Verify the term and try again. > MM> At C:\PoSH\farmbuild.ps1:31 char:2 > MM> + & <<<< $execSql | Out-Null > MM> Does that help? > MM> > MM> I am really struggling... > MM> > MM> "Shay Levi" wrote: > MM> > >> Hi Matthew, > >> > >> Try with the call operator (ampersand): > >> > >> & <pathToApplication>\application.exe /foo bar > >> > >> If you need the command to wait for completion before moving to the > >> next line of code then pipe it to out-null: > >> > >> & <pathToApplication>\application.exe /foo bar | out-null > >> > >> PowerShell also has a DOS %ErrorLevel% equivalent, check this post > >> for more information: > >> > >> http://blogs.msdn.com/powershell/arc...orLevel-equiva > >> lent.aspx > >> > >> Hope this helps > >> > >> --- > >> Shay Levi > >> $cript Fanatic > >> http://scriptolog.blogspot.com > >>> All, > >>> > >>> I am really sorry, but I am obviously missing something REALLY basic > >>> here. > >>> > >>> I am trying to create a scripted installaiton for an application > >>> that has a lot of dependancies and moving parts. I have been > >>> successful using CMD but PoSH is the future so I figured this would > >>> be a good way to learn it. The script has to call an installation > >>> with parameters, then call SQL with parameters...etc. > >>> > >>> I need to call several external applications from my PoSH script. It > >>> does not work! > >>> > >>> In CMD I might call: > >>> > >>> %installdir% application.exe /foo bar > >>> > >>> How the heck do you do that in PowerShell? (And don't get me started > >>> about having spaces in the directory names!!! )> >>> > >>> I have tried various versions of Invoke-Expression but that crashes > >>> when I use command line parameters. > >>> > >>> I understand that PoSH has amazing abilites, but this seemingly > >>> simple task has me stumped! > >>> > >>> Can anyone point me in the right direction? Even just an example > >>> that WORKS! > >>> > >>> Thanks in advance! > >>> > > > |
|
|
|
#9 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Hi Matthew,
Can you post a sample DB_Create_Script.txt, I'd like to test it. --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com MM> Shay, MM> MM> I don't understand either, but as I said I have to run it as params MM> in variables so my expression is: MM> MM> $sqlExec = "C:\Program Files\Microsoft SQL MM> Server\90\Tools\Binn\sqlcmd.exe" MM> $sqlParams = "-S MOSS1 -i DB_Create_Script.txt" MM> & $sqlExec $sqlParams MM> And sqlcmd returns a parameter error. If I run it your way it MM> works...BUT the command fails because the sqlcmd process cannot MM> "SEE" the directories I created from PoSH. MM> MM> I simply execute a mkdir and create the data and log locations. When MM> I do this manually (or via CMD) the databases are created in the MM> directories, but when I use PoSH to create the directories I get: MM> MM> Directory lookup for the file "c:\MSSQL\Log\SharePoint_Config.ldf" MM> failed MM> with the operating system error 2(The system cannot find the file MM> specified.). MM> Msg 1802, Level 16, State 1, Line 1 MM> CREATE DATABASE failed. Some file names listed could not be created. MM> Check MM> related errors. MM> But the directories exist and I can write to them. MM> MM> One step forward two steps back...the only thing I can figure is MM> there is more security on PoSH getting in the way of doing the kind MM> of simple scripting I want to do. MM> MM> Is it ME? Is this simple activity not what PoSH is designed to do? MM> MM> "Shay Levi" wrote: MM> >> Hi Matthew, >> >> I can't see any reason why this won't work: >> >> $sqlExec = "C:\Program Files\Microsoft SQL >> Server\90\Tools\Binn\sqlcmd.exe" & $sqlExec -S MOSS1 -i >> DB_Create_Script.txt >> >> --- >> Shay Levi >> $cript Fanatic >> http://scriptolog.blogspot.com >> MM> Thanks for the reply. >> MM> >> MM> Let me add a better example: >> MM> >> MM> The applications and command line params will change, so I made >> them >> MM> variables: >> MM> >> MM> $sqlExec = "C:\Program Files\Microsoft SQL >> MM> Server\90\Tools\Binn\sqlcmd.exe" $execSql = "`"$sqlExec`" -S >> MOSS1 >> MM> -i DB_Create_Script.txt" >> MM> >> MM> I need the double quotes (I think) so that the line will work. >> MM> >> MM> Then I am trying to execute $execSql: >> MM> >> MM> Invoke-Expression -Command $execSql >> MM> >> MM> And I get the following: >> MM> >> MM> The term '"C:\Program Files\Microsoft SQL >> MM> Server\90\Tools\Binn\sqlcmd.exe" >> MM> -S MOSS1 -i DB_Create_Script.txt' is not rognized as a cmdlet, >> MM> function, >> MM> operable program, or script file. Verify the term and try again. >> MM> At C:\PoSH\farmbuild.ps1:31 char:2 >> MM> + & <<<< $execSql | Out-Null >> MM> Does that help? >> MM> >> MM> I am really struggling... >> MM> >> MM> "Shay Levi" wrote: >> MM> >>>> Hi Matthew, >>>> >>>> Try with the call operator (ampersand): >>>> >>>> & <pathToApplication>\application.exe /foo bar >>>> >>>> If you need the command to wait for completion before moving to the >>>> next line of code then pipe it to out-null: >>>> >>>> & <pathToApplication>\application.exe /foo bar | out-null >>>> >>>> PowerShell also has a DOS %ErrorLevel% equivalent, check this post >>>> for more information: >>>> >>>> http://blogs.msdn.com/powershell/arc...rrorLevel-equi >>>> va lent.aspx >>>> >>>> Hope this helps >>>> >>>> --- >>>> Shay Levi >>>> $cript Fanatic >>>> http://scriptolog.blogspot.com >>>>> All, >>>>> >>>>> I am really sorry, but I am obviously missing something REALLY >>>>> basic here. >>>>> >>>>> I am trying to create a scripted installaiton for an application >>>>> that has a lot of dependancies and moving parts. I have been >>>>> successful using CMD but PoSH is the future so I figured this >>>>> would be a good way to learn it. The script has to call an >>>>> installation with parameters, then call SQL with parameters...etc. >>>>> >>>>> I need to call several external applications from my PoSH script. >>>>> It does not work! >>>>> >>>>> In CMD I might call: >>>>> >>>>> %installdir% application.exe /foo bar >>>>> >>>>> How the heck do you do that in PowerShell? (And don't get me >>>>> started about having spaces in the directory names!!! )>>>>> >>>>> I have tried various versions of Invoke-Expression but that >>>>> crashes when I use command line parameters. >>>>> >>>>> I understand that PoSH has amazing abilites, but this seemingly >>>>> simple task has me stumped! >>>>> >>>>> Can anyone point me in the right direction? Even just an example >>>>> that WORKS! >>>>> >>>>> Thanks in advance! >>>>> |
|
|
|
#10 |
|
Guest
Posts: n/a
|
Re: Scripted Installation with PowerShell
Here's the script:
CREATE DATABASE DB_Config ON ( NAME = DB_Config_data, FILENAME = 'c:\MSSQL\Data\DB_Config.mdf' ) LOG ON ( NAME = DB_Config_log, FILENAME = 'c:\MSSQL\Log\DB_Config.ldf' ) COLLATE Latin1_General_CI_AS_KS_WS I am doing a mkdir like this in PoSH: $sqlroot = "\\MOSS1\c$\mssql\" $sqldata = "\data" $sqllog = "\log" $datapath = Join-Path -path $sqlroot $sqldata $logpath = Join-Path -path $sqlroot $sqllog mkdir $sqlroot mkdir $datapath mkdir $logpath Thanks Again for the help. -- Matthew McDermott, MVP Principal Consultant Catapult Systems, Inc. "Shay Levi" wrote: > Hi Matthew, > > Can you post a sample DB_Create_Script.txt, I'd like to test it. > > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > > MM> Shay, > MM> > MM> I don't understand either, but as I said I have to run it as params > MM> in variables so my expression is: > MM> > MM> $sqlExec = "C:\Program Files\Microsoft SQL > MM> Server\90\Tools\Binn\sqlcmd.exe" > MM> $sqlParams = "-S MOSS1 -i DB_Create_Script.txt" > MM> & $sqlExec $sqlParams > MM> And sqlcmd returns a parameter error. If I run it your way it > MM> works...BUT the command fails because the sqlcmd process cannot > MM> "SEE" the directories I created from PoSH. > MM> > MM> I simply execute a mkdir and create the data and log locations. When > MM> I do this manually (or via CMD) the databases are created in the > MM> directories, but when I use PoSH to create the directories I get: > MM> > MM> Directory lookup for the file "c:\MSSQL\Log\SharePoint_Config.ldf" > MM> failed > MM> with the operating system error 2(The system cannot find the file > MM> specified.). > MM> Msg 1802, Level 16, State 1, Line 1 > MM> CREATE DATABASE failed. Some file names listed could not be created. > MM> Check > MM> related errors. > MM> But the directories exist and I can write to them. > MM> > MM> One step forward two steps back...the only thing I can figure is > MM> there is more security on PoSH getting in the way of doing the kind > MM> of simple scripting I want to do. > MM> > MM> Is it ME? Is this simple activity not what PoSH is designed to do? > MM> > MM> "Shay Levi" wrote: > MM> > >> Hi Matthew, > >> > >> I can't see any reason why this won't work: > >> > >> $sqlExec = "C:\Program Files\Microsoft SQL > >> Server\90\Tools\Binn\sqlcmd.exe" & $sqlExec -S MOSS1 -i > >> DB_Create_Script.txt > >> > >> --- > >> Shay Levi > >> $cript Fanatic > >> http://scriptolog.blogspot.com > >> MM> Thanks for the reply. > >> MM> > >> MM> Let me add a better example: > >> MM> > >> MM> The applications and command line params will change, so I made > >> them > >> MM> variables: > >> MM> > >> MM> $sqlExec = "C:\Program Files\Microsoft SQL > >> MM> Server\90\Tools\Binn\sqlcmd.exe" $execSql = "`"$sqlExec`" -S > >> MOSS1 > >> MM> -i DB_Create_Script.txt" > >> MM> > >> MM> I need the double quotes (I think) so that the line will work. > >> MM> > >> MM> Then I am trying to execute $execSql: > >> MM> > >> MM> Invoke-Expression -Command $execSql > >> MM> > >> MM> And I get the following: > >> MM> > >> MM> The term '"C:\Program Files\Microsoft SQL > >> MM> Server\90\Tools\Binn\sqlcmd.exe" > >> MM> -S MOSS1 -i DB_Create_Script.txt' is not rognized as a cmdlet, > >> MM> function, > >> MM> operable program, or script file. Verify the term and try again. > >> MM> At C:\PoSH\farmbuild.ps1:31 char:2 > >> MM> + & <<<< $execSql | Out-Null > >> MM> Does that help? > >> MM> > >> MM> I am really struggling... > >> MM> > >> MM> "Shay Levi" wrote: > >> MM> > >>>> Hi Matthew, > >>>> > >>>> Try with the call operator (ampersand): > >>>> > >>>> & <pathToApplication>\application.exe /foo bar > >>>> > >>>> If you need the command to wait for completion before moving to the > >>>> next line of code then pipe it to out-null: > >>>> > >>>> & <pathToApplication>\application.exe /foo bar | out-null > >>>> > >>>> PowerShell also has a DOS %ErrorLevel% equivalent, check this post > >>>> for more information: > >>>> > >>>> http://blogs.msdn.com/powershell/arc...rrorLevel-equi > >>>> va lent.aspx > >>>> > >>>> Hope this helps > >>>> > >>>> --- > >>>> Shay Levi > >>>> $cript Fanatic > >>>> http://scriptolog.blogspot.com > >>>>> All, > >>>>> > >>>>> I am really sorry, but I am obviously missing something REALLY > >>>>> basic here. > >>>>> > >>>>> I am trying to create a scripted installaiton for an application > >>>>> that has a lot of dependancies and moving parts. I have been > >>>>> successful using CMD but PoSH is the future so I figured this > >>>>> would be a good way to learn it. The script has to call an > >>>>> installation with parameters, then call SQL with parameters...etc. > >>>>> > >>>>> I need to call several external applications from my PoSH script. > >>>>> It does not work! > >>>>> > >>>>> In CMD I might call: > >>>>> > >>>>> %installdir% application.exe /foo bar > >>>>> > >>>>> How the heck do you do that in PowerShell? (And don't get me > >>>>> started about having spaces in the directory names!!! )> >>>>> > >>>>> I have tried various versions of Invoke-Expression but that > >>>>> crashes when I use command line parameters. > >>>>> > >>>>> I understand that PoSH has amazing abilites, but this seemingly > >>>>> simple task has me stumped! > >>>>> > >>>>> Can anyone point me in the right direction? Even just an example > >>>>> that WORKS! > >>>>> > >>>>> Thanks in advance! > >>>>> > > > |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|