When I execute a PowerShell script (.ps1) via command line, it prefixes the script with a few headers, such as:
powershell.exe -File "C:\path\to\powershell.ps1"
GAC Version Location
--- ------- --------
True v4.0.30319 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089...
I don't want to hide all output from the PowerShell script, as it does echo some useful information. I just would like to hide these headers so they do not appear on my screen or mixed in with the logs when the script runs.
If it matters, I'm using whatever PowerShell is built in to Windows 10.
Likely this happens due to call to [System.Reflection.Assembly]::Load
/ LoadFile
/ LoadFrom
/ LoadWithPartialName
method. This methods return Assembly
object, that them have load. Since PowerShell return value from every statement, not just explicit return
statement, you need to explicitly ignore that Assembly
object, so it does not get printed on console. Although, I suggest you to use Add-Type
PowerShell cmdlet to load assemblies:
Add-Type -AssemblyName System.Windows.Forms