Prompt for credentials for remote replication
This commit is contained in:
17
certy.ps1
17
certy.ps1
@@ -238,6 +238,7 @@ function Invoke-Replication {
|
|||||||
[string[]]$Servers,
|
[string[]]$Servers,
|
||||||
[string]$Command,
|
[string]$Command,
|
||||||
[bool]$UseRemote,
|
[bool]$UseRemote,
|
||||||
|
[pscredential]$Credential,
|
||||||
[scriptblock]$Log
|
[scriptblock]$Log
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -261,7 +262,11 @@ function Invoke-Replication {
|
|||||||
if ($UseRemote) {
|
if ($UseRemote) {
|
||||||
if (-not $sessions.ContainsKey($server)) {
|
if (-not $sessions.ContainsKey($server)) {
|
||||||
try {
|
try {
|
||||||
$sessions[$server] = New-PSSession -ComputerName $server -ErrorAction Stop
|
if ($Credential) {
|
||||||
|
$sessions[$server] = New-PSSession -ComputerName $server -Credential $Credential -ErrorAction Stop
|
||||||
|
} else {
|
||||||
|
$sessions[$server] = New-PSSession -ComputerName $server -ErrorAction Stop
|
||||||
|
}
|
||||||
& $Log "Replication session opened: $server"
|
& $Log "Replication session opened: $server"
|
||||||
} catch {
|
} catch {
|
||||||
& $Log ("Replication session error on {0}: {1}" -f $server, $_.Exception.Message)
|
& $Log ("Replication session error on {0}: {1}" -f $server, $_.Exception.Message)
|
||||||
@@ -1132,7 +1137,15 @@ $runBtn.Add_Click({
|
|||||||
& $logAction "Replication targets empty; using primary DNS server $dnsServer."
|
& $logAction "Replication targets empty; using primary DNS server $dnsServer."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Invoke-Replication -Servers $replicationTargets -Command $replicationCmdBox.Text -UseRemote $replicationRemoteBox.Checked -Log $logAction
|
$replicationCredential = $null
|
||||||
|
if ($replicationRemoteBox.Checked) {
|
||||||
|
$replicationCredential = Get-Credential -Message "Enter credentials for replication targets."
|
||||||
|
if (-not $replicationCredential) {
|
||||||
|
& $logAction "Replication canceled: credentials not provided."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Invoke-Replication -Servers $replicationTargets -Command $replicationCmdBox.Text -UseRemote $replicationRemoteBox.Checked -Credential $replicationCredential -Log $logAction
|
||||||
if ($replicationDelaySeconds -gt 0) {
|
if ($replicationDelaySeconds -gt 0) {
|
||||||
& $logAction "Waiting $replicationDelaySeconds seconds for replication."
|
& $logAction "Waiting $replicationDelaySeconds seconds for replication."
|
||||||
Start-Sleep -Seconds $replicationDelaySeconds
|
Start-Sleep -Seconds $replicationDelaySeconds
|
||||||
|
|||||||
Reference in New Issue
Block a user