I need information from the disks and network drives mapped on the server

Welcome Forums General PowerShell Q&A I need information from the disks and network drives mapped on the server

Viewing 3 reply threads
  • Author
    Posts
    • #210195
      Participant
      Topics: 8
      Replies: 8
      Points: 93
      Rank: Member
      Function sendEmail  
      { 
      param($to)
      
      # Sender and Recipient Info
      $MailFrom = "xxx@xxx.com"
      $MailTo = "xxx@xxx.com"
      $MailTo = "xxx@xxx.com"
      # Sender Credentials
      $Username = "xxx@xxx.com"
      $Password = "xxx"
      # Server Info
      $SmtpServer = "smtp.gmail.com"
      $SmtpPort = "587"
      
      # Message stuff
      $MessageSubject = $to
      $Message = New-Object System.Net.Mail.MailMessage $MailFrom,$MailTo
      $Message.IsBodyHTML = $true
      $Message.Subject = $MessageSubject
      $Message.Body = @'
      <!DOCTYPE html>
      <html>
      <head>
      </head>
      <body>
      MENSAGEM ENVIADA SOBRE O SERVIDOR.
      </body>
      </html>
      '@
      
      # Construct the SMTP client object, credentials, and send
      $Smtp = New-Object Net.Mail.SmtpClient($SmtpServer,$SmtpPort)
      $Smtp.EnableSsl = $true
      $Smtp.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
      $Smtp.Send($Message)
      }
      
      # Get SQL Server hostname
      $hostname=Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
      
      # Here I need Get all drives include network drives mapped. How to do it ?
      $Results = Get-WMIObject -ComputerName $hostname Win32_LogicalDisk | where {($_.DriveType -eq 3)}
      
      ForEach ($Result In $Results)
      {
          $drive = $Result.Name
          $space = $Result.FreeSpace
          $size = $Result.Size
          
      
          if((($space/1gb)/($size/1gb)) -le 0.901){
              $espacoLivre = ("{0:N0}" -f [math]::truncate($space/1GB))
              $espacoTotal = ("{0:N0}" -f [math]::truncate($size/1GB))    
              $espacoLivre = $espacoLivre + " GB"
              $espacoTotal = $espacoTotal + " GB"
              $mensagem = $hostname + " " + $drive + " " + $espacoLivre + " livres de " + $espacoTotal + " total."
              sendEmail $mensagem
              
          }
      }
      • This topic was modified 2 months, 3 weeks ago by vpmaciel67.
      • This topic was modified 2 months, 3 weeks ago by vpmaciel67.
    • #210801
      Participant
      Topics: 8
      Replies: 8
      Points: 93
      Rank: Member

      Someone can help me ?
      This code above show only hard disk in the server.
      I need to show network locations whith total space and used space.

    • #210804
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      Have you searched for enumerating network drives?

      PoshTip #35 – How To List Your Windows Mapped Drives?

      Also, there are easier ways to build HTML in Powershell, take a look at:

      Creating HTML Reports in Windows PowerShell

    • #210810
      Participant
      Topics: 8
      Replies: 8
      Points: 93
      Rank: Member

      thanks

Viewing 3 reply threads
  • You must be logged in to reply to this topic.