How to hide warnings from Azure powershell command lets

和自甴很熟 提交于 2020-02-23 10:21:07

问题


Am getting warnings when i invoke some azure commandlets. Example:

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

New-AzureStorageAccount -StorageAccountName $storageName -Location $storageLocation -ErrorAction Stop -WarningAction SilentlyContinue -verbose:$false

WARNING: GeoReplicationEnabled property will be deprecated in a future release of Azure PowerShell. The value will be merged into the AccountType property.

Please note: I have been using $verbose:False to avoid such messages from the invocation. But could not stop this WARNING from appearing.


回答1:


You could try -WarningAction Ignore, but if that doesn't work, you can redirect the warning stream, which is stream 3, to $null (or to wherever you want):

New-AzureStorageAccount -StorageAccountName $storageName 3> $null
# Left out other parameters for readability

Note that -Verbose:$false will affect verbose messages, not warnings, which are a different stream.

about_Redirection

Also note that this requires Powershell 3+:

The All (*), Warning (3), Verbose (4) and Debug (5) redirection operators were introduced in Windows PowerShell 3.0. They do not work in earlier versions of Windows PowerShell.




回答2:


I have exactly the same problem before and solve this by the follow:

New-AzureStorageAccount ... | Out-Null


来源:https://stackoverflow.com/questions/30034259/how-to-hide-warnings-from-azure-powershell-command-lets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!