Getting Powershell to shut up

  • richard.gardner87

    SSC Enthusiast

    Points: 123

    Hi, I'm hoping someone can help me with this, it's very shonky but it's what I've got currently. I'm on version 4 with 2014 r1

    So I'm calling an API through Powershell. If I run the script directly in Powershell it takes less than a second, as soon as I try and run it from XP_CMD_Shell it's taking 7 seconds plus (with quite a bit of variance).

    I've noticed that when I'm echoing the variables to screen (which is for testing only) Powershell is passing the output to SQL (SQL doesn't need the output) when I remove these variables it's much quicker.

    But for whatever reason I can't turn off the echo from the ConvertTo-Json command below. I've tried piping it to null but that just makes it null. Any ideas?

    $body = @{





























    ConvertTo-Json $body

    Aside from the obvious concerns about using xp_cmdshell (which I share, but we are where we are) any general advice about speeding this up would be greatly appreciated.


  • garry.lovesey

    SSC Veteran

    Points: 289

    With this command you are not actually doing anything with it....which is why it sends the data back to SQL and the screen. Normally you would put this into a variable such as:

    $jsonBodyVar = ConvertTo-Json $body

    This puts the value into the variable and nothing is returned to SQL or the screen. You could then write this to a log file (for testing) or whatever else you want to do with it.

  • richard.gardner87

    SSC Enthusiast

    Points: 123

    Thanks Garry,

    It does indeed not do anything. Who knew? 😉

    That's a lot quicker, at least, thanks!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply