如何隐藏Azure powershell命令中的警告

Pra*_*aja 6 powershell azure azure-storage azure-powershell

当我调用一些azure命令行开关时会收到警告.例:

Get-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -verbose:$false

New-AzureStorageAccount -StorageAccountName $storageName -Location $storageLocation -ErrorAction Stop -WarningAction SilentlyContinue -verbose:$false
Run Code Online (Sandbox Code Playgroud)

警告:Azure PowerShell的未来版本中将弃用GeoReplicationEnabled属性.该值将合并到AccountType属性中.

请注意:我一直在使用$ verbose:False来避免来自调用的此类消息.但无法阻止此警告出现.

bri*_*ist 8

您可以尝试-WarningAction Ignore,但如果这不起作用,您可以将警告流(即流 3)重定向到$null(或您想要的任何地方):

New-AzureStorageAccount -StorageAccountName $storageName 3> $null
# Left out other parameters for readability
Run Code Online (Sandbox Code Playgroud)

请注意,这-Verbose:$false将影响详细消息,而不是警告,它们是不同的流。

about_重定向

另请注意,这需要 Powershell 3+:

Windows PowerShell 3.0 中引入了全部 (*)、警告 (3)、详细 (4) 和调试 (5) 重定向运算符。它们在早期版本的 Windows PowerShell 中不起作用。