[英]Powershell - command was found in the module, but the module could not be loaded
[英]Name of module to be imported to run this Powershell Command
我正在嘗試使用以下 powershell 命令將一些 IP 地址列入我的 Azure 存儲帳戶的白名單
Add-AzStorageAccountNetworkRule -ResourceGroupName $rgName -Name $storageAccountName -IPRule $rule
現在這個 $rule object 是一個類型為Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule
的數組。 參考鏈接在這里
所以我嘗試使用以下命令創建這些對象
New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule
嘗試創建此 object 時出現以下錯誤
New-Object : Cannot find type [Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule]:
Verify that the assembly containing this type is loaded.
我嘗試使用谷歌搜索導入具有此程序集的模塊,但找不到任何內容。 要導入的模塊是什么,或者有沒有其他方法可以解決此錯誤?
using asssembly [path]
using assembly "C:\Users\administrator\Documents\PowerShell\Modules\Az.Storage\4.9.0\Microsoft.Azure.PowerShell.Cmdlets.Storage.Management.dll"
之后你可以創建 object
$ipRule = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule
這會為您提供一個 object,其屬性為 Action 和 IpAddressOrRange。
導入模塊方式(模塊必須存儲在系統變量 PsModulePath 已知的位置,否則必須指定路徑):
Import-Module az.storage
$ipRule = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule
要確定為特定 cmdlet 加載哪個模塊:
#Ask get command about the cmdlet
get-command [cmdlet]
get-command Add-AzStorageaccountnetworkrule
#Source tells you where it is coming from
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-AzStorageAccountNetworkRule 4.9.0 Az.Storage
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.