3

I have an IIS machine hosting some PHP that calls a Powershell file. After adding the Powercli snap in in my Powershell file, I makes a connection to vSphere.

When it does it produces some output that I don't want as this gets put on to each php output page.

Name Port User ---- ---- ---- myhostaddress.com 443 mynetwork\reporteruser

I have tried to add variables to the end to stop the feedback

Connect-VIServer -server myhostaddress.com -User $logincred.User -Password $logincred.Password  -WarningAction SilentlyContinue -ErrorAction Continue

but no use.

Is there a way to stop it. Or a clever way to call it so the output is dumped somewhere else please?

user3520245
  • 1,016
  • 1
  • 8
  • 18

3 Answers3

7

You can assign the connection to a variable to suppress the output:

$connection = Connect-VIServer -Server myhostaddress.com  -Credential $cred

Working on PS v5.

Jelphy
  • 961
  • 2
  • 11
  • 28
1

before executing, run the following code:

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
IT M
  • 359
  • 1
  • 2
  • 12
0

You can pipe the output to Out-Null:

Connect-VIServer -Server ... | Out-Null

This is the PowerShell equivalent of redirecting stdout to /dev/null in Linux (... > /dev/null).

stackprotector
  • 10,498
  • 4
  • 35
  • 64