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 !