I have a script to gerate information inside a folder.
Very basic example:
PS C:\Users\> write-host "teste"
teste
PS C:\Users\>
I want open powershell in silent mode, paste the write-host "teste"
command and only show the result:
teste
Also, I don't want the PS C:\Users\>
I know I can create a ps1 script and run, but I need to navigate manually through PowerShell.
Resume: I don't want to see what I type in PowerShell command line, only the result.
If possible, turn on and turn off after execution, something like it:
PS C:\Users\> <enable silent mode>
(I paste the commands here, but is not showed in the powershell command line)
teste
<disable silent mode>
PS C:\Users\> now I can work again....
About the first comment, this is the reason. How I see after paste the commands:
PS C:\Users> set-location C:\Users\xxxxxxxxxxxxxx
PS C:\Users\> $ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
PS C:\Users\> $CUR_DIR = "spool ""$pwd\"
PS C:\Users\> $DIR = ($CUR_DIR| Select-String -Pattern "(?<!;)XX.*").Matches.Value.replace('\','')
PS C:\Users\> write-host $CUR_DIR$DIR".log"""
spool "C:\Users\xxxx.log"
PS C:\Users\> set-location xxxxxxxxxxxx
PS C:\Users> foreach ($row in $(Get-ChildItem| % { $_.FullName }| Sort-Object $ToNatural))
>> {
>> write-host "@""$row"""
>> write-host "show erros"
>> }
@"C:\Users\xxxxxxxxxx.txt"
show erros
@"C:\Users\xxxxxxxxxx.txt"
show erros
@"C:\Users\xxxxxxxxxx.sql"
show erros
PS C:\Users\xxxxxxxxxxxxxx> cd ..
PS C:\Users\> write-host "spool off"
spool off
PS C:\Users\>
PS C:\Users\> foreach ($row in $(Get-ChildItem| % { $_.FullName }| Sort-Object $ToNatural)|Select-String 'registro')
>> {
>> write-host "@""$row"""
>> }
@"C:\Users\xxxxxxxxxxxxxx\xxxxx.txt"
PS C:\Users\>
I'd like to see:
PS C:\Users> set-location C:\Users\xxxxxxxxxxxxxx
PS C:\Users\> <enable silent mode>
spool "C:\Users\xxxx.log"
@"C:\Users\xxxxxxxxxx.txt"
show erros
@"C:\Users\xxxxxxxxxx.txt"
show erros
@"C:\Users\xxxxxxxxxx.sql"
show erros
spool off
@"C:\Users\xxxxxxxxxxxxxx\xxxxx.txt"
<disable silent mode>
PS C:\Users\> now I can work again....
I have replaced some information with xxx to don't show customer content.
command_here >NULL
where in powershell, you would do something like$Null = command_here
will show no output and still run the command. Is that what you are asking? @Aganju ... I pipe STDOUT and STDERR commands to null all of the time in every language I code in and I don't write viruses.