powershell

How to expose functionality to PowerShell from within your application.

I was listening to the podcast about PowerShell 2.0 that Scott Hanselman did. In that episode, they talked about the possibilities to extend your application to expose functionality for PowerShell. Now this sounds interesting. Have any of you done such extensions that exposes functionality in your application? If so, what kind of functi...

powershell to get the first x MB of a file

Its pretty straightforward to get the first x lines of a text file, but I need the first x MB of a file. Given that I'm a PowerShell neophyte if you could please give me some annotations on the script that would be greatly appreciated. ...

How to Remove ReadOnly Attribute on File Using PowerShell?

Hi, How can I remove the ReadOnly attribute on a file, using a PowerShell (version 1.0) script? Thanks, MagicAndi ...

What are some of the most useful yet little known features in the PowerShell language

A while back I was reading about multi-variable assignments in PowerShell. This lets you do things like this 64 > $a,$b,$c,$d = "A four word string".split() 65 > $a A 66 > $b four Or you can swap variables in a single statement $a,$b = $b,$a What little known nuggets of PowerShell have you come across that you think may not be...

PowerPoint 2007 SP2, ExportAsFixedFormat in PowerShell ?

Yesterday I was trying to batch convert a group of PPTs into PDFs for a friend, and I decided to have a look at PowerShell, since it's been sitting on my HD for a while. Here's the code I've come up with. $p = new-object -comobject powerpoint.application # I actually don't know why I have to set the window to visible, # but it doesn'...

Powershell Hard and Soft Links

Can Powershell 1.0 create hard and soft links analogous to the unix variety? If this isn't built in, can someone point me to a site that has a ps1 script that mimics this? This is a nessary function of any good shell, IMHO. :) ...

Setting the start dir when calling Powershell from .NET?

I'm using the System.Management.Automation API to call PowerShell scripts a C# WPF app. In the following example, how would you change the start directory ($PWD) so it executes foo.ps1 from C:\scripts\ instead of the location of the .exe it was called from? using (Runspace runspace = RunspaceFactory.CreateRunspace()) { runspace.Open...

Query assembly

I have a .NET assembly that has tens of classes and methods which are unit testing methods. I want to generate a report with all the method marked with attribute Ignore, do you know a simple way to do that? ...

Why would I use Powershell over C#?

I know that Powershell is quite powerful in that it is a scripting language in which you have access to the entire .Net framework (thats all I know about it). But i'm struggling to understand what's the big hype about Powershell when I could use C# to code the exact same thing? ...

How do you add users from a CSV file to Active Directory (AD) and Exchange using PowerShell?

How would one add a group of users to Active Directory from a csv file using PowerShell? The csv file would contain the first, last, email, temp password, and description for the users. The OU, permissions, and etc. could be hard coded. The script should also add an Exchange 2007 email box. ...

How Can I Prevent Needing to Re-sign My Code Every 1 or 2 Years?

I was reading What happens when a code signing certificate expires - Stack Overflow and wondering about a more solid answer. The answer provided was more about setting up your own CA. Even with your own CA you will still need to deal with expiring code certificates. If you signed the code without using a time stamping service, after t...

Powershell being too clever

Apologies for what is probably a newbish question. I am writing some Powershell scripts that run various queries against AD. They will usually return a bunch of results, which are easy to deal with, ie: $results = myQuery write-host "Returned " + $results.Count + " results." foreach ($result in $results) { doSomething } No worries. H...

Elevate Powershell scripts

Is it possible to elevate the permissions of a powershell script so a user without admin privileges can run the script? Our network admins are trying to find more time-efficient ways to accomplish certain tasks that right now they have to use remote desktop for...automating them with PS scripts would help, but the users don't have admin...

Is it possible to have many pipelines for 1 runspace.

Hi, This is executing scripts asynchronously from c# and having threads doing the work of loading the script for execution and waiting for output to come out. I may need to have many scripts executing at once, maybe concurrently. Is possible to have a 1:M relationship between runspace and pipelines in windows poweshell and if so what...

Tool to list all source safe link files

My client is migrating from Source Safe to Clearcase. They need to list all the link files in the Source Safe database so the links can be carried over to Clearcase, as apparently all the source must be checked into Clearcase on day 1, losing any existing links. Are there any tools for creating this report, or perhaps even doing the ful...

Capture EXE output in PowerShell

A little background first. I've been tasked with encrypting files with a Powershell script using GPG (gnupg.org). The specific exe I'm calling is simply gpg.exe. I'd like to capture the output whenever I execute a command. For instance, I import a public key in powershell as follows: & $gpgLocation --import "key.txt" $gpgLocation is...

Powershell and SQL parameters. If empty string, pass DBNull

Hi, I got this parameter: $objDbCmd.Parameters.Add("@telephone", [System.Data.SqlDbType]::VarChar, 18) | Out-Null; $objDbCmd.Parameters["@telephone"].Value = $objUser.Telephone; Where the string $objUser.Telephone can be empty. If it's empty, how can I convert it to [DBNull]::Value? I tried: if ([string]:IsNullOrEmpty($objUser.Tele...

C# Poweshell. Is it neccessary to teardown the pipeline after each script execution.

Hi, Simple question. I see that Jean-Paul Mikkers async poweshell example over at code project is tearing down the pipeline and recreating it after every script execution. Does anybody know if there is a particular reason why it's done this way, or does the pipeline need to be recreated every time. I've tried execution on it multiple...

Powershell not loading profile when running through PSEXEC

I am working with powershell 1.0 using PSEXEC to run scripts remotely (or on the same box in a batch mode). On my machine, the "remoted" powershell session correctly loads my profile.ps1 (from the MyDocuments folder), but on another machine, it doesn't. I'm not passing in the -noprofile switch to the powershell.exe, and I have verified...

Powershell error when using CloudDrive Azure sample

I am currently trying to use the CloudDrive (Powershell) sample that comes with the Azure SDK to list the blobs I have stored. I'm getting an error fairly early in the process, and I figure there must be something I'm doing wrong - I just don't know how to debug this kind of problem... I have followed a great tutorial regarding logging,...