powershell

What problem did MS solve by creating PowerShell?

I'm asking because PowerShell confuses me. I've been trying to write some deployment scripts using PowerShell and I've been less than enthused by the result. I have a co-worker who loves PowerShell and defends it at every turn. Said co-worker claims PowerShell was never written to be a strong shell, but instead was written to: a) All...

Users and Local Groups Report using Powershell?

Is there a simple way using powershell to show all Local Windows Groups that are active on a machine and the users that are part of those groups? A second part of this question would be if it can be extended to look at more than one machine at a time. ...

Invoke multiple powershell commands from c# on the same scope

Basically what I want to do is: Step 1) Invoke whatever.ps1 (or a scriptblock), the script is something like: $hello = "world" Step 2) Invoke Get-Variable -name hello Step 3) Retrieve the output of Get-Variable I can't figure out how to do this cleanly, because every time I invoke a scriptblock a differente scope is created. ...

Powershell script problem (Get-content vs assigning to variable)

Hello everyone, I'm attempting to write a Twitter Powershell script that will use community created interfaces PoshTwitter with the Twitter API to attempt and find a list of followers who are potential spammers. I have a feeling that my problem lies not with the particular cmdlet I'm calling (Get-TwitterFollowers), but rather with the ...

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...

Use Powershell to print out line number of code matching a RegEx

I think we have a bunch of commented out code in our source, and rather than delete it immediately, we've just left it. Now I would like to do some cleanup. So assuming that I have a good enough RegEx to find comments (the RegEx below is simple and I could expand on it based on our coding standards), how do I take the results of the fi...

Powershell output column width

If i have an exe: out.exe and its stdout is redirected to a file ie: out.exe > $file Right now if i do this it only outputs <-----------------------------> 80 columns per line to the file is there a way to make the standard output to be wider in console column count? is it the out.exe thats somehow messing with the columns.. in my ...

Width of PowerShell Output in the Visual Studio Output Window

I have a powershell script that runs fxcopcmd in the output window. Turns out that when I output results it limits the output to 80 Chars, is there a way to get it to be wider in the visual studio output window ...

Changing List's Column type from Lookup in Sharepoint

I am using the ilovesharepoint Lookup Field with Picker that is on codeplex on a Moss 2007 standard environment. I ran the setup project, and then in Powershell issued the appropriate command to change a Lookup field to the Lookup with Picker (ConvertLookupToLookupFieldWithPicker.ps1) which is shown below. # http://www.iLoveSharePoint.c...

How to do this in PowerShell? Or : what language to use for file and string manipulation?

What language should I use for file and string manipulation? This might seem objective, but really isn't I think. There's lot to say about this. For example I can see clearly that for most usages Perl would be a more obvious candidate than Java. I need to do this quite often and at this time I use C# for it, but I would like a more scr...

Saving webpage as MHTM file

Given a specific URL, I'm trying to download the contents of that URL as an MHT file. I considered writing a parser/crawler, but think there must be a quicker way. I fired up Powershell: $ie = new-object -com "InternetExplorer.Application" $ie.navigate("http://www.example.com") $ie.document.title # Just to verify the navigate worked ...

Powershell and Forms

I'm trying to get forms working with powershell, and I'm nearly there. I've got a checklist box full of ~10 items, and I'd like to perform an action on the selected items when you click the Report button. I've never worked with forms (either in C#, .NET, or powershell) so this is a learning experience... Is there any examples of how to,...

Where do you store your library of PowerShell scripts?

As soon as you start using PowerShell, you are likely to start collecting small, useful scripts. Managing them well is tricky. Where do you keep your PowerShell scripts? How do you track versions & do backups? How do you synchronize between machines? How do you integrate new versions of other's scripts? (Including dealing with brea...

Can I create my own attribute classes in PowerShell 2.0?

I was wondering whether you could create your own .NET Attribute classes for PowerShell and use them in scripts e.g. [DebugAttribute=true] function DoSomeThing() { "I don't run in Release mode" } ...

Powershell - calling remote WMI objects - RPC error HRESULT: 0x800706BA (RPC server not available)

Hello, I've got some troubles with Get-WmiObject and usage of this object. In case, I'm connecting to remote computer - which is not in AD, but in the internet. I'm using credentials and I'm able to retrieve list of WMI classes, or object (to be specific, I want to work with Win32_Process) via commands: $credential = Get-Credential $...

how can I split a text file using PowerShell

I need to split a large (500MB) text file (a log4net exception file) into managle chunks like 100 5MB files would be fine. I would think this should be a walk in the park for PowerShell. Any suggestions? ...

Is there a unit testing framework for testing PowerShell with PowerShell scripts?

I am lookin for a unit testing framework of type xUnit that lets me test PowerShell functions with PowerShell scripts. ...

MSBuild fails when run via Powershell

I have an MSBuild script that I want to call from a PowerShell script as part of a deployment process. If I call the build script via a bat file all works well. If I do the exact same thing in PowerShell I get CS1668 error looking for wierd and wonderful paths that dont exist on my machine. I know I am getting into the MSBuild script as...

How can I intersect two collections with a table with a 2-part key, in PowerShell?

I have input data like this: FOO.A FOO.B FOO.C BAR.X BAR.Y and a rules table like: (FOO = A, BAR = X) => 1 # match (FOO = A, BAR = Z) => 2 # no match (FOO = B, BAR = X) => 3 # match I want to take the input data, and ask the table "what entries match this input data?", and get back rows 1 & 3. I thought about using ...

Is there a shorter way to pull groups out of a Powershell regex?

In PowerShell I find myself doing this kind of thing over and over again for matches: some-command | select-string '^(//[^#]*)' | %{some-other-command $_.matches[0].groups[1].value} So basically - run a command that generates lines of text, and for each line I want to run a command on a regex capture inside the line (if it matche...