简体   繁体   English

要导入以运行此 Powershell 命令的模块的名称

[英]Name of module to be imported to run this Powershell Command

I am trying to whitelist some IP addresses to my Azure storage account by using below powershell command我正在尝试使用以下 powershell 命令将一些 IP 地址列入我的 Azure 存储帐户的白名单

Add-AzStorageAccountNetworkRule -ResourceGroupName $rgName -Name $storageAccountName -IPRule $rule

Now this $rule object is an Array of type Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule .现在这个 $rule object 是一个类型为Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule的数组。 Link for reference is here参考链接在这里

So I am trying to create these objects using the below command所以我尝试使用以下命令创建这些对象

 New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule

I am getting below error while trying to create this object尝试创建此 object 时出现以下错误

New-Object : Cannot find type [Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule]:
Verify that the assembly containing this type is loaded.

I tried googling to import the module that has this assembly, but couldn't find any.我尝试使用谷歌搜索导入具有此程序集的模块,但找不到任何内容。 What is the module to be imported or is there any other way to fix this error?要导入的模块是什么,或者有没有其他方法可以解决此错误?

#Load Assembly https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-7.2 #加载程序集https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-7.2

using asssembly [path]
using assembly "C:\Users\administrator\Documents\PowerShell\Modules\Az.Storage\4.9.0\Microsoft.Azure.PowerShell.Cmdlets.Storage.Management.dll"

After that you can create the object之后你可以创建 object

$ipRule = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule

which gives you an object with the properties Action and IpAddressOrRange.这会为您提供一个 object,其属性为 Action 和 IpAddressOrRange。

The import-module way (module must be stored in a location known by system variable PsModulePath, otherwise you have to specify the path):导入模块方式(模块必须存储在系统变量 PsModulePath 已知的位置,否则必须指定路径):

Import-Module az.storage
$ipRule = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule

To identify which module to load for a specific cmdlet:要确定为特定 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM