Why can't Windows usernames is numbers?[BUG]
runas is int type
[root@saltstack file]# salt 'MyWindows' cmd.powershell '(Get-Process | Where-Object {$_.ProcessName -like 'Photoshop'} | Stop-Process)' runas='1201' MyWindows: Passed invalid arguments to cmd.powershell: argument of type 'int' is not iterable
Execute the passed PowerShell command and return the output as a dictionary.
Other ``cmd.*`` functions (besides ``cmd.powershell_all``)
return the raw text output of the command. This
function appends ``| ConvertTo-JSON`` to the command and then parses the
JSON into a Python dictionary. If you want the raw textual result of your
PowerShell command you should use ``cmd.run`` with the ``shell=powershell``
option.
For example:
.. code-block:: bash
salt '*' cmd.run '$PSVersionTable.CLRVersion' shell=powershell
salt '*' cmd.run 'Get-NetTCPConnection' shell=powershell
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:
- Community Wiki
- Salt’s Contributor Guide
- Join our Community Slack
- IRC on Freenode
- SaltStack YouTube channel
- SaltStackInc Twitch channel
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!
Hi @Zziwen What is your version of salt? I ran this on 3002.2
salt-call --local cmd.run '$PSVersionTable.CLRVersion' shell=powershell runas='1201' -l debug
It worked and gave me this:
[INFO ] Executing command 'Powershell -NonInteractive -NoProfile "$PSVersionTable.CLRVersion"' as user '1201' in directory 'C:\'
[DEBUG ] Unable to OpenProcess pid=4 name=System
[DEBUG ] Unable to OpenProcess pid=148 name=Registry
[DEBUG ] Token for pid does not match user sid: S-1-5-18
[DEBUG ] Unable to OpenProcess pid=564 name=smss.exe
[DEBUG ] OpenProcessToken failed pid=672 name=svchost.exe userNT AUTHORITY\SYSTEM
[DEBUG ] Unable to OpenProcess pid=780 name=csrss.exe
[DEBUG ] Unable to OpenProcess pid=884 name=wininit.exe
[DEBUG ] Unable to OpenProcess pid=900 name=csrss.exe
[DEBUG ] Unable to OpenProcess pid=984 name=services.exe
Exception ignored in: <bound method HANDLE.Close of HANDLE(0)>
Traceback (most recent call last):
File "c:\dev\salt\salt\platform\win.py", line 188, in Close
CloseHandle(self.Detach())
File "c:\dev\salt\salt\platform\win.py", line 633, in errcheck_bool
raise ctypes.WinError(ctypes.get_last_error())
OSError: [WinError 6] The handle is invalid.
[DEBUG ] output:
Major Minor Build Revision
----- ----- ----- --------
4 0 30319 42000
[DEBUG ] LazyLoaded nested.output
local:
Major Minor Build Revision
----- ----- ----- --------
4 0 30319 42000
Hi @Zziwen What is your version of salt? I ran this on 3002.2
salt-call --local cmd.run '$PSVersionTable.CLRVersion' shell=powershell runas='1201' -l debugIt worked and gave me this:
[INFO ] Executing command 'Powershell -NonInteractive -NoProfile "$PSVersionTable.CLRVersion"' as user '1201' in directory 'C:\' [DEBUG ] Unable to OpenProcess pid=4 name=System [DEBUG ] Unable to OpenProcess pid=148 name=Registry [DEBUG ] Token for pid does not match user sid: S-1-5-18 [DEBUG ] Unable to OpenProcess pid=564 name=smss.exe [DEBUG ] OpenProcessToken failed pid=672 name=svchost.exe userNT AUTHORITY\SYSTEM [DEBUG ] Unable to OpenProcess pid=780 name=csrss.exe [DEBUG ] Unable to OpenProcess pid=884 name=wininit.exe [DEBUG ] Unable to OpenProcess pid=900 name=csrss.exe [DEBUG ] Unable to OpenProcess pid=984 name=services.exe Exception ignored in: <bound method HANDLE.Close of HANDLE(0)> Traceback (most recent call last): File "c:\dev\salt\salt\platform\win.py", line 188, in Close CloseHandle(self.Detach()) File "c:\dev\salt\salt\platform\win.py", line 633, in errcheck_bool raise ctypes.WinError(ctypes.get_last_error()) OSError: [WinError 6] The handle is invalid. [DEBUG ] output: Major Minor Build Revision ----- ----- ----- -------- 4 0 30319 42000 [DEBUG ] LazyLoaded nested.output local: Major Minor Build Revision ----- ----- ----- -------- 4 0 30319 42000
My version is 3000.6, but I upgraded to 3002.2 and still have problems

Confirmed this is an issue:
- when executing the command from
salt-callscript, here's the rendered kwargs{'__kwarg__': True, 'shell': 'powershell', 'runas': '1201'}] - when executing the command from
saltscript, here's the rendered kwargs{'__kwarg__': True, 'shell': 'powershell', 'runas': 1201}], 'tgt': 'windows', 'jid': '20210125204551657963', 'ret': '', 'tgt_type': 'glob', 'user': 'sudo_eacott'}
so somewhere the runas param isn't being wrapped in a string. Will have to find that spot and we'll get a PR up for ya.
The above PR addresses this issue