Powershellでの名前空間の使用
この質問に答えながらそれについて考えました。 名前空間内のすべての型を完全に修飾する必要をどのように回避できますか? のSystem.Security.Cryptography.X509Certificates.X509Store代わりにX509Store、またはの[System.Security.Cryptography.X509Certificates.StoreName]::My代わりに書くのは本当に、本当に退屈です[StoreName]::My。 C#にはusingディレクティブがあります... Powershellはどうですか? 編集1-これはタイプに対して機能します: $ns = "System.Security.Cryptography.X509Certificates" $store = New-Object "$ns.X509Store"(StoreName,StoreLocation) New-Objectは、型定義として文字列リテラルを使用するため、プログラムで構築できます。 編集2-これは、パラメーターとして使用される列挙型メンバーに対して機能します。 $store = New-Object "$ns.X509Store"("My","LocalMachine") 「My」[System.Security.Cryptography.X509Certificates.StoreName]::Myと「LocalMachine」は[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachineです。 リテラル名は、列挙型メンバーが必要な場所に配置されている場合、自動的に列挙型メンバーに変換されます。