TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

Scripted Installation with PowerShell

Microsoft Windows Powershell


Reply
 
Thread Tools Display Modes
Old 26-06-2008, 04:23 PM   #11
Leo Tohill
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

I can't see any reason why a directory created from PS would be any different
from one created from CMD.

Is the SqlServer instance you are connecting to on the same machine? If
not, then of course it wouldn't be able to access the C: drive on the PS
machine.

If you let this script create the folders and then fail, and then go to a
cmd prompt (same default folder) and execute the sqlcmd in exactly the way
that PS did, does it work?



- Leo

"Matthew McDermott" wrote:

> 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
> >
> >
> > 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:
> > >>
> > >>
> > >> lent.aspx
> > >>
> > >> Hope this helps
> > >>
> > >> ---
> > >> Shay Levi
> > >> $cript Fanatic
> > >>
> > >>> 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!
> > >>>

> >
> >
> >

  Reply With Quote
Old 26-06-2008, 04:23 PM   #12
Shay Levi
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Hi Matthew,



1. Created the DB_Create_Script.txt file on the server:

### C:\DB_Create_Script.txt ###

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

#######################



2. Launched powershell and started recording the session using start-transcript (no errors):


**********************
Windows PowerShell Transcript Start
Start time: 20080623165057
Username : DOMAIN\administrator
Machine : MYSERVER (Microsoft Windows NT 5.2.3790 Service Pack 2)
**********************
Transcript started, output file is c:\sql.txt

PS C:\> $server = "myServer"
PS C:\> $sqlroot = "\\$server\c$\mssql\"
PS C:\> $sqldata = "\data"
PS C:\> $sqllog = "\log"
PS C:\>
PS C:\> $datapath = Join-Path -path $sqlroot $sqldata
PS C:\> $logpath = Join-Path -path $sqlroot $sqllog
PS C:\>
PS C:\> mkdir $sqlroot


Directory: Microsoft.PowerShell.Core\FileSystem::\\myServer\c $


Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 23/06/2008 16:51 mssql


PS C:\> mkdir $datapath


Directory: Microsoft.PowerShell.Core\FileSystem::\\myServer\c $\mssql


Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 23/06/2008 16:51 data


PS C:\> mkdir $logpath


Directory: Microsoft.PowerShell.Core\FileSystem::\\myServer\c $\mssql


Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 23/06/2008 16:51 log


PS C:\> $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe"
PS C:\> & $sqlExec -S $server -i c:\DB_Create_Script.txt
PS C:\>
PS C:\>



3. Launched 'SQL Server Management Studio' to verify that db_config was created (see attached image).




---
Shay Levi
$cript Fanatic


MM> Here's the script:
MM>
MM> CREATE DATABASE DB_Config
MM> ON
MM> (
MM> NAME = DB_Config_data,
MM> FILENAME = 'c:\MSSQL\Data\DB_Config.mdf'
MM> )
MM> LOG ON
MM> (
MM> NAME = DB_Config_log,
MM> FILENAME = 'c:\MSSQL\Log\DB_Config.ldf'
MM> )
MM> COLLATE Latin1_General_CI_AS_KS_WS
MM>
MM> I am doing a mkdir like this in PoSH:
MM> $sqlroot = "\\MOSS1\c$\mssql\"
MM> $sqldata = "\data"
MM> $sqllog = "\log"
MM> $datapath = Join-Path -path $sqlroot $sqldata
MM> $logpath = Join-Path -path $sqlroot $sqllog
MM> mkdir $sqlroot
MM> mkdir $datapath
MM> mkdir $logpath
MM> Thanks Again for the help.
MM>
MM> "Shay Levi" wrote:
MM>
>> Hi Matthew,
>>
>> Can you post a sample DB_Create_Script.txt, I'd like to test it.
>>
>> ---
>> Shay Levi
>> $cript Fanatic
>>
>> 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
>>>>
>>>> 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:
>>>>>>
>>>>>>
>>>>>> ui va lent.aspx
>>>>>>
>>>>>> Hope this helps
>>>>>>
>>>>>> ---
>>>>>> Shay Levi
>>>>>> $cript Fanatic
>>>>>>
>>>>>>> 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!
>>>>>>>


  Reply With Quote
Old 26-06-2008, 04:23 PM   #13
Matthew McDermott
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Shay,

So it worked for you without error?

Is there some permission that I am missing? I am not clear on how to
proceed...

M
--
Matthew McDermott, MVP
Principal Consultant
Catapult Systems, Inc.


