Detect 2.0 scripts when running on 1.0

I need to write up a C# console app that would take in a PowerShell script 
passed to it and execute it. I've got it mostly running by using the 
System.Management.Automation namespace and the corresponding 1.0 reference 
library. However, I'm running into an issue where the script can contain 
commands meant for PowerShell 2.0 (e.g. ThreadOptions). In this case, the 
script fails even if the script has a check in place for the powershell 
version. For example:

$ver = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}

fails right away, when it sees the ThreadOptions property. I am using the 
"RunspaceInvoke" class to invoke the scripts.

I'm new to PowerShell in general. Any help with what is happening here and 
how I might fix it would be appreciated.

6/29/2010 6:53:58 AM
windows.powershell 690 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 23

> commands meant for PowerShell 2.0 (e.g. ThreadOptions). In this case, the
> script fails even if the script has a check in place for the powershell
> version. For example:
> $ver = $host | select version
> if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = 
> "ReuseThread"}

Can you clarify this?  You have this check in your script, but it is not 
working when you call the script from C#?  Odd...

Try this maybe:
PS > get-content requires.ps1
#requires -version 3.0
PS > trap{"error";continue};./requires.ps1
PS >

No, I don't have PowerShell v3.  That's just to show you the header line you 
can use inside a script to make sure you're running the correct version of 
the engine.


6/30/2010 12:09:13 PM

Similar Artilces:

MultiWorkbook Change Event Detection / Spell Checker
Excel 2003 or 2007. Looking to be able to force spell checking whenever any cell content is is changed. I've been successful on a single workbooks by adding Spell Check execution on Worksheet_Change. I'm hoping to take this one step further - make it an 'Add-In' so the check will run for any workbook. It looks like the Worksheet_Change event only triggers for the host workbook so an 'Add-in' will not do the job. Any suggestions to force spell checking on a change for any workbook/worksheet I modifiy? TIA, - Pat The way I would go about this i...

attachment question #2
Hi every1... just had a question about attachments in outlook 2000 when i attach a file is it possible to have this msg appear in each email that has a attachment? the msg is (See attached file: filename.ext) my friend using lotus notes has it generated automatically.. just wondering if outlook had this option. Thanks for your help ------------------------------------------------ ~~ Message posted from ~~ View and post usenet messages directly from any 1? ;) ------------------------------------------------ ~~ Message posted fro...

merging data from 2 spreadsheets
Hello I work in a school and often export or collect data into spreadsheets of student grades and assessments etc. I often have to combine different lots of assessments from 1 or 2 spreadsheets into one and do this by arranging windows or 'comparing side by side' and go down the list of students in both files, (sorted by name) then when the students are in the exact order of rows, I copy the columns of data i want from one file into the other. This is very tedious and making me go blind! Is there a better way of doing this?? Like a query or something. Anything? I'm using Off...

Error message on startup #2
I've started using my copy of Outlook 2007 that came along with Office 2007 Pro. Got it all coordinated with my email server but every time it (Outlook) opens I see the following message: Any ideas? Thank You All, -plh -- Where are we going and why am I in this HAND BASKET?? The error says it all; the issue is with an Avast add-in that you installed. You'll be better off reinstalling Avast without the email integration tools as it doesn't add an extra level of protection anyway. See -- Robert Sparnaaij [MVP-...

Lookup tables #2
want to use lookup tables as poor man's db. have about 200 uniquely numbered stores, each time a call comes in we log it by that number, and each "record" has 11 "fields" or columns. if the list is sorted in ascending order, how can i use a a vlookup in combo with macro to go in and key off the unique number and bring all the rows of data back identified with that unique number to one page? Stores may have only one "record" and some may 15. formula would look at the keyed in number...say 101 and go to lu table and start with 101 and repeat until it reach...

CSV to XML #2
Hi, I want to generate different XML files from one CSV file. For eample I want build the employee.xml which should contain the distinct list of employees from the CSV file. The CSV File contains employee name getting repeated multiple times based on the record type. Please suggest how can I handle this requirement. Thanks in advance. Regards, Manoj Thanks to the wonders of modern computers, there are at least a dozen different ways you could do this, but how about this straight-forward approach ... 1. Write a program that reads the CSV file, line by line, and just writes the same ...

