powershell

In Powershell, what's the quickest way to tell if two files are different?

Given two files (in this case, largish CSV files), what's the most efficient way in Powershell to determine if their content differs? ...

Install-SPSolution : This solution contains no resources scoped for a Web appli cation and cannot be deployed to a particular Web application.

I have a powershell script that deploys about 12 web parts. They have all been created in the manner through visual studio 2010 and are being deployed to sharepoint 2010. I am getting the following error when running Install-SPSolution for one of my web parts: Install-SPSolution : This solution contains no resources scoped for a Web app...

Is there a better way to get ‘class’ semantics in Powershell (defining custom types)?

I am building an automation system using Powershell and I would like to define custom .Net types so that I can structure my application in a similar way to the other code I write. At first, I tried using ‘Add-Type’ to import types from c# files into my application but I found this to be extremely painful to debug as a .net type can only...

MAML (Powershell Help) XSD

I am generating MAML files for use with Powershell's Get-Help cmdlet. I would like to validate them. Can anybody tell me if there's a schema file somewhere that I can validate against? ...

Powershell: How to capture output from the host

I am using powershell to automate some tasks related to checking out/merging in TFS. When I call tf get * /recurse I get a bunch of data scrolling by about the files that are getting checked out. The last line generated by this command (assuming its success) is one telling the checkin number. I would like to parse this out so it c...

Powershell Get-QADUser -SearchRoot

I read that you can pass an array to the -SearchRoot parameter so that you can retrieve objects from multiple containers with one call, but I'm struggling to find any examples or further writings on the subject. Has anyone come across an example they could point me to that will help me understand how to do this? ...

Powershell: call an exe with parameters from items in an array?

I have a set of commands that I'd like to run and do some returncode checks against the result, so i figured it would be easy to put them into an array for execution. Let's take this one as an example: C:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section system.webServer/webdav/authoring /enabled:true /commit:...

Display Progress while Restoring Database with PowerShell and SMO

I have a script for restoring a database with PowerShell and SMO. Now I know that I can pass a event handler into PercentComplete on the restore object and get the progress of the restore as it happens. The problem is I don't know how to create a event handler and pass it a function in PowerShell? I can do it in C# restore.PercentComple...

Fast ping function for Powershell

Does anybody have a fast function for pinging a list of machines using Powershell? I know I can use Test-Connection: Test-Connection -Count 1 -ComputerName (gc .\comps.txt) -ea silentlycontinue but this seems painfully slow (I'm assuming because it uses Win32_PingStatus). Even better would be an example of how running it as a backgr...

Powershell - quick way to read tab delimited file and sort by date column

What is the best/quickest way to read a tab delimited file and process only a few columns Sample Name\tAddress\tCit\t\State\Zip\Date of Move I am looking to only get column1 and colum6 for the next 30 days (Name , Date of Move and sort by Date of Move's scheduled in the next 30 days..... Make sense...? I have played with Get-Conten...

Problem invoking PowerShell commands from C# custom action in WiX installation

Background: I'm writing an installation for a SharePoint component. In addition to getting the software onto the target machine, I want to properly configure it. SharePoint (esp. 2010) exposes its management functionality via PowerShell. So I wrote a C# custom action to invoke a series of commands, like this: Runspace runSpace = Runs...

Having trouble integrating powershell and c#

EDIT: I figured out how to solve the specific code broken part of my question (see my answer bellow), but I'm still looking for resources on integrating powershell and C# so please still feel free to comment or answer! I found a simple example of making your C# objects visible to powershell scripts and I've been playing around with it. ...

Would you recommend Iron Ruby, Iron Python, or PowerShell for making a C# application a script host?

After some quick tinkering, right now I'm leaning towards powershell for two main reasons (note these a purely my opinions and if they are wrong, I'd love to know!!!): 1) It's simple to create a runspace with classes in your application, and therefor easy to make your application scriptable. 2) I've heard some rumors that IronRuby and...

Powershell One-Liner to return version of .NET Framework on a machine?

My first guess is something involving WMI. Does anybody know better? Clarification: One-Liner to return only the latest version for each installation of .NET ...

How to automate script generation using SMO in SQL Server?

I would like to automate script generation (in SSMS --> Tasks --> Generate Scripts) in SSMS 2008. I have read that SQL Server 2008 does not support Database Publishing Wizard (including SQLPUBWIZ SCRIPT) but this automation can be done using SMO in SQL Server 2008. I don't have a clue about SMO and how to do this using SMO, so could you ...

Powershell File Compare

I am using a PowerShell script to move some files around on some servers. I want to test if a file I am going to move already exists in the destination. Not just a file with the same name. I thought Compare-Object $File1 $File2 Should do it but no matter what the files are it always returns that they are the same eg. InputObject ...

What's the powershell syntax for multiple values in a switch statement?

I basically want to do this: switch($someString.ToLower()) { "y", "yes" { "You entered Yes." } default { "You entered No." } } ...

What does $_ mean in powershell?

I've seen this alot in powershell but not sure what exactly it does: $_ ...

Creating a build configuration in TeamCity using Powershell

Anyone know how I can create or delete a build configuration in TeamCity, only using Powershell? I am trying to automate our entire project setup process; have looked at the REST API but that appears to be mostly read-only. ...

Listing Folder Size by Piping

How can I list size of each folder in a directory by the sum of all files in each folder/subfolders? My latest attempt: ls | foreach-object { select-object Name, @{Name = "Size"; Expression = { ls $_ -recurse | measure-object -property length -sum } } I've made other attempts but nothing successful yet. Any suggestions or solutions a...