你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
此脚本可帮助你将本地 Windows 服务器或客户端计算机注册到恢复服务保管库。
示例脚本
<#
.SYNOPSIS
Registers MARS agent
.DESCRIPTION
Registers MARS agent
.ROLE
Administrators
#>
param (
[Parameter(Mandatory = $true)]
[String]
$vaultcredPath,
[Parameter(Mandatory = $true)]
[String]
$passphrase
)
Set-StrictMode -Version 5.0
$env:PSModulePath = (Get-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name PSModulePath).PSModulePath
Import-Module MSOnlineBackup
$ErrorActionPreference = "Stop"
Try {
$date = Get-Date
Start-OBRegistration -VaultCredentials $vaultcredPath -Confirm:$false
$securePassphrase = ConvertTo-SecureString -String $passphrase -AsPlainText -Force
Set-OBMachineSetting -EncryptionPassphrase $securePassphrase -SecurityPIN " "
}
Catch {
if ($error[0].ErrorDetails) {
throw $error[0].ErrorDetails
}
throw $error[0]
}
运行脚本
若要运行用于注册本地 Windows Server/客户端计算机的 PowerShell 脚本,请执行以下步骤:
- 使用所选
.ps1
名称和扩展在计算机上保存上述脚本。 - 通过提供以下参数运行脚本:
$vaultcredPath
- 下载的保管库凭据文件的完整路径$passphrase
- 将纯文本字符串使用 ConvertTo-SecureString cmdlet 转换为安全字符串。
注释
还需要提供从 Azure 门户生成的安全 PIN。 若要生成 PIN,请转到恢复服务保管库>设置 -属性 ->>安全 PIN,然后选择“生成”。
后续步骤
详细了解 如何使用 PowerShell 通过 MARS 代理部署和管理本地备份。