Unable to query windows process from ansible

I am working on ansible playbook where I need to add remote desktop session host on current RDS deployment. I am running below command to start servermanager process on remote server via ansible:

Invoke-CimMethod Win32_Process -MethodName create -Arguments {CommandLine="C:\Windows\System32\ServerManager.exe /p"}

It is working fine and process is being launched on remote server. I tried logging to remote server and opened task manager. I can see the process is running in task manager under details tab with my user name. But If I go to Users tab, I don’t see the process under my username.

It might be because of process launched in non-interactive session and I am looking at task manager using interactive session.

Since launching process is working fine from ansible. But when I query same process from same ansible module using below command, it doesn’t work and it gives the error:

Get-CimInstance -Query 'Select * from Win32_Process where name like "servermanager%"' - ErrorAction SilentlyContinue -ComputerName $servername

Error: A specified logon does not exist it may already have been terminated

It seems double hop issue from ansible. Can anyone help me to find the solution for this. Though remote query is working fine from other server. It is the issue via ansible only.

It could be that this topic is not relevant to this forum. But atleast please guide to resolve double hop issue from Ansible/Powershell. You can also refer me to any documentation/article/tutorial etc.

Thanks in advance
Jatinder Pal Singh (JPS)

I would wager it’s a windows station issue. The windows station services run is very isolated from interactive user stations (think of stations as logon sessions). Also if you’re trying to add session hosts to RDS there’s a purpose built cmdlet for that https://learn.microsoft.com/en-us/powershell/module/remotedesktop/add-rdsessionhost?view=windowsserver2016-ps

I am running Add-RDSessionHost cmdlet however this cmdlet only works if I am logged in to connection broker server interactively and then it adds the session host without any issue. But If I am not logged in to connection broker. I get the error that:
‘The remote desktop services deployment does not exist’
That is why I thought of starting server manager process then add the session host. Ansible is already running winrm connection with the server and RDS cmdlets also use winrm. Any suggestion to add session host without logging to connection broker. I can try that. Or any other complete solution would also work.

Can Ansible run as a user?

Yes, I tried that also. I tried my own account to run the playbook on server and choose same my own account to run as a user. But both are different. It seems my same account runs in 2 different sessions on the server.

Yeah running a process as a user vs when you elevate to admin are always going to be separate sessions.

This is just me spitballing, but isn’t there a mapped drive that represents the RDS deployment? Get-PSDrive from your user to verify. If yes, you may need to create that drive from the script via Ansible

Could you please elaborate a bit more on mapping psdrive? How it is relevant to RDS deployment. I am not aware of this.

I may be completely off base with my comment. It’s been awhile since I worked with RDS deployments. I was just wondering if there is a drive mapped that relates to RDS.
If you login the RDS server and run Get-PSDrive are there any drives pertaining to RDS? If there are they may not be getting mapped by Ansible.

How about sharing the command you ran to add the session host that you say gives you the error? Perhaps we can help with that.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.