Noob Alert. Powershell 7.0.1 on Windows 10.
As part of a larger script, am trying to submit an ActiveDirectory command, that doesn’t support the -Credential option, with alternate credentials. The best way I found was using Start-Job
$CredentialAdmin = Get-Credential $DhcpScope = "10.1.0.0" $DhcpServer = "DC1" start-job -scriptBlock { Invoke-DhcpServerv4FailoverReplication -ScopeId $using:DhcpScope -ComputerName $using:DhcpServer -Confirm:$false } -WorkingDirectory $Home -credential $CredentialAdmin |Receive-Job -AutoRemoveJob -Wait
The issue I am running in to is that I still get this confirmation prompt:
The configuration of the scopes specified on host server DC1 will be replicated to the partner server. Do you want to perform this action?
[Y] Yes [N] No [?] Help (default is “Y”):
I guess I am curious why -Confirm:$false doesn’t work inside of the script block. And, is there a way I can work around it so the Invoke-DhcpServerv4FailoverReplication command will execute without prompting?
Just to try, I set $ConfirmPreference to ‘none’ inside the script block…
start-job -scriptBlock { $ConfirmPreference = "none" Invoke-DhcpServerv4FailoverReplication -ScopeId $using:DhcpScope -ComputerName $using:DhcpServer } -WorkingDirectory $Home -credential $CredentialAdmin |Receive-Job -AutoRemoveJob -Wait
…but that didn’t seem to make any difference.