powershell-v2.0

Powershell 2.0 out-file formatting nightmare...

How can I get Powershell to output a file IDENTICAL to the file produced by the following command? dir /s /b /a-d *.* > C:\files.txt should be easy, right?!! EDIT: I found ps was truncating the output based on the screen buffer width. Fix that with format-table and it pads with spaces... try format-list and you get property headings.....

Powershell script that extracts medadata from powershell script.

Hi, Does anybody know of a script or powershell windows utility, or 3rd party utility, codeplex, poshcode script, app, whatever etc, which can read and scan a powershell script and detail what snapins, providers, assemblies, cmdlets, functions, etc, etc, etc, the script needs to execute. Thanks. Bob. ...

get a multi-version diff report from TFS?

I used to use a different source control tool and it allowed me to get a "diff report": all the changes made to a file between version X and version Y (including lines added/removed between each version, which could be many versions) in one text file. It was pretty handy for situations where you are pretty sure that some code used to be ...

What are the effects of failing to close/dispose Powershell Runspace objects before process termination?

Given an application that maintains a singleton instance of a Runspace object (from System.Management.Automation.Runspaces) for the lifetime of the application, what are the potential side effects of failing to dispose of the Runspace before the application is terminated? The design rationale I have been presented with is that memory/ha...

Can you set an object's DefaultDisplayPropertySet in a PowerShell v2 script?

Here is a blog post from Kirk Munro that explains how a script can set the DefaultDisplayPropertySet on its output objects: Essential PowerShell: Define default properties for custom objects His technique and example code doesn't appear to work in PowerShell v2. (Note, I have PowerTab and PSCX installed--perhaps those could be interfer...

powershell v2 remoting - How do you enable unecrypted traffic

I'm writing a powershell v2 script that I'd like to run against a remote server. When I run it, I get the error : Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration. Change the client conf...

Locate Compressed files on servers

Hi, I would like to create a powershell script generating a report showing all compressed files/folders on remote servers. By compressed files I mean files compressed using the buildin Windows Compression utility, not zip. But I have a hard time figuring out how to localize the compressed files. Should I go with WMI or? Thanks Frank ...

Does PowerShell STA mode eliminate SharePoint memory leak issue?

Some background: SharePoint+PowerShell is (Usually) a Perfect Match by Zach Rosenfield [MSFT] SharePoint+PowerShell Leak Workarounds by me SO: Could you explain STA and MTA? In short, standard SharePoint guidance is that COM-backed objects like SPSite and SPWeb should not be used by different threads. This stands in conflict with Pow...

get a set of files that have been modified after a certain date

Does anyone have a handy powershell script that gets a set of files from TFS based on a modification date? I'd like to say "give me all the files in this folder (or subfolder) that were modified after X/Y/ZZZZ" and dump those files to a folder other than the folder they would normally go to. I know enough powershell to hack about and get...

Accessing Event Arguments in Action scriptblock of Register-ObjectEvent cmdlet

Is it possible to access the Event arguments in the -Action scriptblock of the Register-ObjectEvent cmdlet? And if yes, how? ...

How to build a WPF application with Add-Type C# code

hi, i tryed to build WPF application using Add-Type, but it failed. $a = @' using System.Windows; public class Program { [STAThread()] public static void Main(string[] args) { Application app = new Application(); Window1 w = new Window1(); app.Run(w); } ...

How to create a performance counter and see it in PowerShell?

Hello I want to create a performance counter named as FileCopierApp, this should work with the get-counter cmdlet, How can I Achieve this? the properties would be: CounterSetName : FileCopierApp MachineName : . CounterSetType : SingleInstance Description : Statistics for FileCopierApp.exe application Paths : {\localhost\blablabla} PathW...

How to use BITS in Powershell to upload / download files?

I've found some pages in Google regarding this, but they are either not complete or outdated. Is there a definite guide somewhere? Thanks ...

Unblock a file with PowerShell?

I am trying to have PowerShell unblock a file in Win2K8 R2. Does anyone have a pointer as to syntax? Thanks in advance, Dan ...

Exec sproc from Powershell

I would like to execute a stored procedure from Powershell (v2) against a SQL Server 2008 database. Coming from using C# as my primary language, I'm doing it in that fashion. For example, when I need to run a sproc that doesn't return results, here is what I'm doing now: $con = new-object System.Data.SqlClient.SqlConnection($connectionS...

Powershell, trying to output only the path and lastwritetime on directories

I am trying to write a script that will output any directory that has not changed in over 90 days. I want the script to ONLY show the entire path name and lastwritetime. The script that I wrote only shows the path name but not the lastwritetime. Below is the script. Get-ChildItem | Where {$_.mode -match "d"} | Get-Acl | Format-T...

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run commands remotely. So PS remoting is working between the local server and remote server. But when I try to access a share on a 3rd server (di...

Where is the "Invoke" member in System.Management.Automation.VerbsCommon?

I'm trying to create a cmdlet with the name Invoke-Something. But I cannot find the member "Invoke" to put in the attribute: [Cmdlet(VerbsCommon.Invoke, "Something", SupportsShouldProcess = true)] ^^^^^^ What am I missing? ...

Gracefully stopping in Powershell

How do I catch and handle ctrl+C in a Powershell script? I understand that I can do this from a cmdlet in v2 by including an override for the Powershell.Stop() method, but I can't find an analog for use in scripts. I'm currently performing cleanup via an end block, but I need to perform additional work when the script is canceled (as o...

Building a Snap-in Targeting PowerShell V1 and PowerShell V2

How do I build a PowerShell snap-in to target PowerShell v1 and v2? Given that v1 and v2 can't be installed side by side how can I reference the appropriate assemblies and build against them? Inevitably as things go on I'm going to be adding new PowerShell v2 specific features. So I'm going to need separate product builds targeting diff...