show diskspace in servers

Welcome Forums General PowerShell Q&A show diskspace in servers

Viewing 3 reply threads
  • Author
    Posts
    • #206541
      Participant
      Topics: 8
      Replies: 8
      Points: 93
      Rank: Member
      $User = "user"
      $PWord = ConvertTo-SecureString -String "1234" -AsPlainText -Force
      $cred1 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
      $cred2 = $cred1
      $cred3 = $cred1
      
      # Custom HTML Report Formatting
      $html = "<style>"
      $html = $html + "BODY{background-color:#b0c4de;}"
      $html = $html + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
      $html = $html + "TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#778899}"
      $html = $html + "TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}"
      $html = $html + "tr:nth-child(odd) { background-color:#d3d3d3;}"
      $html = $html + "tr:nth-child(even) { background-color:white;}"
      $html = $html + "</style>"
      
      # Script Variables
      $ErrorActionPreference = "SilentlyContinue"
      $SizeInGB=@{Name="Size(GB)"; Expression={"{0:N2}" -f ($_.Size/1GB)}}
      $FreespaceInGB=@{Name="Freespace(GB)"; Expression={"{0:N2}" -f ($_.Freespace/1GB)}}
      $PercentFree=@{name="PercentFree(%)";Expression={[int](($_.FreeSpace/$_.Size)*100)}}
      
      # Script Body
      Write-Output "Gathering Disk Usage Information..."
      $Domain1Servers = @(
      'server1'
      'server2'
      )
      
      $Domain2Servers = @(
      'server3'
      'server4'
      )
      
      $WorkGroupServers = @(
      'Server5'
      'Server6'
      )
      
      $AdminName1 = "domain1\user"
      $AdminName2 = "domain2\user"
      $AdminName3 = "workgroupuser"
      
      #What do I should put in these files d1.txt and d2.txt and d3.txt ?
      
      $Domain1 = Get-Content "d:\diskspace\d1.txt" | ConvertTo-SecureString
      $cred1 = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName1, $Domain1
      
      $Domain2 = Get-Content "d:\diskspace\d2.txt" | ConvertTo-SecureString
      $cred2 = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName2, $Domain2
      
      $Domain3 = Get-Content "d:\diskspace\d3.txt" | ConvertTo-SecureString
      $cred3 = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName3, $Domain3
      
      $WMIQuery = "SELECT SystemName,Caption,VolumeName,Size,Freespace FROM win32_logicaldisk WHERE DriveType=3"
      
      $Domain1Disk = Get-WmiObject -Query $WMIQuery -ComputerName $Domain1Servers -Credential $cred1
      $Domain2Disk = Get-WmiObject -Query $WMIQuery -ComputerName $Domain2Servers -Credential $cred2
      $WorkGroupDisk = Get-WmiObject -Query $WMIQuery -ComputerName $WorkGroupServers -Credential $cred3
      
      ( $Domain1Disk + $Domain2Disk + $WorkGroupDisk ) |
      Select-Object -Property SystemName,Caption,VolumeName,$SizeInGB,$FreespaceInGB,$PercentFree |
      sort-object "SystemName" |
      ConvertTo-Html -as table -head $html -body "
      
      Server Disk Space Report $(( get-date ).ToString('dd/MM/yyyy'))
      "|
      Out-File "d:\diskspace\reports\ServerDiskSpaceReport--$(( get-date ).ToString('yyyyMMdd')).html"
      
      • This topic was modified 3 months ago by vpmaciel67.
      • This topic was modified 3 months ago by vpmaciel67.
      • This topic was modified 3 months ago by kvprasoon. Reason: code formatting
    • #206724
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      It is hard to gues what you’re actually asking. Please go back and fix your post by formatting your code correctly as code. And try to ask a clear technical question. You should keep in mind that we cannot see your screen and we cannot read your mind.

      Thanks.

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

      Anybody could show what I shoud put in file d1.txt for example ?

    • #206961
      Participant
      Topics: 0
      Replies: 1
      Points: 27
      Rank: Member

      The text file d1.txt is piped to ConvertTo-SecureString on line 46 and then used as a secure string password on line 47 when creating a credentials object.

      I’d say the text file d1.txt is supposed to contain the plain text password for the user account specified on line 40 which is then used to access the machines from the array on line 25.

Viewing 3 reply threads
  • The topic ‘show diskspace in servers’ is closed to new replies.