You are reading an unmaintained version of the Ansible documentation. Unmaintained Ansible versions can contain unfixed security vulnerabilities (CVE). Please upgrade to a maintained version. See the latest Ansible documentation.
win_command - Executes a command on a remote Windows node¶
The win_command module takes the command name followed by a list of space-delimited arguments.
The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $env:HOME and operations like "<", ">", "|", and ";" will not work (use the win_shell module if you need these features).
For non-Windows targets, use the command module instead.
-name:Save the result of 'whoami' in 'whoami_out'win_command:whoamiregister:whoami_out-name:Run command that only runs if folder exists and runs from a specific folderwin_command:wbadmin -backupTarget:C:\backup\args:chdir:C:\somedir\creates:C:\backup\
If you want to run a command through a shell (say you are using <, >, |, etc), you actually want the win_shell module instead. The win_command module is much more secure as it’s not affected by the user’s environment.
creates, removes, and chdir can be specified after the command. For instance, if you only want to run a command if a certain file does not exist, use this.
For non-Windows targets, use the command module instead.
For more information about Red Hat’s this support of this module, please
refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>