.net - Equivalent to C#'s "using" keyword in powershell? -
When I use any other object in .NET-framework in C # I can save
with Fu Companie.Br.QX.ASAP Assemblies. Redicquil clove. Namespace.i.Sachmuch Pisces. ... var blurb = new thingomobobe (); ...
So what is a way to do something in a parsehale? I'm reaching a lot of pure things and I'm not happy to type.
$ blurb = new-object FooCompany.Bar.Qux.Assembly.With.Ridiculous.Long.Namespace. I.Really.Mean.It.Thingamabob;
all the time.
View this blog post some years ago:
here add -types.ps1
is quoted from that article:
param ([string] $ assemblyName = $ ('assembly name is required'), [object] $ object) process {If ($ _) {$ object = $ _} if {throw 'object'} to load an object parameter or 'pipe' in a # $ dll = $ assembly = [System.Reflection.Assembly]: : LoadWithPartialName ($ assembly name) # Add property as member asset $ assembly. GetTypes () | Where {$ _. Ispublic- And! $ _.} IsSubclassOf ([exception]] and $ _ Name -Notmatch "Event"} | In case of foreach {# avoiding error messages, it is already present if (($ ($ object | member $ _. Name)) {add-member note-agent $ _. Name $ _ -inputobject $ object}}}
And, to use it:
RICBERG470> $ TFS | Add-type "Microsoft. TAM Foundation. Version Control. Client" RICBERG470 & gt; $ ItemSpec = new-object $ tfs.itemspec ("$ / foo", $ tfs.RecursionType :: none)
What do I actually do for the Assentrial type assembly
> Html>
Comments
Post a Comment