Pssession- computername vs vmname for Enter-pssession
-
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
-
OK, start by verifying you don't currently have any remote sessions.
Type
Get-PSSession
and hit enter.You should get nothing back.
Then type
New-PSSession -VMName virt3datactr
and hit enter.It should prompt for creds, display info about your new PSSession, and then return you to a normal prompt. If not, stop here and let me know.
Type
hostname
and hit enterIt should return the name of your laptop.
Type
Get-PSSession
and hit enter
You should see info about the PSSession you just created.You have started a PSSession on virt3datactr, but you are not connected to it. It's like you went to virt3datactr and launched PowerShell and walked away. It's running, you're just not there.
-
I received different results. I was prompted for credentials, but now shows I'm connected to virt3datactr, and hostname returns virt3datactr. The error is my fat fingering my password.
[Virt3datactr]: PS C:\Users\Administrator\Documents> New-PSSession -VMName virt3datactr
Windows PowerShell Credential Request: cmdlet New-PSSession at command pipeline position 1
Warning: A script or application on the remote computer VIRT3DATACTR is requesting your credentials. Enter your
credentials only if you trust the remote computer and the application or script that is requesting them.Supply values for the following parameters:
Credential
Hyper-V was unable to find a virtual machine with name "virt3datactr".
New-PSSession : The input VMName virt3datactr does not resolve to a single virtual machine.
+ CategoryInfo : InvalidArgument: (:) [New-PSSession], ArgumentException
+ FullyQualifiedErrorId : InvalidVMNameNotSingle,Microsoft.PowerShell.Commands.NewPSSessionCommand[Virt3datactr]: PS C:\Users\Administrator\Documents> hostname
virt3datactr
[Virt3datactr]: PS C:\Users\Administrator\Documents>[Virt3datactr]: PS C:\Users\Administrator\Documents> get-pssession
[Virt3datactr]: PS C:\Users\Administrator\Documents>