"Shay Levi" wrote:

> Hi Matthew,
>
>
>
> 1. Created the DB_Create_Script.txt file on the server:
>
> ### C:\DB_Create_Script.txt ###
>
> 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
>
> #######################
>
>
>
> 2. Launched powershell and started recording the session using start-transcript (no errors):
>
>
> **********************
> Windows PowerShell Transcript Start
> Start time: 20080623165057
> Username : DOMAIN\administrator
> Machine : MYSERVER (Microsoft Windows NT 5.2.3790 Service Pack 2)
> **********************
> Transcript started, output file is c:\sql.txt
>
> PS C:\> $server = "myServer"
> PS C:\> $sqlroot = "\\$server\c$\mssql\"
> PS C:\> $sqldata = "\data"
> PS C:\> $sqllog = "\log"
> PS C:\>
> PS C:\> $datapath = Join-Path -path $sqlroot $sqldata
> PS C:\> $logpath = Join-Path -path $sqlroot $sqllog
> PS C:\>
> PS C:\> mkdir $sqlroot
>
>
> Directory: Microsoft.PowerShell.Core\FileSystem::\\myServer\c $
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> d---- 23/06/2008 16:51 mssql
>
>
> PS C:\> mkdir $datapath
>
>
> Directory: Microsoft.PowerShell.Core\FileSystem::\\myServer\c $\mssql
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> d---- 23/06/2008 16:51 data
>
>
> PS C:\> mkdir $logpath
>
>
> Directory: Microsoft.PowerShell.Core\FileSystem::\\myServer\c $\mssql
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> d---- 23/06/2008 16:51 log
>
>
> PS C:\> $sqlExec = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe"
> PS C:\> & $sqlExec -S $server -i c:\DB_Create_Script.txt
> PS C:\>
> PS C:\>
>
>
>
> 3. Launched 'SQL Server Management Studio' to verify that db_config was created (see attached image).
>
>
>
>
> ---
> Shay Levi
> $cript Fanatic
>
>
> MM> Here's the script:
> MM>
> MM> CREATE DATABASE DB_Config
> MM> ON
> MM> (
> MM> NAME = DB_Config_data,
> MM> FILENAME = 'c:\MSSQL\Data\DB_Config.mdf'
> MM> )
> MM> LOG ON
> MM> (
> MM> NAME = DB_Config_log,
> MM> FILENAME = 'c:\MSSQL\Log\DB_Config.ldf'
> MM> )
> MM> COLLATE Latin1_General_CI_AS_KS_WS
> MM>
> MM> I am doing a mkdir like this in PoSH:
> MM> $sqlroot = "\\MOSS1\c$\mssql\"
> MM> $sqldata = "\data"
> MM> $sqllog = "\log"
> MM> $datapath = Join-Path -path $sqlroot $sqldata
> MM> $logpath = Join-Path -path $sqlroot $sqllog
> MM> mkdir $sqlroot
> MM> mkdir $datapath
> MM> mkdir $logpath
> MM> Thanks Again for the help.
> MM>
> MM> "Shay Levi" wrote:
> MM>
> >> Hi Matthew,
> >>
> >> Can you post a sample DB_Create_Script.txt, I'd like to test it.
> >>
> >> ---
> >> Shay Levi
> >> $cript Fanatic
> >>
> >> 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
> >>>>
> >>>> 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:
> >>>>>>
> >>>>>>
> >>>>>> ui va lent.aspx
> >>>>>>
> >>>>>> Hope this helps
> >>>>>>
> >>>>>> ---
> >>>>>> Shay Levi
> >>>>>> $cript Fanatic
> >>>>>>
> >>>>>>> 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!
> >>>>>>>

>

  Reply With Quote
Old 26-06-2008, 04:24 PM   #14
Matthew McDermott
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Thanks Leo,

No, all on one box right now. (Trying to keep it simple.)

Looks like Shay got it to work, but I do not see what is different.

M

--
Matthew McDermott, MVP
Principal Consultant
Catapult Systems, Inc.


"Leo Tohill" wrote:

> I can't see any reason why a directory created from PS would be any different
> from one created from CMD.
>
> Is the SqlServer instance you are connecting to on the same machine? If
> not, then of course it wouldn't be able to access the C: drive on the PS
> machine.
>
> If you let this script create the folders and then fail, and then go to a
> cmd prompt (same default folder) and execute the sqlcmd in exactly the way
> that PS did, does it work?
>
>
>
> - Leo
>
> "Matthew McDermott" wrote:
>
> > 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
> > >
> > >
> > > 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:
> > > >>
> > > >>
> > > >> lent.aspx
> > > >>
> > > >> Hope this helps
> > > >>
> > > >> ---
> > > >> Shay Levi
> > > >> $cript Fanatic
> > > >>
> > > >>> 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!
> > > >>>
> > >
> > >
> > >

  Reply With Quote
