如何使用 PowerShell 取消 Azure SQL Server 上的所有导入/导出操作

Dav*_*all 5 powershell azure-powershell azure-sql-database

我正在尝试制定用于取消 Azure SQL Server 上所有挂起的导入/导出操作的 PowerShell 语法。我知道我可以使用Stop-AzSqlDatabaseActivitycmdlet,但这需要一个数据库名称(数据库可能尚不存在,因此管道Get-AzSqlDatabase无法工作)。我可以在不指定数据库而仅指定服务器的情况下执行某些操作吗?

谢谢!

Alb*_*llo 6

打开新的 PowerShell 窗口,您也可以通过单击门户屏幕右上角的 Cloud Shell 按钮在 Azure 门户上使用 Cloud Shell。

\n

在此输入图像描述

\n

复制并粘贴以下 PowerShell 代码并执行它 - 它将为当前 PowerShell 会话创建一个函数

\n
function Cancel-AzSQLImportExportOperation\n{\n    param\n    (\n        [parameter(Mandatory=$true)][string]$ResourceGroupName\n        ,[parameter(Mandatory=$true)][string]$ServerName\n        ,[parameter(Mandatory=$true)][string]$DatabaseName\n    )\n\n    $Operation = Get-AzSqlDatabaseActivity -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName | Where-Object {($_.Operation -like "Export*" -or $_.Operation -like "Import*") -and $_.State -eq "InProgress"}\n    \n    if(-not [string]::IsNullOrEmpty($Operation))\n    {\n        do\n        {\n            Write-Host -ForegroundColor Cyan ("Operation " + $Operation.Operation + " with OperationID: " + $Operation.OperationId + " is now " + $Operation.State)\n            $UserInput = Read-Host -Prompt "Should I cancel this operation? (Y/N)"\n        } while($UserInput -ne "Y" -and $UserInput -ne "N")\n\n        if($UserInput -eq "Y")\n        { \n            "Canceling operation"\n            Stop-AzSqlDatabaseActivity -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName -OperationId $Operation.OperationId\n        }\n        else \n        {"Exiting without cenceling the operation"}\n        \n    }\n    else\n    {\n        "No import or export operation is now running"\n    }\n}\n\nCancel-AzSQLImportExportOperation\n
Run Code Online (Sandbox Code Playgroud)\n

使用该功能

\n
Cancel-AzSQLImportExportOperation\xe2\x80\x8b\n
Run Code Online (Sandbox Code Playgroud)\n

要取消导入或导出操作,您需要提供当前运行该操作的资源组名称、服务器名称和数据库名称。

\n


Ven*_*dda 1

除了cmdlet之外Stop-AzSqlDatabaseActivity,您还可以使用数据库操作-取消API Rest API来取消导入或导出操作,并且您需要传递数据库名称,这是根据当前Azure文档的强制参数。