background preloader

Powershell

Facebook Twitter

Executing Sql scripts from powershell. Realizing I still have 6 Tips'n'Tricks articles nearly ready to go to follow up on the series, but none of them are finished, I thought I'd give you another powershell trick.

Executing Sql scripts from powershell

One of the main issue on windows when interop has to be achieved between powershell and cmd is the issue of CreateProcess trying sometimes to be too smart about quotes. That's why powershell supports being called with a base64 encoded parameter as command line parameters, and why attempts to use variables when calling sqlcmd.exe fail miserably. Q. How do I quote command parameters for an external command in PowerShell? A.

Q. How do I quote command parameters for an external command in PowerShell?

Normally, PowerShell can run external commands if you simply type the command name: Ipconfig<br>Ping Bing.com<br>Nslookup However, some commands require extensive command-line parameters. Professional Windows Powershell Programming 2008.pdf (application/pdf Object) Creating PowerShell Help Files Dynamically « SharePoint Automation. It’s been a while since I’ve blogged anything useful due to all my writing efforts going to the book that I’ve been working on.

Creating PowerShell Help Files Dynamically « SharePoint Automation

However, I’ve recently wrapped up my last chapter for the book so I figured what better time to start focusing on my blog again. The first thing I wanted to cover was something that I should have documented back in May of 2010 when I released my SharePoint 2010 cmdlets and it is something that I just finished referencing in my last book chapter: creating help files for custom cmdlets. In the book I emphasize that creating these help files is not a trivial task and there are virtually no good tools available to help you with the effort.

As you may know, I’m all about automation; so I figured, how hard could it possibly be to automate the creation of the help file? Trying to make a MAML file. Here are the files you requested.

Trying to make a MAML file.

How to Declare Cmdlet Parameters. These examples show how to declare named, positional, required, optional, and switch parameters.

How to Declare Cmdlet Parameters

These examples also show how to define a parameter alias. How to Declare a Named Parameter Define a public property as shown in the following code. When you add the Parameter attribute, omit the Position keyword from the attribute. [Parameter()] public string UserName { get { return userName; } set { userName = value; } } private string userName; Types of Cmdlet Output. Windows PowerShellprovides several methods that can be called by cmdlets to generate output.

Types of Cmdlet Output

Typically, these methods use a specific operation to write their output to a specific data stream, such as the success data stream or the error data stream. This topic describes the types of output and the methods used to generate them. Types of Output Success output Error output Verbose output. Cmdlet Verbs. Easy Windows PowerShell cmdlet development and debugging. Sunday, February 03, 2008 2:33 PM bart Before posting another post in the Windows PowerShell domain, I thought it was useful to write down the way to write a simple cmdlet in Visual Studio, with easy iterative debugging support.

Easy Windows PowerShell cmdlet development and debugging

I've used this recipe myself quite a bit, including in on-stage presentations where you want to avoid messing up things at any cost :-). Step 1 - Create a Class Library project In Visual Studio, create a new Class Library project in the language of your choice (e.g. C#). Creating a PowerShell cmdlet – Pablo Galiano's Blog. Some time ago kzu told me about a shell extension called CleanSources, the purpose of this application is to recursive delete all the files and folders under the \bin and \obj directories for a given path.

Creating a PowerShell cmdlet – Pablo Galiano's Blog

Free Windows Powershell Community. Easy Windows PowerShell cmdlet development and debugging. Sunday, February 03, 2008 2:33 PM bart.

Easy Windows PowerShell cmdlet development and debugging

PowerShell Visual Studio 2008 templates - Download: 1.1. PowerGUI VSX - Visual Studio Gallery. Creating a Windows PowerShell CmdLet using the Visual Studio Windows PowerShell Templates - David Aiken. 1st grab the Visual Studio Templates from There are VB.NET and C# ones.

Creating a Windows PowerShell CmdLet using the Visual Studio Windows PowerShell Templates - David Aiken

(yes i did say VB.NET) Now thats downloading i'm going to walk through building, installing and running a Windows PowerShell CmdLet. The steps are simple: Download and install Windows PowerShell Download and install the Windows SDK for Vista - you will need this to install the assemblies required for Windows PowerShell. Download and install the templates I made from the link above. Sounds a lot, but its really very simple and soon you will be building cmdlets for everything. Now the templates have downloaded, extract the zip and you should find 2 vsi files - one for VB.NET and the other for C#.

They are not signed, so expect a complaint they are not signed Next load Visual Studio and create a brand new project, select Windows PowerShell as the project template. Right click the PSSnapin file and choose view code. The PSSnapin contains 5 properties which you need to complete. Get-ScriptDirectory to the Rescue - Windows PowerShell Blog. The other day I was writing a script and decided that I wanted to break it into a couple of files and have the main script dot-source a library script in the same directory. Here is the problem that I ran into: PS> Get-ChildItem Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\testMode LastWriteTime Length Name---- ------------- ------ ----d---- 6/19/2007 6:12 AM subdir-a--- 6/19/2007 6:12 AM 47 Invoke-Test.ps1-a--- 6/19/2007 6:12 AM 47 LibraryTest.ps1PS> Get-Content Invoke-Test.ps1. .

PowerShell Management Library for Hyper-V - Download: 1.00b. Create zip/compressed folders with Powershell - Mike Hodnick - Avtex Blogs for SharePoint, Microsoft CRM, .NET Development, and Infrastructure Services. I came across this Powershell blog post about adding folders and files to a zip archive, but it wasn't exactly 100% usable out of the box. Here's a slight re-work of the script that will have you zipping files from a prompt all day and all night:

Burn CD's and DVDs with Powershell - Austin Osuide's Windows Server and Random Rants Blog. Included with Microsoft Vista is a new API for scripting against optical drives; the Image Mastering API version 2 or IMAPI2. This makes it possible to retrieve information from optical storage media like CDs and DVDs and write to them. The story around the IMAPI and what you can do with it can be found on msdn but what brought it to my attention was the Scriptcenter newsletter this week where a VB sample of how to burn CDs/DVDs using the Image Mastering API was described. Yep, if we can do it with VB there's got to be a PoSHer way to do the same thing so I gave it a go and over a couple of hours managed to get my version to work. Who needs ISO burning tools anymore ay? Roll your own! My modification of the script accepts one argument which is the path to the ISO file and it barfs if a wrong path is given. The assumption is that the CD/DVD writer is first optical drive on the system (If it's not, change the msftdiscMaster2 index used in the msftdiscrecorder2 initializedrecorder method ).

Build a PowerShell cmdlet. Download source code- 9.41 KB What is Windows PowerShell? Windows PowerShell (a.k.a. Monad) is a new CLI (Command Line Interface) provided by Microsoft. PowerShell is based on .NET Framework 2.0, and passes data as .NET objects. Alan's Development Blog - Building PowerShell Cmdlets with Visual Studio 2008. I’m going to show you how easy it is to build a Windows PowerShell Cmdlet using Visual Studio 2008, C# and my PowerShell Cmdlet templates available on CodePlex.Download my Windows PowerShell Cmdlet templates from CodePlexRun the VSI installer to install the project and item templatesOpen Visual Studio 2008 and select File->New->Project From the New Project dialog select the ‘PowerShellCmdlet’ template Now right click on the project and select ‘Add New Item’.

This will show the ‘Add New Item’ dialog. You can see that there are class templates for PSCmdlets, Cmdlets, SnapIns and XML helper files. For now select the Cmdlet template. Windows PowerShell Tip: Even More Things You Can Do With Arrays.