Well, first get an SSH server on the machine. On one of my previous post I wrote about FreeSSHd, didn’t work so well with my Windows 8 machine. I’m now using Bitvise works great, and gives you a clean window. I am not use yet if I want to buy it, so I stayed with the standard version. The limitation with that is I can’t login as a domain user. I tried Get-Credential so I could pass it on New-PSsession and start a powershell session with a domain user. Well, not that easy.. Get-Credential pops up a credential window and there’s no option to pass the password in the cli. This means, remotely (or in a script).. not gonna work! not smart!!. There’s a couple of tricks to get this going but all without a few long commands. Easiest way is as follows:
Inserting Password Credential without popping window
===========================================
$pwd = ConvertTo-SecureString “PlainTextPassword” -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential (“username”, $pwd)
Now that we have the password just create a new session using $cred variable.
Start new session
=================
New-PsSession -Credential $cred
And to enter that session
Enter-PsSession <id>
Ok, if you get stuck here, and you get the nasty message that says..
New-PSSession : [localhost] Connecting to remote server localhost failed with the following error message :
The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting req….
it only means that WinRM service is not enabled. Just start force install the service and start it on the machine itself.
Enable-PSRemoting –force
or If you wanna do this remotely, try this from regular CMD..
runas /user:DOMAIN\admin “sc \\remoteComputer start winrm”
and check
(locally) :
get-service winrm or
(remotely with Domain Admin privilege):
get-service -ComputerName remoteComputer winrm
(if you’re doing that through ssh from still another remote, enter into a PS session on the target)
Enter-PSSession -Computer remoteComputer -Credential $cred
- Another helpful command i learned today is the equivalent of Grep-ing (from The Bits 2.0)
get-command | where {$_ -match “Session”}
- If you want to connect to a remote machine (having winrm running) powershell session:
Enter-PsSession -computername remotepc -Credential $cred
- Another CMD cool command to use in your remote CMD ssh, so you can run a command as a domain user..
C:\Users>runas /user:DOMAIN\admin “netdom renamecomputer ComputerName /newname:ComputerNameNew -userd:DOMAIN\adminuser -passwordd:MyPassword /reboot:05 /force as user “DOMAIN\user /reboot:05 /force”
Enter the password for conseil\ace:
Attempting to start netdom renamecomputer ComputerName /newname:ComputerNameNew -userd:DOMAIN\adminuser -passwordd:MyPassword /reboot:05 /force as user “DOMAIN\adminuser”