Search code examples
powershellnamespacesusing

Powershell: does ps4.0 has "using namespace" semantics or its equivalence?


I find it not possible to use using namespace in powershell 4.0? Thanks.


Solution

  • You need to write full namespaces to use a class within. Say [System.IO.File]. Or you can omit System, but not anything else. Or you can use a variable as in here to save you typing and compute the fully qualified class name at runtime:

    $ns="System.Security.Cryptography.X509Certificates"
    $store = New-Object "$ns.X509Store"(StoreName,StoreLocation)
    

    There is no "using namespace" in Powershell.