mikeymikec
Lifer
I got as far as setting up sshd on Windows, configuring its default shell to be PowerShell, testing the connection successfully from the command prompt and then tested each bit of the plan in turn in PowerShell, I wrote this script to create a user (or change the user's password):
When I thought I'd up my game a bit and make it so that I didn't have to type the password for each ssh connection (because the setting I intend to use this in will have several PCs to run the script on, and yes I should write a PowerShell function with an array to cut down the amount of code for each connection), so I read up about the -credential parameter, but I kept getting a generic error saying that it couldn't be parsed with one or more parameters which I initially thought meant that the credentials for the admin account weren't being supplied correctly, but in fact.... the -credential parameter doesn't with a ssh connection. It would be nice if the official documentation said this, but the official documentation is a lovely little mess of omissions that result in lots of wasted time.
Logically at this point I'd backtrack and consider using WinRM to make the connection rather than ssh, but the documentation says "it's as easy as running these two commands to set up winrm!"... nope, can't be http, has to be https. For it to be https you've got to set up a certificate. An error message I received when attempting to set up the https connection said that the certificate can't be self-signed either. I think I've had enough for today 🙂
Code:
$cred = Get-Credential -Message "Enter the user credentials."
$username = $cred.username
$password = $cred.GetNetworkCredential().Password
$s = new-pssession -hostname 192.168.0.20 -username admin
Invoke-Command -Session $s -ArgumentList $username,$password -ScriptBlock { net user $Using:username $Using:password }
remove-pssession -session $s
$s = new-pssession -hostname 192.168.0.17 -username admin
Invoke-Command -Session $s -ArgumentList $username,$password -ScriptBlock { net user $Using:username $Using:password }
remove-pssession -session $s
When I thought I'd up my game a bit and make it so that I didn't have to type the password for each ssh connection (because the setting I intend to use this in will have several PCs to run the script on, and yes I should write a PowerShell function with an array to cut down the amount of code for each connection), so I read up about the -credential parameter, but I kept getting a generic error saying that it couldn't be parsed with one or more parameters which I initially thought meant that the credentials for the admin account weren't being supplied correctly, but in fact.... the -credential parameter doesn't with a ssh connection. It would be nice if the official documentation said this, but the official documentation is a lovely little mess of omissions that result in lots of wasted time.
Logically at this point I'd backtrack and consider using WinRM to make the connection rather than ssh, but the documentation says "it's as easy as running these two commands to set up winrm!"... nope, can't be http, has to be https. For it to be https you've got to set up a certificate. An error message I received when attempting to set up the https connection said that the certificate can't be self-signed either. I think I've had enough for today 🙂