you can see my attachment pic.
which i want to switch the credentials via GUI.
But how to do it in PowerShell way?

Code: Select all
# Get credentials you want to assign to the computer inside a protection group
$creds = Get-VBRCredentials -Name 'CredsName'
# Get target protection group and a container of hosts inside it
$pg = Get-VBRProtectionGroup -Name 'ProtectionGroup'
$container = $pg.Container
# Create empty array for custom credentials
$customCredsArray = @()
# Compose new custom credentials object for the host you want to assign these creds to and add this object to custom creds array created earlier
$customCredsTarget = New-VBRIndividualComputerCustomCredentials -HostName 'HostName' -Credentials $creds
$customCredsArray += $customCredsTarget
# Loop through existing container and add all other records, which you want to leave intact, to the custom creds array
foreach ($customCreds in $container.CustomCredentials)
{
if ($customCreds.HostName -eq $customCredsTarget.HostName) {
continue
}
else {
$customCredsArray += $customCreds
}
}
# Assign new array of custom credentials to the existing container
$newContainer = Set-VBRIndividualComputerContainer -Container $container -CustomCredentials $customCredsArray
# Update the existing protection group with the changed container
Set-VBRProtectionGroup -ProtectionGroup $pg -Container $newContainer
Users browsing this forum: No registered users and 5 guests