|
Jun
7
Written by:
Karl Prosser (MVP)
6/7/2008 12:32 AM
One thing that has bothered me about true cmdlets in contrast scripts is that they lived in SnapIns and couldn't be deployed with xcopy as scripts can because SnapIns required Registration/Installation. I build my own way to deal with this need some time ago, and thought that I'd start a blog series covering it. I call them Snapininis or SnapIn-Lites. A good thing is you can achieve the same end result in PowerShell V2 with modules - but that is V2 and a while away from being released, and then even further away from being fully deployed.
So how does this work?
1) you have to load an assembly into memory in powershell that contains your snapin.
2) you add the cmdlets directly into the runspace that is running and tell powershell to update its list of cmdlets.
Here is the C# code for a sample barebones SnapInini.
using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace Snapinini
{
public class DynamicCmdLet
{
public static void Load()
{
CmdletConfigurationEntry conf = new CmdletConfigurationEntry("dummy-cmdlet", typeof(ForeachDictionaryCmdLet), null);
Runspace.DefaultRunspace.RunspaceConfiguration.Cmdlets.Append(conf);
Runspace.DefaultRunspace.RunspaceConfiguration.Cmdlets.Update();
Runspace.DefaultRunspace.CreateNestedPipeline(
"new-alias dcmd dummy-cmdlet; write-host 'snapinini loaded'",
false).Invoke();
}
}
[Cmdlet("dummy", "cmdlet")]
public class ForeachDictionaryCmdLet : System.Management.Automation.PSCmdlet
{
protected override void EndProcessing()
{
WriteObject("hello from the dummy cmdlet");
}
}
}
In the above sample I have a very very simple cmdlet. You can see that i get the defaultrunspace, go into its RunspaceConfiguration and add the cmdlets and update the list. I am additionally running some powershell script that adds an alias to the cmdlet and writes a message to the screen just as an example showing you that you can do more stuff if you wish. In the above code the load is a static method so its easy to call from powershell once you've loaded the assembly, but in all honesty the Load() code could just as well have been written in the calling PowerShell.
So how do we load and use this in PowerShell?
[system.Reflection.Assembly]::LoadFrom("snapinini.dll")
[snapinini.DynamicCmdLet]::load()
dummy-cmdlet
dcmd
Where to from here? This example is very simple, you could easily add multiple cmdlets into the equation, specify help files, add custom type definitions etc. Another thing I had experimented with is taking a real snapin and using reflection to see the cmdlets in it and adding them directly, however unless you know exactly what a snapin does this is dangerous because in its registration it might set up a bunch of other things also that are important.
Another thing I should cover next time is a safe way to load assemblies from any location and ensure that all their references get resolved seamlessly.
-Karl
5 comment(s) so far...
Re: SnapInini - Lite portable SnapIns with no need of registration/installation.
Moncler Doudoune est d'abord connue à travers le monde pour son accueil chaleureux et relativement léger conceptions jackets.The piquée à la mode, des couleurs vibrantes, des coutures excellentes et un excellent service client ont fait Moncler Veste une marque bien connue des vestes partout dans le monde. Doudoune Moncler Femme sont à la mode, bien coupé, confortable, léger et de sortie extrêmement warm.Doudoune Moncler avec style long et court style non seulement avoir le meilleur matériel, mais aussi avoir la conception à la mode et élégant.
By doudounemoncler on
10/5/2011 10:39 PM
|
Re: SnapInini - Lite portable SnapIns with no need of registration/installation.
Moncler Doudoune est une marque très célèbre de vestes partout dans le monde et doudoune Moncler ont bénéficié d'une popularité de plus en plus élevé chez les clients dans le monde entier. Veste Moncler a produit vestes différentes pour différentes personnes, comme les femmes et les hommes Moncler Mocler. En tant que professionnel de vestes souple, Moncler Pas Cher a con?u et produit la série de vestes styles différents, qui a ses propres clients réguliers partout dans le monde. Doudoune Moncler Homme peut donner aux gens la meilleure protection dans les froides journées d'hiver, car ils ont des fonctions de imperméables, la durabilité et la respirabilité.
By doudounemoncler on
10/5/2011 10:40 PM
|
Re: SnapInini - Lite portable SnapIns with no need of registration/installation.
Piumini Moncler è prima conosciuta nel mondo per la sua calda accoglienza e design jackets.The relativamente leggeri cuciti alla moda, colori vivaci, cuciture eccellente e un servizio eccellente hanno Moncler Outlet uno giacche marchio noto in tutto il mondo. Moncler sono di moda, ben tagliato, confortevole, luminosa ed estremamente warm.Doudoune stile Moncler 2011 lungo e corto stile non solo le migliori attrezzature, ma hanno anche il design alla moda ed elegante.Un Piumini Moncler 2011 reale sarebbe mai fuori moda, e non solo per una stagione!/Moncler 2012
By doudounemoncler on
10/5/2011 10:40 PM
|
Re: SnapInini - Lite portable SnapIns with no need of registration/installation.
You just came Chanel Replicas across this really cool bumper sticker printing website that offers colorful, custom stickers at great prices. Unfortunately, Chanel Handbags you're just not sure that you want to put Chanel Bags a sticker of any kind on your Prada Handbags car. What reason would you have to do UGG so?
Trust us;Discount UGGs there are plenty of reasons to Prada Replicas smack one of these great stickers on your ride. The Prada Bags first of which is for a cause. UGGs Is there something that you feel particularly strong about? Are you completely against illegal Gucci Replicas immigration? Do you support organ and tissue donation? Are you a gun control advocate? Are you all about owning a firearm? Gucci Handbags These days there are plenty of things to be passionate UGG Boots on Sale about, from wars in foreign countries, to animal adoption. Gucci Bags People from your hometown to places on the opposite side of the country are promoting their causes with bumper sticker printing.UGG Boots
You don't want to let everyone know Louis Vuitton Replicas how you feel about the death penalty. That's okay! People are putting bumper stickers on their Christian Louboutin Shoes on Sale cars for other reasons too. Discount UGG Boots How about advertising? Do you own a business? Louis Vuitton Handbags Do you have a friend who owns a business? What about UGG Boots Outlet your parents? Individuals who own businesses are beginning to realize that it doesn't really make sense to pay for elaborate Louis Vuitton Bags and expensive advertising when you could just advertise on your own vehicle for essentially free. Bumper sticker advertising is not Discount UGG Boots only inexpensive, it's portable. If you're promoting your business from the back window of your car, then people from your house, to the mall, to the Coach Bags Outlet beach where you're planning to go this weekend will see your advertisement.UGG Boots on Sale Talk about Christian Louboutin Outlet reaching a mass market!
What about politics? Are you a Democrat who is against the new Republican congress and you're already dreaming Coach Handbags about campaigning for the future? Come up with a slogan and make it happen! Or, you can Cheap UGG Boots just promote the candidate with whom you most relate. If you're passionate about politics and you want to help your favorite candidate get the word out, a Coach Bags bumper sticker is definitely the way to go. Political stickers are almost as The North Face Outlet prevalent on the roadway as....cars! Christian Louboutin Shoes
Another type of sticker that's seen on Coach Outlet Online the roadways quite frequently is the sports team sticker. Show off your UGG Boots Volunteer Pride or your love for the Baltimore Orioles with a big, orange "T" or an "O" Discount Christian Louboutin Shoes that takes up half of the back window on your SUV. There are sports team stickers available everywhere online. If Cheap Christian Louboutin Shoes you aren't seeing one you love, a custom bumper sticker printing company can certainly produce one for you and it'll Coach Outlet be a bumper sticker you're proud to have on your car. The North Face Jackets
People also put stickers on North Face Jackets their cars for religious and spiritual reasons. From the Jesus fish, to the cross, people Coach Handbags Outlet are praising the Lord in the pew and on their bumper!
On a more somber note, people also use Coach Handbags bumper stickers to remember relatives and friends who have passed away.
If you're UGGs interested in ordering your Coach Bags Outlet own custom bumper sticker, you're making a great decision! Have a seat in front of your computer and visit a bumper sticker printing company's website. You can customize your own sticker Coach Bags or choose one from the thousands they have to offer. Don't just stop at one though! You can order stickers in bulk, which is especially handy if you're using your bumper stickers to promote your small business. Your Coach Outlet sticker order should ship The North Face Jacket within a couple of days and you'll be well on your way to showing off your cause, political affiliation, or favorite sports team! North Face Jacket
By swei on
10/13/2011 10:35 PM
|
Re: SnapInini - Lite portable SnapIns with no need of registration/installation.
Anyone blogging regularly Discount Vibram FiveFingers would love to increase their blog traffic. Targeted web Vibram Five Fingers on Sale traffic is what every webmaster craves. Cheap Christian Louboutin Shoes The process of getting your site or blog noticed by Vibram FiveFingers on Sale the search engines is often referred to as UGG SEO which stands for search engine Discount Vibram Five Fingers optimization.
When it comes to SEO there are 100's Vibram Five Fingers Outlet of methods, with in those 100's of methods Discount Christian Louboutin Shoes there are probably 1000's of strategies. The most popular method of SEO would have to be Vibram FiveFingers Link Building. Building quality Christian Louboutin Shoes on Sale one way links back to your site or blog Vibram FiveFingers Outlet can be very effective in getting UGGs the search engines attention, when done Vibram Five Fingers correctly.
I know, not Christian Louboutin Shoes everyone that's Blogging or doing any writing online Cheap UGG Boots for that matter, is doing it for a business purpose, I also know, it's a great hobby. A lot of people write Blue UGG Boots cause they feel they have a knack for it, but unfortunately no one can Christian Louboutin Outlet ever see it because it hasn't been Blue UGG Search Engine Optimized or to be a little more specific, Blue UGGs you need Backlinks. Yes, Backlinks is only part of the equation, but in my honest Red UGG opinion a solid Link Building Strategy can UGG Boots on Sale really get the search engines attention. Red UGG Boots
Think about this, you wouldn't be spending Red UGGs your valuable time working out or exercising if you knew you'd never UGG Gloves get results, so why are you Blogging/Writing, if only a handful of Discount UGGs people ever see it, you might as well just think it for that matter.
You need to get traffic to UGG Boots on Sale your Blogs and Articles if you'd like a chance of monetizing it. You can use UGG Gloves AdSense ad's or promote affiliate products to make some spare cash if your UGG Boots Blog is getting traffic too. It all comes back to traffic, and unless your paying for it, getting traffic is hard work. Building one way Backlinks to your Blog Discount UGG Boots is one of the most popular methods UGG Boots Outlet to increase Blog traffic.
You'd be surprised to know how many UGGs "Bloggers", holding no more than a High School Diploma are "6 Figure Income - Expert Writers" now because some Big- Wig saw something special in their content. Blogging is awesome, I still write at least a post a day. Nothing is Sand UGG Boots worse than pouring your heart into something Sand UGG and getting nothing out of it.
Quick Personal Experience... Sand UGGs
I love the NFL, I know a lot Navy UGG Boots about it and it's fun for me to Green UGGs write about it. When I first started Blogging I couldn't get 10 visitors a day, and it killed me because I knew Navy UGG I had a lot to offer. I knew that anyone that actually Black UGG Boots knew football would really enjoy my Blog, but I Discount UGG Boots couldn't get it to anyone. Finally I read a report about Green UGG Boots Link Building strategies and I got to work. After about Green UGG 6 weeks of blood sweat and tears and building Backlinks nearly 24/7 the traffic started to roll in. Now, I enjoy writing about the NFL weekly and it results in a steady income Black UGGs for me. Is it making me rich, no far from it, just knowing my writing is what I thought it Navy UGGs was and people are willing to pay me UGG Boots for it, has been very gratifying. Black UGG
By swei on
12/14/2011 11:09 PM
|
|
|
|
|