This Visual Studio template adds a C#and/or VB.NET project template for building Windows PowerShell Cmdlets and item templates in both languages to build CmdLet derived and PSCmdLet derived Windows PowerShell Cmdlets.
The project templates are a Visual Studio class library, with references to the Windows PowerShell assemblies. They also include a PSSnapIn class, which you can customise and use to install your Windows PowerShell cmdlets.
The item templates included, create a PSCmdLet or CmdLet derived class, with the correct class attributes, a commented example of a parameter, and an empty ProcessRecord method.
If you want to build Windows PowerShell cmdlets, this template will get you started and save you time.
Note the templates are not signed.
Forum Read Only
This forum has been made read only by the site admins. No new threads or comments can be added.
-
-
Thank you for the great template there, David Aiken.
I am enjoying every bit of this template now.
-
Thanks David.
Very useful
How about a 'walkthrough' tutorial, too? I'm finding documentation on this subject is a little sparse and spread out.
Herbie -
I've just posted a short tutorial to get you started with the templates on my blog at http://blogs.msdn.com/daiken/archive/2007/02/07/creating-a-windows-powershell-cmdlet-using-the-visual-studio-windows-powershell-templates.aspx
Let me know what you are doing with PowerShell.
David -
And I made a screencast on the DFO Show.
http://channel9.msdn.com/ShowPost.aspx?PostID=281672
-
David,
I installed VS in a 'non standard' way - on my D:\ HDD. your vsi files wont install, leaving a message of:
Installation stopped because the directory for the ProjectType value did not exist. The project type is invalid for your installation of Visual Studio.
Any ideas please?
I am new to PS and cannot create and execute ANY .ps1 files. I get an error like this:
PS C:\scripts\PS> . ls
Directory: Microsoft.PowerShell.Core\FileSystem::C:\scripts\PS
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 08/06/2007 10:42 Help
-a--- 08/06/2007 11:59 18127360 abexet1.xls
-a--- 08/06/2007 15:22 1558 changeimagetype.ps1
-a--- 08/06/2007 11:17 7208826 Copy of exet1.csv
-a--- 08/06/2007 10:44 51 errors1.ps1
-a--- 08/06/2007 10:44 91 errors2.ps1
-a--- 08/06/2007 11:59 7205486 exet1.csv
-a--- 08/06/2007 12:00 0 exet1errors.csv
-a--- 04/06/2007 11:02 28562 ExetHome_Full.txt
-a--- 29/05/2007 12:47 732 ExetPS.txt
-a--- 04/06/2007 09:56 5572 ExetPS_Full.txt
-a--- 04/06/2007 11:04 0 ExetShared_Full.txt
-a--- 08/06/2007 09:25 59 myscript.PS1
PS C:\scripts\PS> . changeimagetype
PS C:\scripts\PS> changeimagetype
The term 'changeimagetype' is not recognized as a cmdlet, function, operable program, or script file. Verify the term a
nd try again.
At line:1 char:15
+ changeimagetype <<<<
The term 'changeimagetype' is not recognized as a cmdlet, function, operable program, or script file. Verify the term a
nd try again.
At line:1 char:2
+ . <<<< changeimagetype
PS C:\scripts\PS> changeimagetype .
The term 'changeimagetype' is not recognized as a cmdlet, function, operable program, or script file. Verify the term a
nd try again.
At line:1 char:16
+ changeimagetype <<<< .
PS C:\scripts\PS>
i can see so many uses for powershell but this is stopping me progressing.
thanks -
First, which version of Visual Studio are you using? It should not matter which folder you installed it into.
Second, to run powershell scripts, you need to specify the full path to the file, so your file should execute if you use the following:
c:\scripts\ps\changeimagetype.ps1
to get that on the command line quickly, you can type .\ch then press tab - which should resolve the filename.
the other thing which may stop you is the executionpolicy,
Type
get-executionpolicy
to find out what it is. It's likely set to "All Signed" which means your script would have to be signed.
You can find out how to sign scripts by typing
get-help about_signing
Alternatively, you can change the executionpolicy using
set-executionpolicy "unrestricted"
which will allow all scripts to be executed.
Hope this helps, for more info see the Powershell episodes on the DFO Show.
-
The problem I'm having with this post is where it says, "This Visual Studio template" - which template? Where? What? Is there something to click on that I'm missing?
-
It's a little hard to find. look at the end of the top section, you should see a [save] which is where the file is hidden.
-
David,
I encountered this VSTI error when I tried to install the Powershell templates:
Installation stopped because the directory for the ProjectType value did not exist. The project type is invalid for your installation of Visual Studio.
I don't see anything unusual in the .vscontent file either; just...
<Attribute name="ProjectType" value="Visual C#"/>
Visual Studio is installed on D:. I have recently installed the 180 day trial edition of the Team Foundation suite; but, beyond that, there is nothing distinctive about the installation.
Jesse -
Two items:
First, on a 64 bit XP box, the Wizard Framework dlls can get lost and not in the GAC after the SDK for vista is installed. The following link
http://www.codeplex.com/DocProject/Thread/View.aspx?ThreadId=9037 will walk someone through the solution.
Second, when starting up my first Powershell project, the designer for the PSSnapin.cs had the following complaint:
The designer must create an instance of type 'System.Management.Automation.PSSnapIn' but it cannot because the type is declared as abstract.
Hope this is useful.
-
jsinnott wrote:Second, when starting up my first Powershell project, the designer for the PSSnapin.cs had the following complaint:
The designer must create an instance of type 'System.Management.Automation.PSSnapIn' but it cannot because the type is declared as abstract.
Hope this is useful.
I got the exact same problem. Only installed the VB template. Using Vista x86, everything is up to date. -
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) -
The designer throwing an exception is a known problem, and is caused because the designer requires a concrete class, not an abstract one that PSSnapIn is.
Fortunately the only problem is the designer does not load. Viewing the code (and editing) in VS works fine. There should be no need to view in designer mode for this class. (now i've said it...)
Hope this helps. -
Thank you very much for this template.
Does this template is compatible with Visual Studio 2008, if not is it possible to create Windows PowerShell Visual Studio 2008 Templates (VB.NET).
And more is it possible to have more examples on the use of classes.