Pssession- computername vs vmname for Enter-pssession
-
I can't connect to a hyperv session if i use
Enable-PSremoting
New-PSSession -ComputerName virt3datactr
Enter-PSSession -ComputerName virt3datactrI receive "a specified login does not exist or it may have been terminated. Error 0x8009030e
My googling returns specific scenarios that do not fix my issue.
I can run the same cmdlet using -vmname. What is the difference I am seeing? I have verified my computer name is virt3datactr in server manager on the vm and the server is in a workgroup.
-
Hey @John-DeWilde ,
I need some more information to help you. When you say you cannot connect to a Hyper-V session, do you mean connect to a virtual machine on a Hyper-V server or connect to the Hyper-V server itself? If you are trying to connect to a VM, are you connecting from the Hyper-V server or a remote machine?
The
Enable-PSRemoting
cmdlet is run on the destination machine, and only needs to be run once. This configures the machine to accept inbound connections.The
-VMName
parameter is referring to the name that appears in the Hyper-V console. This is a display name only, it might not be the same as the actual hostname of the VM. For example, in my Hyper-V console, there is a VM with the name ITProTVDemoSync. The hostname of the machine is svr01. You can right-click on a VM in the Hyper-V console and rename it. This does not change the hostname of the VM, just the display name in the console.When I run
Enter-PSSession
from the Hyper-V host, I use the-VMName
parameter, the Hyper-V host knows what VMs exist (Get-VM
on the Hyper-V host will return a list). But if I runEnter-PSSession
from my laptop to connect to the same VM, I use-ComputerName
. My laptop doesn't know its a VM, just sees it as another machine on the network. The parameters-ComputerName
and-VMName
are just ways to identify the machine you are trying to connect to. Which one you use depends on where you are connecting from.You also have to think about the credentials being used. Since you are using workgroups, the credentials you are logging in to the Hyper-V host don't have permissions on the VM. You will need to use the
-credentials
parameter.Enter-PSSession -VMName ITProTVDemoSync -Credential demo\mike
It will prompt you for a password.
You also need to add the destination machine to the TrustedHosts list on your local machine. The machine you are connecting from needs to trust the remote machine in order to send credentials. If you are connecting to a VM from the Hyper-V server, you can skip this.
For example, on my laptop, I want to connect to dc01 and svr01, so I must tell my laptop it is ok to send credentials to those machines.
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "dc01,svr01"
You can check your TrustedHosts list using
Get-Item WSMan:\localhost\Client\TrustedHosts
I know that is a lot of information to digest, I would suggest taking one step at a time. First, let's get more information so I know exactly what you are trying to do.
- Where are you connecting from, the Hyper-V server itself or another machine on the network?
- Can you copy and paste the error message you are getting?
-
Hi Mike,
Thank you...
I thought Enable-Pssremoting was run on the machine attempting to connect to the remote machine. At least that's what the demo I'm watching is showing.
I'm sure I'm missing something simple, but I'll outline my steps.
I'm trying to connect from a hyper-v server (my laptop) to a vm. If I use -vmnname I can connect to the vm/remote machine. If I use -computername I get errors.
1. Enable-Pssession
PS C:\WINDOWS\system32> Enable-PSremoting
WinRM has been updated to receive requests.
WinRM service started.Set-WSManQuickConfig : <f:WSManFault
xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113"
Machine="localhost"><f:Message><f:ProviderFault provider="Config provider"
path="%systemroot%\system32\WsmSvc.dll"><f:WSManFault
xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113"
Machine="DESKTOP-KCG0J0V.NOTATIONS.COM"><f:Message>WinRM firewall exception will
not work since one of the network connection types on this machine is set to
Public. Change the network connection type to either Domain or Private and try
again. </f:Message></f:WSManFault></f:ProviderFault></f:Message></f:WSManFault>
At line:116 char:17-
Set-WSManQuickConfig -force
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (:) [Set-WSManQuickConfig], Inva
lidOperationException - FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuic
kConfigCommand
- CategoryInfo : InvalidOperation: (:) [Set-WSManQuickConfig], Inva
2. New-PSSession -computername virt3datactr
PS C:\WINDOWS\system32> New-PSSession -computername virt3datactr
New-PSSession : [virt3datactr] Connecting to remote server virt3datactr failed
with the following error message : WinRM cannot process the request. The
following error with errorcode 0x8009030e occurred while using Kerberos
authentication: A specified logon session does not exist. It may already have
been terminated.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does
not exist.
-The client and remote computers are in different domains and there is no
trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM
TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command:
winrm help config. For more information, see the about_Remote_Troubleshooting
Help topic.
Other Possible Cause:
-The domain or computer name was not included with the specified credential,
for example: DOMAIN\UserName or COMPUTER\UserName.
At line:1 char:1- New-PSSession -computername virt3datactr
-
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:Remo teRunspace) [New-PSSession], PSRemotingTransportException + FullyQualifiedErrorId : 1312,PSSessionOpenFailed
3. Enter-PSSession -ComputerName virt3datactr
PS C:\WINDOWS\system32> Enter-PSSession -ComputerName virt3datactr
Enter-PSSession : Connecting to remote server virt3datactr failed with the
following error message : WinRM cannot process the request. The following error
with errorcode 0x8009030e occurred while using Kerberos authentication: A
specified logon session does not exist. It may already have been terminated.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does
not exist.
-The client and remote computers are in different domains and there is no
trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM
TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command:
winrm help config. For more information, see the about_Remote_Troubleshooting
Help topic.
At line:1 char:1- Enter-PSSession -ComputerName virt3datactr
-
+ CategoryInfo : InvalidArgument: (virt3datactr:String) [Enter-PSSe ssion], PSRemotingTransportException + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
-
-
I added virt3datactr to the trustedhosts list, and confirmed it was listed. Still receive the same errors.
I also misread your post, and went back to the machine I want to connect to. I ran Enable-Psremoting which started successfully. I went back to my hyper-v server and tried running the New-PSSession -computername virt3datactr and Enter-PSSession -ComputerName virt3datactr again. I received the same errors I posted earlier.
-
OK. Lets take it one step at a time.
From Microsoft:
Enable-PRRemoting: Configures the computer to receive remote commands.
Definitely run on the destination machine. Let me know what demo you are referring to, so I can fix it.
Sounds like you ran it successfully on virt3datactr, so we are good there.
If you are curious about why it failed on your laptop, it's because your network profile is set to public. But it doesn't matter, since you are not connecting to your laptop using PSSessions.
-
Now that virt3datactr is configured to accept remote commands, lets try to connect to it.
First, lets see if we have any existing sessions.
From PowerShell on your Hyper-V host (your laptop) type the following:
Get-PSSession
You should not get anything back.
Let me know if this works.
-
So far so good. I received nothing when I ran get-pssession on my laptop.
-
Good.
Next, run this command on your Hyper-V host (your laptop):
Get-VM
Lets verify the name of your VMs. Seems silly, but we want to eliminate all possible issues.
Make sure the name of the VM reports back as virt3datactr.
-
@Mike-Rodrick I think spelling of names is ok.
PS C:\WINDOWS\system32> Get-VM
Name State CPUUsage(%) MemoryAssigned(M) Uptime Status
Centos Off 0 0 00:00:00 Operating ...
Virt1dc Running 0 1092 23:49:02.7930000 Operating ...
Virt2mbr Off 0 0 00:00:00 Operating ...
Virt3datactr Running 0 4000 23:49:03.1420000 Operating ...
virt4datactr Off 0 0 00:00:00 Operating ...
vm02 Off 0 0 00:00:00 Operating ... -
OK. Now let's try to create a temporary session first. Type the following command on your Hyper-V host (your laptop):
Enter-PSSession -VMName virt3datactr
Notice we did not use
New-PSSession
That will come later.
Let me know what happens. -
@Mike-Rodrick said in Pssession- computername vs vmname for Enter-pssession:
Enter-PSSession -VMName virt3datactr
Worked like a charm, returned a credentials window and allowed me to login. Ok at least that has been consistently available.
PS C:\WINDOWS\system32> Enter-PSSession -VMName virt3datactr
cmdlet Enter-PSSession at command pipeline position 1
Supply values for the following parameters:
Credential
[Virt3datactr]: PS C:\Users\Administrator\Documents> -
Great!
Now we have a temporary PSSession to virt3datactr. As long as the PS prompt starts with [Virt3datactr], any commands issued will be sent to the remote machine.
Lets first verify the hostname of the VM. Then we can look at what I mean by temporary session.
Type the following command
hostname
Does it return virt3datactr?
-
@Mike-Rodrick yes it does
-
Good.
Now lets look at what is meant by a temporary session, and how variables are deleted at the end of a temporary session (not persistent)Type the following
$h = hostname
and hit enter. You should get nothing back.This command stores the hostname in the variable $h.
We can now use the variable anywhere we need the hostname.
Type the following:
$h
and hit enter. It should return the hostname.Type the following:
ping $h
and hit enter. It should ping virt3datactr.After all of this, you are still connected in a temporary session to virt3datactr (your prompt should indicate this)
Let me know if this works and makes sense.
-
@Mike-Rodrick Set the variable to hostname and pinged. Yes it makes sense so far
-
Good.
Everything you have been typing is happening on the remote machine. Even though you are looking at the same PowerShell window on your laptop. You are really in a PowerShell window (session) that exists on virt3datactr. It's like you were logged on to virt3datactr and launched PowerShell.
Now type this:
exit
and hit enter.Exit is an alias for the command Exit-PSSession. This should end your temporary session, and return you to a normal PS prompt.
Once you are back to a normal PS prompt, you are no longer connected to virt3datactr.
Type the following:
$h
and hit enter.You should get nothing back. This is because $h was created and only existed in the PSSession on virt3datactr, to which you are no longer connected.
Let me know if that worked and makes sense
-
@John-DeWilde And I think I get the temporary part. After reading your explanations about 15 times...not kidding it began to sink in. I guess I was my own worst enemy, and thought well, I'm creating a variable, and it will be there whenever i need it.
-
After running exit I received nothing for $h
-
Great! Easy to do, it can get really confusing.
Now let's reconnect to virt3datactr.
Type the following:
Enter-PSSession -VMName virt3datactr
and hit enter.Your prompt should change to show that you are connected again.
Type the following:
$h
and hit enter. It shouldn't return anything. Even though you are connected again. The variable was deleted when you exited your session, and you would need to recreate it. It's like you closed the PowerShell window on the remote machine.Once you are good with that concept. exit the session, and return to a normal prompt. Next we can look at creating a persistent connection.
-
It returned nothing as you said it would