1

I have a weird problem with my script.

The goal is to display a summary of the configuration of a server, and everything went fine until I arrived to Firewall and Disk configuration.

So, if I enter this command:

Get-NetFirewallProfile | Select-Object Name, Enabled

It works, I have my Firewall status: FW_status

if I enter this command:

get-volume | Select-Object -property DriveLetter, FileSystem, {$_.size /1GB} | Where-Object {$_.DriveLetter -ne $null -and $_.FileSystem -ne "`O"}

it works too! I have my volume configuration: Volume_conf

But... If I use these commands in a script, it doesn't work anymore. If the FW command is first and volume command is second, I only have the result of the FW. If the Volume command is first, and the FW command is second, I only have the result of the Volume!

For example, if I do:

Write-host "Firewall command" -backgroundcolor green
Get-NetFirewallProfile | Select-Object Name, Enabled
Write-host "Volume command" -backgroundcolor green
get-volume | Select-Object -property DriveLetter, FileSystem, {$_.size /1GB} | Where-Object {$_.DriveLetter -ne $null -and $_.FileSystem -ne "`O"}

I have this result: FW_first

if I change the order, I have this result: Volume_First

Firewall command

Volume command
Name    Enabled
----    -------
Domain     True
Private    True
Public     True

I add that the problem is the same if I delete "Write-host" commands. I try on Powershell, Powershell ISE, and Visual Studio Code, and by using variables...Always the same result...

Does someone know what's going on, or what I do wrong?

Thanks for your help !

Luuk
  • 12,245
  • 5
  • 22
  • 33
Matt
  • 11
  • 3
  • Mixing different object types doesn't work well with the implied running of format-table. – js2010 Dec 26 '22 at 16:45
  • Sorry, I'm not so familiar with powershell yet... What do you mean exactly? Is there a way to pass throught it? – Matt Dec 26 '22 at 16:53
  • In other words, try to end both lines that start with `get`, with ` | Format-Table` (But I am that this works too.... ) – Luuk Dec 26 '22 at 16:54
  • Thanks for your help, I don't fully understand this yet, but it gave me leads to solve my problem. With the help of this topic: https://stackoverflow.com/questions/40257475/powershell-write-output-only-writes-one-object So, to make it works, I used " | out-host " after each command to display what I want. – Matt Dec 27 '22 at 09:20

0 Answers0