Call powershell script via Batch-File

powershell

    Next

  • 1. call powershell from ASP
    can someone post an example or point me to one where I can write an ASP page that calls powershell commands and displays results of a query like "get-disks"? thanks.
  • 2. When non-ASCII creeps into script
    What to do, what to do... When non-ASCII characters creep into a script, what's the best way to see them and remove them? Without re-typing the whole text. Grasping at straws doesn't seem to work: gc psa1.ps1|out-file -encoding ascii psa2.ps1
  • 3. powershell trimming extensions internally
    Hi All, I've encountered a really strange behavior of powershell. I use a small utility that executes scripts written in C#, and is associated with the .csscript extension. The .csscript is also appended to the PATHEXT environment variable. In CMD.EXE, everything works as expected, and when I type for example backup-db ..., the backup-db.csscript is executed and everything is fine. In powershell, when I type backup-db, it locates the script properly (PATHEXT is used, same as in CMD.EXE), but it doesn't use the registered application to execute the script, but instead opens the script in InterDev. I was really shocked by this behavior, until I found out (through ProcessMonitor), that powershell doesn't look for the .csscript extension, but for .css instead! I've this with other extensions, and the result is always the same - only first three characters of the extension are used. (e.g I've tried renaming a .xml file to .xmlblahblahblah, and typing filename.xmlblahblahblah opens it like an .xml file) I think that limiting extensions to 3 characters smells like good-old 8.3 times, doesn't it? I like powershell, but this is not something I would expect of a modern shell. Looking forward to any comments on this ;) Stefan
  • 4. Get-Date needs a -Millisecond parameter
    Get-Date needs a -Millisecond parameter. Either that or it should zero out the milliseconds. This is an example of the problem I ran into. # -------------------------------------------------------------- # 9:00 PM $dt1 = Get-Date "9:00 PM" # milliseconds are 0 # 9:00 PM $dt2 = Get-Date -Hour "21" -Minute "00" -Second "00" # milliseconds are current milliseconds $dt1 $dt2 "" if( $dt1 -eq $dt2 ) { "equal" } else { "not equal" } "" '$dt1 = ' + $dt1.Ticks '$dt2 = ' + $dt2.Ticks $dt2 - $dt1 # -------------------------------------------------------------- I was able to work around it by using New-Object and the DateTime constructor that includes milliseconds. But I shouldn't have had to do that. Get-Date should be able to handle it.

Call powershell script via Batch-File

Postby kr1999 » Wed, 04 Jul 2007 00:28:11 GMT

Hi everyone,

i wrote a script to sign my powershell scripts. When I call the sign
script with a file to sign any file, the script works fine. But when I
create a batch file to call the powershell script with a file to sign,
I get the error message that no file name was given.

Batch-File:
.\SignFile.ps1 %1%

SignFile.ps1:
Param
	(
		[string] $File
	)
$str = "Filename: " + $File
Write-Output $str
...

How have I to call the powershell script within my batch file to work
as I expect?

Thanks for the help,
Reiner


Re: Call powershell script via Batch-File

Postby Brandon Shell » Wed, 04 Jul 2007 00:37:02 GMT

Two things

1) you have to put powershell in front of the PS script name
powershell c:\pathtoscript\SingFile.ps1

2) you dont need trailing % on  %1%







Re: Call powershell script via Batch-File

Postby kr1999 » Wed, 04 Jul 2007 00:50:01 GMT





Hello Brandon,

thanks for your help. It works as I expected.

Reiner


Similar Threads:

1.Powershell Wrapper Script Problems - Trying to Call Powershell Exchange 2007 Commands from Secondary Language (Like VBScript)

2.Running batch file from Powershell script

Hi,

Can anyone tell me how to run a batch file from a Powershell script? Will 
appreciate a sample code.

Thanks in advance,
Varun 


3.Invoke PowerShell Script from Batch File

Richard just helped me write a PowerShell script to enable/disable a net 
adapter.  Now I want to run the script from a batch file.  I tried this:

PowerShell -file  EnableAdapter.ps1

with no luck.  EnableAdapter.ps1 is in my path.  It works if I run it from a 
PS prompt:

& EnableAdapter.ps1.

It also works if I use the noexit option:

PowerShell -noexit -file  EnableAdapter.ps1

Is it timing out or something?  How can I get the first one to work?

Fred 


4.Running batch file from Powershell script

Hi,

Can anyone tell me how to run a batch file from a Powershell script? Will 
appreciate a sample code.

Thanks in advance,
Varun 


5.calling multiple batch files from within a batch file

I have two batch files - hello.cmd and hello2.cmd.

Here's the contents of hello.cmd:

@echo hello, world!

Here's the contents of hello2.cmd:

@hello
@hello

Why is "hello, world!" only output once?

6. Newbie - Call batch file from a logon script

7. login script to call a batch file

8. Need to call batch file from VB Script



Return to powershell

 

Who is online

Users browsing this forum: No registered users and 72 guest