Hello, I have the following script to be able to see the disk space. I am completely new to programming in powershell.
Right now the script exports two html files with the information I want, but I wanted it to export everything in one file. can someone help?

#Lista de Computadores a monitorar
$listaServidores = @("srvcl02","l-it3")

foreach($servidor in $listaServidores) {
  Get-WMIObject -ComputerName $servidor Win32_LogicalDisk |
 
  where{($_.DriveType -eq 3)}|
  #seleciona os atributos a mostrar e faz a devida formatação
  select @{n='Servidor' ;e={"{0:n0}" -f ($servidor)}},
  @{n='Drive' ;e={"{0:n0}" -f ($_.name)}},
  @{n='Capacidade' ;e={"{0:n2} Gb" -f ($_.size/1gb)}},
  @{n='Livre';e={"{0:n2} Gb" -f ($_.freespace/1gb)}},
  @{n='Percentagem';e={"{0:n2}%" -f ($_.freespace/$_.size*100)}}   |`
      ConvertTo-Html | `
      #Formata o nome do ficheiro
      Out-File ("C:\Temp\AnaliseDisco_{0}_{1}.html" -f $servidor`
      ,(Get-Date -Format "ddMMyyyy"))
}
2 Spice ups

Welcome.

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

I already put it like you said, thanks

Your code specifically tells it to create a new file for each server.

try like so:

#Lista de Computadores a monitorar
$listaServidores = @("srvcl02", "l-it3")

foreach ($servidor in $listaServidores) {
    Get-WMIObject -ComputerName $servidor Win32_LogicalDisk |
     Where-Object { ($_.DriveType -eq 3) } |
    #seleciona os atributos a mostrar e faz a devida formatação
    Select-Object @{n = 'Servidor' ; e = { "{0:n0}" -f ($servidor) } },
    @{n = 'Drive' ; e = { "{0:n0}" -f ($_.name) } },
    @{n = 'Capacidade' ; e = { "{0:n2} Gb" -f ($_.size / 1gb) } },
    @{n = 'Livre'; e = { "{0:n2} Gb" -f ($_.freespace / 1gb) } },
    @{n = 'Percentagem'; e = { "{0:n2}%" -f ($_.freespace / $_.size * 100) } } |
    ConvertTo-Html | 
    Out-File ("C:\Temp\AnaliseDisco_Servers_{1}.html" -f $servidor, (Get-Date -Format "ddMMyyyy")) -Append
}

Thank you very much for wasting some time trying to help me, but the titles were repeated and I wanted him to do the listing by server. In fact this is all to add to an inventory script that I am creating, but I am having an extremely difficult time creating and then exporting everything.
Not even that simple of the discs can I export.

since you are outputting with server names you will get multiples files based on the name of the servers, change it to

Out-File "C:\temp\AnaliseDisco $(Get-Date -Format "ddMMyyyy").html" -Append
1 Spice up

huh_small.jpg

I’m not following?

it creates this for me:

2021-03-02_10-53-42.pngHow do you want it?

oh so you just want the data, not the titles again?

Use google translator to speak english. I’m sorry that’s not what I meant. Just, thank you so much for your help

That’s right, thank you.

I think in mine he had written over it. So it had been duplicated.

Thank you for your help.

try like so:

#Lista de Computadores a monitorar
$listaServidores = "srvcl02","l-it3"

$report =
foreach ($servidor in $listaServidores) {
    $data = Get-WMIObject -ComputerName $servidor Win32_LogicalDisk | Where-Object { ($_.DriveType -eq 3) }
    foreach ($drive in $data) {
        [pscustomobject]@{
            Servidor    = $servidor
            Drive       = $drive.name
            Capacidade  = [math]::Round($drive.size / 1gb, 2)
            Livre       = [math]::Round($drive.freespace / 1gb,2)
            Percentagem = "$([math]::Round(($drive.freespace / $drive.size * 100),2))%"
        }
    }
}

$report | 
ConvertTo-HTML |
out-file ".\AnaliseDisco_$(Get-Date -Format "ddMMyyyy").html"

2021-03-02_11-05-12.png

No worries, English is not my first or second language either :¬)

It was perfect, that’s what I wanted. Thank you very much.