1

I'm using the AWS Powershell tools.

When I run the following, I get a message from the cmdlet.

(Set-AWSCredentials -AccessKey $key -SecretKey $secret -StoreAs "default") > $null

I get the following message:

INFO: Credentials loaded from the supplied key parameters

How can I prevent this message from being written to the host? I attempted redirecting using *> as well, yet the message remains.

Ci3
  • 4,632
  • 10
  • 34
  • 44

2 Answers2

1

The cmdlet seems to write that info message to the host program. Something like this might work:

powershell -Command "Set-AWSCredentials -AccessKey '$key' -SecretKey '$secret' -StoreAs 'default'" >$null

When you run a command in a separate host program, the host output of that program appears in the success output stream of its parent host program.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • From The Godfather himself, http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/ – evilSnobu Oct 21 '14 at 20:36
  • @kamikatze Your comment is indeed helpful, but I decompiled the assembly and found that it invokes host.ui.writeline which is not the same as Write-Host. Meaning, if it were Write-Host, I could write a proxy command to put the object on the pipeline. Not sure what I could do with host.ui.writeline.. – Ci3 Oct 22 '14 at 17:45
0

I think you could have replaced "> $null" with "| out-null". The latter uses native Powershell pipeline control to send to null.

or,

[void](Set-AWSCredentials -AccessKey $key -SecretKey $secret -StoreAs "default")

macq
  • 19
  • 1
  • 4
  • Unfortunately that doesn't work either. I think it's related to how AWS wrote their assembly such that it writes directly to the UI. – Ci3 May 13 '15 at 20:37
  • How odd. I guess if you wanted to keep it instream to a larger script you would need to do what Ansgar suggested but with "cmd /c" preceding it in the ps1. You may have already figured this out but like: `cmd /c powershell -command set-aws... >$null` – macq May 13 '15 at 23:02