3

I am running the below cmdlet which I need to use in a script.

Connect-Pfa2Array -Endpoint 10.10.10.10 -Username pureapiuser -Password $psw -IgnoreCertificateError

I get the below output which I am trying to suppress. I just need for the cmdlet to make the connection. Is there a way this can be done? I checked the cmdlet and did not see an option to do a silent connection.

ArrayName    ApiVersion
---------    ----------
10.100.24.50 2.2 
SQL Novice
  • 193
  • 8

1 Answers1

5

As Santiago Squarzon mentioned, there are a couple of options you can use:

[void](Connect-Pfa2Array ... )

or

Connect-Pfa2Array | Out-Null

or

Connect-Pfa2Array > $null

or

$null = Connect-Pfa2Array
mklement0
  • 382,024
  • 64
  • 607
  • 775
Alex_P
  • 2,580
  • 3
  • 22
  • 37
  • 2
    Nicely done, though not all of these approaches are created equal; overall, `$null = ...` is the best general-purpose solution, while `| Out-Null` should be avoided for performance reasons - see [this answer](https://stackoverflow.com/a/55665963/45375) to a closely related question. – mklement0 May 14 '21 at 21:33
  • @mklement0 I like you mention not using the pipeline alternative for efficiency, it's hard for me to understand why do newcomers to PS (including myself at some point) get obsessed with using pipeline alternatives everywhere they can when there are more classic and efficient approaches of doing things :P – Santiago Squarzon May 14 '21 at 21:57
  • 1
    @SantiagoSquarzon, that is understandable, given that the pipeline is a very elegant _concept_, and it would be great if it didn't carry a performance penalty, but it invariably does (at least as currently implemented; conceivably, PowerShell could convert purely _expression_-based pipelines into more efficient constructs behind the scenes); conversely, the pipeline enables memory-efficient, streaming solutions (unless the result is collected in memory in full in the end anyway). – mklement0 May 14 '21 at 22:07