powershell-v2.0

Custom read-host dialog for PowerShell 2 CTP3 ISE

Is it possible to hook a custom dialog into the new PowerShell ISE (Integrated Scripting Environment) that replaces the existing .NET WinForms dialog. I am talking about the dialog that the Read-Host cmdlet launches to request for user input. ...

Why is XDocument.Descendants() returning IEnumerator in PowerShell ISE?

I'm writing a PowerShell script to manipulate some Windows Installer XML (WiX). I'm using the new XML APIs in .NET 3.5 to do this, as I find it an easier API to work with than the DOM. The following script fragment is flatly refusing to work: [System.Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null # Basic ide...

Using PowerShell with .NET 3.5 runtime/libraries

Is it possible to run PowerShell 1.0 (or 2.0 CTP) backed by the 3.5 runtime instead of 2.0? We're building a .NET 3.5 solution, and I'd still like to use PowerShell as our scripting engine for scheduled tasks, etc. I don't need LINQ syntax or anything, just the 3.5 libraries and runtime. FOLLOWUP: thank you for the reply about dynam...

PowerShell - Distributed Solution

I'm new to PS so I may get some of the terminology wrong. If you want to roll out a custom PowerShell environment (snap-in) for a team of 30 developers/DBAs. What is the best way to do this... if you intend to be rolling out new functionality once a week? Does PowerShell 2.0 help in this regards? Assumption: There is no issue with eve...

What does it mean that powershell 2.0 will be "firewall friendly"?

I'm interested in executing powershell scripts on a computer behind a firewall. What ports will I need to have open? Will any special configuration be needed or I'll be just be able to connect to a fresh install of Windows Server 2008 r2 and start executing my scripts? ...

PowerShell - Most Compact way of "Delete all files from this folder except one"

What is the most compact way of deleting all files from a folder except one file in a PowerShell script. I doesn't matter at all which file is kept, just as long as one is kept. I'm using the PowerShell 2 CTP. UPDATE: An amalgamation of all the answers so far... $fp = "\\SomeServer\SomeShare\SomeFolder" gci $fp |where {$_.mode -notm...

PowerShell, Web Requests, and Proxies

When making a simple web request is there a way to tell the PowerShell environment to just use your Internet Explorer's proxy settings? My proxy settings are controlled by a network policy(or script) and I don't want to have to modify ps scripts later on if I don't have to. UPDATE: Great info from the participants. The final script tem...

copy-item With Alternate Credentials...

I'm using the CTP of powershell v2. I have a script written that needs to go out to various network shares in our dmz and copy some files. However, the issue I have is that evidently powershell's cmdlets such as copy-item, test-path, etc do not support alternate credentials... Anyone have a suggestion on how best to accomplish my task.....

Structs or Objects in Powershell 2

Does the latest version of Powershell have the ability to do something like JavaScript's: var point = new Object(); point.x = 12; point.y = 50; If not, what is the equivalent or workaround? UPDATE Read all comments ...

What can I do with C# and Powershell?

I have a very good understanding of C# (I'm probably an intermeddiate programmer) and a very basic understanding of powershell. I'm using Windows PowerShell CTP 3, which has been really fun. But I want to go beyond writing scripts/functions. Is there any cool stuff to do with C#? ...

What objects are suitable for Add-Member?

Documentation states: Adds a user-defined custom member to an instance of a Windows PowerShell object. What "Windows PowerShell object" stands for? This works fine: $obj = new-object system.object $obj | add-member -membertype noteproperty -name Name -value "OK" $obj.name But this does not: $obj = @{} Actually, I am tryi...

PowerShell MetaProgramming - Generating Advanced Functions

I am looking at dynamically building a bunch of Advanced Functions. I have been using New-PSScript for this but it doesn't allow for all the flexibility I am looking for. I was reading the man page for about functions advanced parameters and saw something about Dynamic Parameters at the end of the help article which gives the following...

Automate Virtual PC 2007 with PowerShell?

This is basically a duplicate of this question, but the accepted answer was "no" and I would like to keep this question open until getting an actual answer instead of accepting "NO" and giving up. Stephen Rose told me via Twitter DM to use PowerShell to start and stop Virtual PC VM's and do things like run installations, automatic updat...

Equivalent to C#'s "using" keyword in powershell?

When I use another object in the .net-Framework in C# I can save a lot of typing by using the using directive. using FooCompany.Bar.Qux.Assembly.With.Ridiculous.Long.Namespace.I.Really.Mean.It; ... var blurb = new Thingamabob(); ... So is there a way in Powershell to do something similiar? I'm accessing a lot of .net objects and...

Powershell reference assemblies for powershell v2 ctp3

Hi, I've installed powershell v2 ctp3 from the ms download and was wondering where the usual reference assemblies are stored for use in c# for this version. I know for the v1 version they are in program file\etc\reference assemblies\powershell.... but where are they for the v2 ctp3 version. I specifically looking for the new System.Mana...

How to access the powershell v2 ctp3 assembies from c#

Hi, I know the System.Management.Automation.dll assembly is put in the GAC, version 6.1.6949.0, which I know is the ctp3 assembly. When I browse for it, in c# to add it as a reference from within VS 2008TS, it doesn't show up. Anybody know how I can add it. regards scope_creep ...

Windows 2008 unable to execute c# powershell app. Returning access exception.

Hi, Does anybody know why I can't access the folder where my powershell scripts are in windows 2008 Ent. When I try to create a script with textpad it craps out. When I try and execute a c# powershell app, which is stored on another win 2003 drive, it craps out with an access exception as well. I've set powershell execution policy to un...

How to capture a Powershell CmdLet's verbose output when the CmdLet is programmatically Invoked from C#

BACKGROUND I am using Powershell 2.0 on Windows 7. I am writing a cmdlet in a Powershell module ("module" is new to Powershell 2.0). To test the cmdlet I am writing Unit tests in Visual Studio 2008 that programmatically invoke the cmdlet. REFERENCE This Article on MSDN called "How to Invoke a Cmdlet from Within a Cmdlet" shows how ...

whether to use a powershell pipeline or use powershell RunspaceInvoke to execute scripts.

Hi, I have a design query as regards the usage of the powershell pipeline versus the RunspaceInvoke method for the exectuion of single standalone scripts. I know that the pipeline as used is, according to msdn, like an "assembly line". As i'm only excuting single standalone scripts, do I need to use it at all. Whats the pro's and con's...

Whats the best way to wrap a c# class for use by powershell script.

I have an engine that executes powershell scripts, and when they execute, need to feed back in some xml to the caller. The engine only takes i/o as an idmef xml message. So the script needs to return a similarly formatted xml message. I have a class which does my formatting for me and it would like the script writers to use it. So quest...