Old 26-06-2008, 04:24 PM   #15
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Matthew McDermott wrote:
> Shay,
>
> So it worked for you without error?
>
> Is there some permission that I am missing? I am not clear on how to
> proceed...


So version check ya'll...

PowerShell's handling of DOS commands was planned to slightly change in
v2.

I couldn't tell you if anything has been changed as of CTP2 though.

Marco


--
Microsoft MVP - Windows PowerShell


PowerGadgets MVP


Blog:

  Reply With Quote
Old 26-06-2008, 04:24 PM   #16
Matthew McDermott
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Version 1. Should I be using Version 2?
--
Matthew McDermott, MVP
Principal Consultant
Catapult Systems, Inc.


"Marco Shaw [MVP]" wrote:

> Matthew McDermott wrote:
> > Shay,
> >
> > So it worked for you without error?
> >
> > Is there some permission that I am missing? I am not clear on how to
> > proceed...

>
> So version check ya'll...
>
> PowerShell's handling of DOS commands was planned to slightly change in
> v2.
>
> I couldn't tell you if anything has been changed as of CTP2 though.
>
> Marco
>
>
> --
> Microsoft MVP - Windows PowerShell
>
>
> PowerGadgets MVP
>
>
> Blog:
>
>

  Reply With Quote
Old 26-06-2008, 04:24 PM   #17
Matthew McDermott
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

I am using version 1. Should I be using version 2?
--
Matthew McDermott, MVP
Principal Consultant
Catapult Systems, Inc.


"Marco Shaw [MVP]" wrote:

> Matthew McDermott wrote:
> > Shay,
> >
> > So it worked for you without error?
> >
> > Is there some permission that I am missing? I am not clear on how to
> > proceed...

>
> So version check ya'll...
>
> PowerShell's handling of DOS commands was planned to slightly change in
> v2.
>
> I couldn't tell you if anything has been changed as of CTP2 though.
>
> Marco
>
>
> --
> Microsoft MVP - Windows PowerShell
>
>
> PowerGadgets MVP
>
>
> Blog:
>
>

  Reply With Quote
Old 26-06-2008, 04:24 PM   #18
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Matthew McDermott wrote:
> Version 1. Should I be using Version 2?


v2 CTP/CTP2 is for use in non-production environments only...

I just want to try to explain why Shay's works, and yours doesn't. I
have the v2 CTP2, but haven't tried what Shay suggested.

Marco
  Reply With Quote
Old 26-06-2008, 04:25 PM   #19
Matthew McDermott
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell

Marco,

This is a virtual environment so no problem. I'll test it with V2 tonight.
--
Matthew McDermott, MVP
Principal Consultant
Catapult Systems, Inc.


"Marco Shaw [MVP]" wrote:

> Matthew McDermott wrote:
> > Version 1. Should I be using Version 2?

>
> v2 CTP/CTP2 is for use in non-production environments only...
>
> I just want to try to explain why Shay's works, and yours doesn't. I
> have the v2 CTP2, but haven't tried what Shay suggested.
>
> Marco
>

  Reply With Quote
Old 26-06-2008, 04:25 PM   #20
Shay Levi
Guest
 
Posts: n/a
Re: Scripted Installation with PowerShell


Matthew ,

I used v1. Just for the testings, can you run the same commands I executed
and see if any errors arise?
Are you running sqlcmd against a remote server or from a local context?


---
Shay Levi
$cript Fanatic


> I am using version 1. Should I be using version 2?
>
> "Marco Shaw [MVP]" wrote:
>
>> Matthew McDermott wrote:
>>
>>> Shay,
>>>
>>> So it worked for you without error?
>>>
>>> Is there some permission that I am missing? I am not clear on how to
>>> proceed...
>>>

>> So version check ya'll...
>>
>> PowerShell's handling of DOS commands was planned to slightly change
>> in v2.
>>
>> I couldn't tell you if anything has been changed as of CTP2 though.
>>
>> Marco
>>
>> --
>> Microsoft MVP - Windows PowerShell
>>
>> PowerGadgets MVP
>>
>> Blog:
>>



  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 06:14 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional