cmdlet

How to convert .cs file to a powershell cmdlet

Can anyone help me to convert a c# .net program to powershell cmdlet. I am very new to this area. plz help me to get out of this checkpoint. Regards Arun ...

how to create a cmdlet?

I have written my program in c# .net. I want to convert it in to a powershell cmdlet. I was instructed to use pssnapin and getproc programs. Can anyone plz help me out.. Regards Arun ...

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

How do I persist Powershell provider drive information?

In my Powershell provider, which is a business-logic layer over an SQL database, the Powershell drives equate to database connection settings. This collection of connection settings is persisted to an encrypted XML file on the local computer. An administrator may add these PS drives on a computer, supplying SQL Server credentials, that...

Writing a PowerShell cmdlet to accept a scriptblock as a parameter

The Rename-Item accepts a scriptblock (I think...) as a parameter so I can do something like this if I want to rename a bunch of files (for example): Dir *.ps1 | Rename-item -NewName {$_.Name -replace ".ps1" ".txt" } I'm writing a cmdlet to rename some items and would like to be able to use syntax like this for the new name, but how t...

Should I implement the IPropertyCmdletProvider interface for a PowerShell Cmdlet?

I'm writing a NavigationCmdletProvider for PowerShell. Through the GetItem and GetChildItems overrides, there are various types of objects that are written to the pipeline. The docs for IPropertyCmdletProvider interface tell us the following: Developers should implement this interface under the following conditions: When...

Export-Mailbox cmdlet not deleting emails

Hi, I've got an issue with using Export-Mailbox cmdlet in Powershell to delete emails between two dates from a mailbox. The current code that I am running is: Export-Mailbox -Identity mailboxname -StartDate "01/11/2009 00:00:01" -EndDate "14/11/2009 00:00:01" -DeleteContent I know there are emails that fall between these two dates, ...

How do I pass common powershell command line parameters between cmdlets on the pipeline?

Say I've got two cmdlets, 'new-foo' and 'do-bar'. Both cmdlets need to authenticate to a service in order to perform their action, and 'do-bar' takes a foo. Today, I can do: new-foo -host localhost -username user -password password -whateverOtherArgs And I can do: do-bar -host localhost -username user -password password -foo myFoo ...

Powershell scripting: recommended way to implement ShouldProcess when function calls are nested?

Test script: function outer { [cmdletbinding(supportsshouldprocess=$true)] param($s) process { $pscmdlet.shouldprocess("outer $s", "ShouldProcess") | out-null "" | out-file "outer $s" inner ImplicitPassthru inner VerbosePassthru -Verbose:$Verbose inner WhatifPassthru -Wh...

PowerShell Advanced Function get current ParameterSetName

In C# you can get the current ParameterSetName in the ProcessRecord override of a PowerShell Cmdlet with code like this: switch (ParameterSetName) { case FromUriParamSetName: loadFromUri(); break; case FromFileParamSetName: loadFromFile(); break; } I'm trying to figure out ho...

SQL Server 2008, Powershell and Web Services

Hi, Powershell provides the New-WebServiceProxy cmdlet which allows for a web service proxy object to be created. However the Powershell in SQL Server 2008 doesn't appear to support this. Is there a way to get SQL Server's Powershell to support the New-WebServiceProxy cmdlet? Many thanks. ...

creating powershell script to backup a file and append the date

Currently I have a one line batch file to back up a file. I run it manually when I need to back up a file. The only thing I would like to add to it is the current date. Here is what I have: xcopy /W /Y ACTIVE.DB ACTIVE.DB.BACKUP the destination file should simply be ACTIVE.DB.BACKUP.YYYYMMDD. How would I go about creating a script ...