Equivalent to C#'s “using” keyword in powershell?

前端 未结 9 1911
臣服心动
臣服心动 2020-12-04 14:13

When I use another object in the .net-Framework in C# I can save a lot of typing by using the using directive.

using FooCompany.Bar.Qux.Assembly.With.Ridicul         


        
9条回答
  •  Happy的楠姐
    2020-12-04 14:43

    There's really nothing at the namespace level like that. I often assign commonly used types to variables and then instantiate them:

    $thingtype = [FooCompany.Bar.Qux.Assembly.With.Ridiculous.Long.Namespace.I.Really.Mean.It.Thingamabob];
    $blurb = New-Object $thingtype.FullName
    

    Probably not worth it if the type won't be used repeatedly, but I believe it's the best you can do.

提交回复
热议问题