How to detect changes in a column?
If I have a table with sales forecast data (columns) like Customer, Amount and Status, what would be the best way to track changes in this table so I can compare my forecast week after week? -- inomata ------------------------------------------------------------------------ inomata's Profile: View this thread: ...

is HRESULT only used in COM interface programming? I see this quite often in a COM module call. I've seen it mostly used with COM and Windows message calls, but I think HRESULT is just a long that is encode with attributes so you could likely use it wherever. Here are some interesting articles: Tom "June Lee" <> wrote in message > is HRESULT only used in COM inte...

version changes #2
i created a business card on Publisher (xp) but when i try to load it onto a computer w/ a color printer that has publisher ('97) it says i can't load stuff from another version. is there any way i can "downgrade" the project to make it compatible with the older version? ...

System Standby Failed & .Net Framework v1.0.3705 message
I am getting a "System Standby Failed" error message. This pops up on it's own. The full length message is: The service 'Microsoft .NET Framework v1.0.3705 Update' is preventing the machine from entering standby. Try stopping this service and try again. Except for a Windows udpate that came through recently I can't think of anything that's changed. How do I correct this? See the "How to obtain help" section of For home users, no-charge support is available by calling 1-866-PCSAFETY (1-866-727-23...

Error accessing Reports in CRM 3.0
I get this error: Microsoft CRM Unhandled Error Details: Server Error in '/' Application. -------------------------------------------------------------------------------- The request failed with HTTP status 401: Unauthorized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthorized. Source Error: An unhandled exception was generated during...

Copy Paste from Word to Excel in Lao script
I have a strange problem in Office 2004 using Lao script. I have an excel file with a table with Lao script on it, but when I tried to copy / paste the table into Word all the Lao letters 'Noo Nok' just didn't copy over like they were never there. I tried to fix using different Lao fonts etc but always the same result. I did find however that I could paste words with the Noo Nok letter into text edit and then copy and paste that into Word. While this did fix the problem it is extremely slow as you can't paste tables into text edit so I had to do word by word. Why would the l...

detect and repair
my outlook 2002 had some hyperlink problems which were corrected when i used the 'detect and repair' option in help. now i have lost my addresses and all the e-mail that was in my inbox. How do i recover these items? Check this page for all you need to know: -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP **I apologize but I am unable to respond to direct requests for assistance. Please post questions and replies here in the newsgroup. Mahalo! "Mark Conner" <> wrote ...

Restore #2
I have reformated my drive and reinstalled Money. My backup is on a cd. I just connot make money accept the restore. Says something like cannot access where I am trying to put the info. I have tried 15 or 20 different ways but to no avail. Thanks, Melvin In, Melvin wrote: >I have reformated my drive and reinstalled Money. My >backup is on a cd. I just connot make money accept the >restore. Says something like cannot access where I am >trying to put the info. I have tried 15 or 20 different >ways but to no avail. Copy your .mny and/or .m...

Hung Email in Mailbox #2
I have a user that has an email hung in their mailbox that is preventing them from downloading their mail into outlook. I know this is the problem because I have had the same problems but was able to clear the offending email using webmail. However I cannot seem to get the permissions correct on the user account so they can use webmail to clear the message. What other ways can I get to their messages and remove the offender? ...

Disabled accounts #2
Hi, When we have staff leave, I have normally Disabled their account for security purposes. I leave the mailbox intact in case we have to refer to a message. I then Enable their account, check the message and then Disable it again. Having these accounts disabled results in Warning messages in the Application Log saying the "Disabled user 'UserName' does not have a master account SID". What is the recommended way of dealing with users leaving an organisation when their mailbox needs to be retained? Thanks, John 1. hide them from the GAL 2. remove them from all d...

Excel inserted 0's in cells linked to blank cells
I added a work sheet by copying selected data from main worksheet (copy, paste special, link) and where there were blank cells in original worksheet, Excel inserted 0's. Is there a quick way to get rid of them. Blank cells are to be expected in this database of names, info, etc. My approach was to turn on auto filter and select for 0, highlight column and delete contents. Hoping there is a less tedious way to do this. Thanks, Trudy -- lburg801 ------------------------------------------------------------------------ lburg801's Profile:

grid lines #2
i come tables from the net and paste them into Word to format -- removing certain columns. when i paste the tables into excel, i get white spaces in the excel sheet around the information i've pasted in. no matter what i do, i cannot get the original excel grid lines back on the sheet. small problem i know but does anyone have a solution? thanks! Hi, Highlight the range and click the Borders toolbar button and choose No Borders. -- If this helps, please click the Yes button Cheers, Shane Devenshire "Marcie" wrote: > i come tables from the net and paste them in...

block attachments #2
My network is infected to W32.sober.i@mm... virus. All my users get email from different forged email address email with *.zip, *.src ... so on attachments couple of times a day. All computers have up to date antivirus sw and I run everysingle on them soberfix tool from Norton, found nothing. I've been blocking these email address, but they keep coming from different address, so I gave up. Is there any way I can block certain attachments except *.xls and *.doc? We use the following: Outlook 2003, Outlook2000, and Outlook express. Who/What provides e-mail services on the server side?...

Visio 2000 Service Release 1 #4
Does anyone have a copy of this available for download? Bravejoe "There's fodder for the cannons and the guilty ones can all sleep safely." Andy Partridge XTC "That's my opinion. I could be wrong." Dennis Miller "It Doesn't Matter!" Bravejoe remove the "t1","us" and replace "com" with "net" from my email address to reply privately. ...

Money Invoice Designer #2
I have 2005 Money Business. I use the invoice feature. However the invoices need to be altered to work for me. When I use the Invoice Designer and alter the template or make a new template (either/or) then save it, it looks great. However when I go back to use it, it no longer exists. Where does money store it? I need to print out a bunch of! See - it might be the problem that you have. -- Glyn Simpson, Microsoft MVP - Money Check;EN-GB;mny or http://money...

Barcoding Customers #2
I would like to start barcoding customer account cards and customer loyalty cards. Any suggestions? -- Blue Valentine Fashions for All of Your Nightly Affairs For something inexpensive, go to the Avery paper website. Download their Design Pro Limited program create a business card size with your info on it, with an incremental barcode number on it and print to a business card stock, either from Avery or any supplier with the same dimensions. For something fancier, go to Google and type gift or id cards. I have customers who purchased from -- ...

Copy Data from Chart to Chart #2
I have to create separate charts for ten employees. I want to have all the data on one sheet tab. Create the chart on another tab for employee 1, format the chart the way I want and be able to add the data for employee 2, 3, 4, etc. to each tab, using the same format for chart 1 so they all match. So there should be one tab for raw data and 10 tabs for each employee. I’m using Excel 2000 Thank you Karen - Make a chart for the first employee, and make it look just the way you want it. Then right click on the sheet tab, select Move or Copy, and make a copy. Then make eight more copies....

Formula #2
I would like to have a formula that has several if statements in it and give me a dollar amount for the date and code that i specify. for example i have a spread sheet set up as follows date reason code cost 6/22/04 we $1.00 6/22/04 be $1.00 6/22/04 msg $1.00 i need it to search for a specific date then search for the 3 reason codes i have listed the give me the total dollar amount for that date and reason codes. i have been stuggling to figure out the formula that can capture this information for me. any help would be greatly appreciated. t...

Excel4 Workbook Wont run in Excel XP
Hi my experience in Excel is limited but have a major problem. Have been given a excel workbook that is used for producing results for downhill skiing competitions. The sheet lets you put all the competitors details in and then their basic seeding points. By the push of a button it will let you set up each race and then print out the start positions. After each race it will let you put in the times and then calculate by the push of a button the seed positions and the start order for the next race etc. until the whole competition is finished then it will let you print all the overall result...