Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Questions of Powershell script

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 08-01-2007   #1 (permalink)
dh
Guest


 

Questions of Powershell script

I just trying to write up a simple Powershell script quickly. Here're some
basic questions:

1. A powershell commands can be saved in a .vbs file and run it in windows
console using: cscript xyz.vbs?

2. For comment in Powershell script, add ",' in front of commands?

3. In the vbs file when adding commands like:

Wscript.echo "learning powershell..."
or
write-host "learning Powershell..."

In both cases, it gave error: "VbScript compilation error: Expected end of
statement"

What's wrong here?

4. This command will not work:

Copy-Item testfile.txt c:\PS Test Folder

But will this fixes it?

$dir = "c:\PS Test Folder"
Copy-Item testfile.txt $dir

5. How to start a batch file from within the vbs file?

Thanks!


My System SpecsSystem Spec
Old 08-01-2007   #2 (permalink)
dreeschkind
Guest


 

RE: Questions of Powershell script

"dh" wrote:

> I just trying to write up a simple Powershell script quickly. Here're some
> basic questions:
>
> 1. A powershell commands can be saved in a .vbs file and run it in windows
> console using: cscript xyz.vbs?


no you need to save the script as a .ps1 file and use powershell.exe

> 2. For comment in Powershell script, add ",' in front of commands?


# this is a comment

> 3. In the vbs file when adding commands like:
>
> Wscript.echo "learning powershell..."
> or
> write-host "learning Powershell..."
>
> In both cases, it gave error: "VbScript compilation error: Expected end of
> statement"
>
> What's wrong here?


you're not using powershell.exe

> 4. This command will not work:
>
> Copy-Item testfile.txt c:\PS Test Folder
>
> But will this fixes it?


Copy-Item testfile.txt 'c:\PS Test Folder\'

should work

> $dir = "c:\PS Test Folder"
> Copy-Item testfile.txt $dir
>
> 5. How to start a batch file from within the vbs file?


& "C:\script\script.ps1"

--
greetings
dreeschkind
My System SpecsSystem Spec
Old 08-01-2007   #3 (permalink)
dh
Guest


 

RE: Questions of Powershell script

"dreeschkind" wrote:

> "dh" wrote:
>
> > I just trying to write up a simple Powershell script quickly. Here're some
> > basic questions:
> >
> > 1. A powershell commands can be saved in a .vbs file and run it in windows
> > console using: cscript xyz.vbs?

>
> no you need to save the script as a .ps1 file and use powershell.exe
>


Thanks for your quick answering!

Is commandline in console: powershell.exe xyz.ps1?

> > 3. In the vbs file when adding commands like:
> >
> > Wscript.echo "learning powershell..."
> > or
> > write-host "learning Powershell..."
> >
> > In both cases, it gave error: "VbScript compilation error: Expected end of
> > statement"
> >
> > What's wrong here?

>
> you're not using powershell.exe
>


I just did a quick test and here's the error I got:

C:\pstest>powershell update.psl
The term 'xyz.ps1' is not recognized as a cmdlet, function, operable program
, or script file. Verify the term and try again.
At line:1 char:10
+ xyz.ps1 <<<<


> > 5. How to start a batch file from within the vbs file?

>
> & "C:\script\script.ps1"
>


Then the question is how to start a batch file, like "abc.bat" from within
xyz.ps1 file?
My System SpecsSystem Spec
Old 08-01-2007   #4 (permalink)
dh
Guest


 

RE: Questions of Powershell script

Just figured this one out...

The commandline must be powershell.exe c:\pstest\xyz.ps1, not
"powershell.exe xyz.ps1."
My System SpecsSystem Spec
Old 08-01-2007   #5 (permalink)
IT Staff
Guest


 

Re: Questions of Powershell script

or powershell.exe .\filename.ps1 in same directory


"dh" <dh@discussions.microsoft.com> wrote in message
news:F658F392-A863-4BBC-A31A-9C57EC932E2E@microsoft.com...
> Just figured this one out...
>
> The commandline must be powershell.exe c:\pstest\xyz.ps1, not
> "powershell.exe xyz.ps1."



My System SpecsSystem Spec
Old 08-02-2007   #6 (permalink)
dreeschkind
Guest


 

RE: Questions of Powershell script

"dh" wrote:


> Is commandline in console: powershell.exe xyz.ps1?


to see all command line options run

powershell.exe -?

> > > 5. How to start a batch file from within the vbs file?

> >
> > & "C:\script\script.ps1"
> >

>
> Then the question is how to start a batch file, like "abc.bat" from within
> xyz.ps1 file?


Sorry, this was a typo. You can start batch files and other programs
directly from powershell console and powershell scripts:

& "C:\script\batch.bat"
& "C:\script\commands.cmd"
& "C:\script\app.exe"

etc.

--
greetings
dreeschkind
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions on PowerShell SD PowerShell 9 06-11-2008 12:45 PM
when run powershell script as windows service ,powershell fail powershell fail on winodws 2008 PowerShell 6 01-15-2008 03:20 PM
Some powershell questions... mpriem PowerShell 4 04-02-2007 01:04 PM
Remote powershell - questions Did PowerShell 5 02-26-2007 09:27 AM
3 questions (Re: Vista RTM + PowerShell) Jon Davis PowerShell 5 11-26-2006 06:50 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51