【问题标题】:Check if table exists in azure storage powershell检查 azure storage powershell 中是否存在表
【发布时间】:2018-10-18 06:31:28
【问题描述】:

我有这个 powershell,我想使用它在 azure 存储帐户中创建新表。

Param(
 [string]$rgName,
 [string] $tableName
 )
 $storcontext= New-AzureStorageContext -ConnectionString '$(MyConnectionString)'

if(!(Get-AzureStorageTable -Name $tableName -Context $storcontext ))
 {
   New-AzureStorageTable -Name $tableName -Context $storcontext
 }

New-AzureStorageTable 命令完美运行。但是我尝试添加检查表是否已存在。但是在 Get 命令上,powershell 告诉我表不存在。

我要做的是检查表是否存在,如果不存在,则创建它。

还有其他方法吗?

【问题讨论】:

  • powershell中如何检查表中是否存在列?

标签: powershell azure azure-storage azure-powershell


【解决方案1】:

如果表不存在,cmdlet 会引发错误,因此您可以将 ErrorAction 设置为 SilentlyContinue 并为可以检查的错误指定一个变量:

Get-AzureStorageTable -Name $tableName -Context $storcontext -ErrorVariable ev -ErrorAction SilentlyContinue
if ($ev) {
New-AzureStorageTable -Name $tableName -Context $storcontext
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    • 2020-07-22
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多