I'm working with VBScript to check if .NET Framework 3.5 is installed on a Windows 10 machine. I'm using a PowerShell command that looks like this:
`s1 = "Powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -command "" & "`
`s2 = "{$p=$Null;$p=Get-WindowsOptionalFeature -Online -FeatureName:'NetFx3';"`
`s3 = "If($p -ne $Null){$p|Select -ExpandProperty 'Status'|Out-Host} "`
`s4 = "Else {Exit 1}}"""`
`Set oExec = oWSH.Exec(s1 & s2 & s3 & s4)`
`strRunOutput = oExec.StdOut.ReadLine()`
The problem is that if a specific computer has a PowerShell startup profile with Write-Host commands, those messages appear in my output. I thought that using `$p=$Null` was supposed to help with that, but it doesn't seem to do anything. I know I could just add `-NoProfile`, but is there a way to clear any output beforehand?
3 Answers
Just a heads up, VBScript is being deprecated, so it's good to plan a transition to PowerShell or another language if you can. It's not immediate but look for ways to reduce your dependence on VBScript in the future.
When PowerShell is executed from an external process, all output streams, including ones from Write-Host, go to standard output. That's why you're seeing extra messages. There's no way to clear output via your current `-Command` string without using `-NoProfile`, which is your best bet to avoid this output pollution.
And honestly, you might want to avoid writing new VBScript at all and focus on PowerShell exclusively if you can. If VBScript must be used, you could check the registry for the .NET Framework instead of calling PowerShell.
I think you might want to use "State" instead of "Status" in your command. It should look like this:
`Get-WindowsOptionalFeature -Online -FeatureName "NetFx3" | Select-Object -ExpandProperty State`
For clearing output, you could use the `Remove-Variable` cmdlet before running your other commands:
`Remove-Variable * -ErrorAction SilentlyContinue`
By the way, have you considered just using PowerShell directly instead of VBScript? VBScript is slowly being phased out.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically