Executar um comando do PowerShell silenciosamente em um prompt
Como afirmado. . .
-WindowStyle
Sets the window style for the session. Valid values are Normal, Minimized, Maximized and Hidden.
-Command
Executes the specified commands (and any parameters) as though they were typed at the PowerShell command prompt, and then exits, unless the NoExit parameter is specified. Essentially, any text after
-Command
is sent as a single command line to PowerShell
Syntax
powershell -windowstyle hidden -command <PowerShell Command String>
Exemplos verificáveis
1. Command Prompt (cmd)
powershell -windowstyle hidden -command get-childitem -path c:\ ^| out-file "C:\Folder\Log\log.txt"
Note: With cmd the [
|
] pipe symbol needs escaped with the [^
] caret symbol so "^|
".
2. PowerShell Prompt
powershell -windowstyle hidden -command get-childitem -path c:\ | out-file "C:\Folder\Log\log.txt"
Note: After running, open log.txt to verify its content since
out-file
directs it the output.