Welcome › Forums › General PowerShell Q&A › show diskspace in servers
- This topic has 3 replies, 3 voices, and was last updated 11 months ago by
Participant.
Viewing 3 reply threads
-
AuthorPosts
-
-
February 27, 2020 at 4:00 pm #206541PowerShell1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768$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 BodyWrite-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 11 months ago by
vpmaciel67.
-
This topic was modified 11 months ago by
vpmaciel67.
-
This topic was modified 11 months ago by
kvprasoon. Reason: code formatting
-
This topic was modified 11 months ago by
-
February 28, 2020 at 1:52 am #206724
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.
-
February 28, 2020 at 11:50 am #206763
Anybody could show what I shoud put in file d1.txt for example ?
-
February 29, 2020 at 11:22 pm #206961
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.
-
-
AuthorPosts
Viewing 3 reply threads
- The topic ‘show diskspace in servers’ is closed to new replies.