Okay, I need an adult…
I’m attempting to write a multi-purpose script that will, among other things, rename a computer and join it to the domain. I’ve got multiple problems with the structure of the script, but here’s my most immediate issue:
The first thing I’m attempting to do is join the system to the domain. I’m trying to use workflow to perform this task so that I can (eventually) resume the script to do other things. Here’s the code:
Process { workflow Join-Domain { param ( ) # Functionality #1: Rename system & domain join InlineScript { Invoke-Command -ComputerName localhost -ScriptBlock { Add-Computer -Credential (Get-Credential) -DomainName $args[0] -PSComputerName $args[1] -NewName $args[2] -ArgumentList $domainToJoin, $TempComputerName, $ComputerName } } Restart-Computer -Wait -Timeout 30; } # Call workflow to join domain. Join-Domain;
When I run the script, I’m not prompted to enter credentials, and I get the following message:
Cannot process command because of one or more missing mandatory parameters: Credential.
I’ve tried creating a variable $CredsToUse and passing that in the -Credential switch, but I get the same error. I also attempted to pass it in as one of the $args, but I get a different, albeit similar, error:
Cannot process argument transformation on parameter ‘Credential’. A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Enter your credentials.
I’m running this with Powershell 5.1 on a Server 2016 VM.
I’m sure I’m missing some really basic concept, and I’ve Googled this voraciously but to no avail. Any help would be greatly appreciated.
Cheers,
Will