powershell

powershell character problem

Hi, I am running the following command. ([xml](new-object net.webclient).DownloadString( "http://blogs.msdn.com/powershell/rss.aspx" )).rss.channel.item | format-table title,link The answer shows me that one rss items has the text "You Don’t Have to Be An Administrator to Run Remote PowerShell Commands" So, the question is; why the...

Terminating a script in Powershell

I've been looking for a way to terminate a Powershell (PS1) script when an unrecoverable error occurs within a function. For example: function foo() { # Do stuff that causes an error $host.Exit() } Of course there's no such thing as $host.Exit(). There is $host.SetShouldExit() but this actually closes the console window, which...

How to access a chipcard from powershell?

I'd like to send a chipcard command (an APDU) to a chipcard and read the response from the chipcard. Because there should be no extra install on the windows system, I'd like to do it within windows powershell. Is there an easy way to do this? ...

How to access a web service from powershell?

I'd like to access a web service with a given (simple) WSDL from within windows powershell. Is there an easy way to do this? ...

What is the recommended coding style for PowerShell?

Is there any recommended coding style how to write PowerShell scripts? It's not about how to structure the code (how many functions, if to use module, ...). It's about 'how to write the code so that it is readable'. In programming languages there are some recommended coding styles (what to indent, how to indent - spaces/tabs, where to ...

Powershell and overriden comparision operators

How can one create an object that when its operators, such as: operator > (Object obj1, Object obj2) operator < (Object obj1, Object obj2) , are overridden PowerShell utilizes these operators? Such that: where-object { $CustomObject -gt 12 } would call: public static bool operator > (Object object1, Object object2) Is it pos...

How to run a PowerShell script?

Guys and Gals, a really stupid question: How do I run a PowerShell script? I have a script named myscript.ps1 I have all the necessary frameworks installed I set that execution policy thing I have followed the instructions on this MSDN help page and am trying to run it like so: powershell.exe 'C:\my_path\yada_yada\run_import_script.ps...

How to output something in PowerShell

I am running a PowerShell script from within a batch file. The script fetches a web page and checks whether the page's content is the string "OK". The PowerShell script returns an error level to the batch script. The batch script is executed by ScriptFTP, an FTP automation program. If an error occurs, I can have ScriptFTP send the full...

Powershell script gets stuck, doesn't exit when called from batch file

I have a PowerShell script that connects to a web site, and parses its returned data (It's about importing a previously uploaded SQL file into the web site's data base). The PowerShell script uses wget, something I may replace by a native function later. The import process is embedded in a script that is executed by a 3rd party program ...

Powershell script: Can't read return value of executed program

I am using PowerShell to run a script that executes wget to fetch a web page (a simple database import script) and analyzes its output (Error message or "OK"). I am using code from the answer to this previous question of mine. $a = c:\path_to_wget\wget.exe --quiet -O - "http://www.example.com/import_db" $rc = $a.CompareTo("OK") exit $r...

Powershell running under a service hangs on *.zip CopyHere

I'm running a Windows Service (Hudson) which in turn spawns a PowerShell process to run my custom PowerShell commands. Part of my script is to unzip a file using CopyHere. When I run this script locally, I see a progress dialog pop up as the files are extracted and copied. However, when this runs under the service, it hands at the poi...

Powershell and getcontent CR LF

Have a very simple powershell script to count the number of trades in a file: (gc \mimkeimc11n\Batch\FundQuest\TradeFiles\trades.dat |? {$_ -match 'SL|BY'} | Measure-Object | select count).count > \mimkeimc11n\Batch\FundQuest\ConfirmtoFQ\NumberofTrades.txt The problem I am running into is the output NumberofTrades.txt is including the ...

How do I feed a quoted argument to perl in Powershell?

I want to call a perl script from powershell where a parameter is quoted: myProg -root="my path with spaces" I've tried to use -root='"my path with spaces"', -root='my path with spaces', -root=\"my path with spaces\", but nothing seems to work. After pressing <ENTER>, I see >> as a prompt. How do I pass this quoted argument on the co...

Access SQL - WMI Namespaces from Remote Machine

Hi, i am playing with Powershell and SQL WMI events and i am wondering if i can do this stuff remotely from the admin notebook: I'd like to query the "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" namespace: On SQLServer directly: get-wmiobject -list -namespace "root\Microsoft\SqlServer" >> Works! get-wmiobject -list -namespac...

Call a Messagebox.Show() from PowerShell with more than default button?

I am trying to show a message box from PowerShell with yes and no buttons. I can display a message box with an OK button: [system.windows.forms.messagebox]::show("Hello, world!") And I can create a variable $buttons with the buttons I want: $buttons=[system.windows.forms.messageboxbuttons].yesno And I can see that the Show() stati...

Must PowerShell scripts be called using only a single line?

I have some PowerShell scripts that accept many long parameters, like, myScript.ps1 -completePathToFile "C:\...\...\...\file.txt" -completePathForOutput "C:\...\...\...\output.log" -recipients ("[email protected]") -etc. I can't seem to make PowerShell run such scripts unless all the parameters are on a single line. Is there a way to invoke ...

PowerShell "echo on"

This is a duplicate of http://serverfault.com/questions/102098/powershell-script-showing-commands-run. I thought it would be more appropriate to ask this question here. I am playing around with PowerShell scripts and they're working great. However, I am wondering if there is any way to also show all the commands that were run, just as ...

msbuild calling powershell script under windows 7 gets signing error

We have a powershell build script that calls out to other scripts that is giving me trouble under Windows 7 64 bit. It works fine under XP. I've run set-executionpolicy to RemoteSigned (and also tried it with Bypass and Unrestricted). I can pull the command line from the error message and run it myself and it all runs fine. Build err...

Get "The remote server returned an error: (500) Syntax error, command unrecognized" when I try to run FtpWebRequest.GetRequestStream

I have following code to send files to a FTP server. function FtpUploader( [string]$uri, [string]$localeFile, [string]$user = "ftp", [string]$password = "ftp", [int] $timeout = 20000 ){ trap { Write-Host ("ERROR: " + $_) -Foregroundcolor Red return $false } $ftp = [System.Net.FtpWebRequ...

Slow to start an powershell script with no internet

I run a Powershell script on a computer that has no Internet connection. But it takes about 30 seconds to start it. How do I solve it? I have run ngen. ...