When it I run the following script, works perfectly but the email appears as such -<\/p>\n
Many thanks!<\/p>","upvoteCount":3,"answerCount":6,"datePublished":"2020-06-01T11:27:58.000Z","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"},"acceptedAnswer":{"@type":"Answer","text":"
Redid the script with these suggestions and ideas -<\/p>\n
$a = @\"\n<style>\nTABLE{border-width: 1px;border-style: solid;border-color:black;}\nTable{background-color:#DFFFFF;border-collapse: collapse;}\nTH{border-width:1px;padding:10px;border-style:solid;border-color:black;}\nTD{border-width:1px;padding-left:10px;border-style:solid;border-color:black;}\nTD{border-width:1px;padding-right:10px;border-style:solid;border-color:black;}\n</style>\n\"@\n$PC = $env:COMPUTERNAME\nfunction Result {\n $PCs = $env:COMPUTERNAME\n $drives = Get-WmiObject Win32_LogicalDisk -filter \"DriveType=3\" -ComputerName $PC | \n Select SystemName,DeviceID,@{Name=\"Size(GB)\";Expression={\"{0:N0} GB\" -f ($_.size / 1GB) } },@{Name=\"FreeSpace(GB)\";Expression={ \"{0:N0} GB\" -f ($_.freespace / 1GB) } } \nforeach ($drive in $drives)\n{\n[PSCustomObject]@{ \n \"PC Name\" = $os.csname \n \"OS Version\" = $os.Caption \n \"Device ID\" = $drive.DeviceID\n \"Size(GB)\" = $drive.\"Size(GB)\"\n \"FreeSpace(GB)\" = $drive.\"FreeSpace(GB)\"\n\n }\n }\n } \n\nResult | ConvertTo-HTML -head $a | Out-File C:\\temp\\Inventory.htm\n\nIf (Result){\n\n $User = \"diskspace@\"\n $File = (Get-Content C:\\Temp\\pw.txt | ConvertTo-SecureString)\n $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential `\n -ArgumentList $User, $File\n \n $To = \"diskspace@\"\n $from = \"alert@\"\n $EmailSubject = \"Storage is low on $PC\"\n $smtp = \"auth.smtp.1and1.co.uk\"\n $body = get-content C:\\temp\\Inventory.htm\n $DefaultMessage=\"\n <p>Dear Help,</p>\n <p>There is a hard drive space issue on $PC IPv4: $IPAddy </p>\n <p> $body </p>\n <p>The Robot Checker .<br><br>\n </p>\"\n \n $MailMessage = @{\n To = $To\n From = $from\n # BCC = $Bcc\n Subject = $EmailSubject\n Body = $DefaultMessage\n priority = \"High\"\n Smtpserver = $smtp\n Credential = $MyCredential\n ErrorAction = \"SilentlyContinue\" \n }\n \n Send-MailMessage @MailMessage -bodyashtml\n \n }\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-06-01T13:04:37.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/6","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},"suggestedAnswer":[{"@type":"Answer","text":"### Getting all domain-joined Server by Names\n \n$Computer = $env:COMPUTERNAME\n$SendIt = $Null\n$Email= @(\"diskspace@\");\n$IPAddy = Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri \"http://ifconfig.me/ip\").Content) | Select ip\n \n### Get only DriveType 3 (Local Disks) foreach Server\n \nForEach ($s in $Computer)\n \n{$Report=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.1'}}\n$View=($Report.DeviceID -join \",\").Replace(\":\",\"\")\n$Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" | Select-Object -Property DeviceID,VolumeName,@{Label=\"Total SIze\";Expression={$_.Size / 1gb -as [int] }},@{Label=\"Free Size\";Expression={$_.freespace / 1gb -as [int] }} | Export-Csv C:\\temp\\space.csv -NoTypeInformation\n$Freespace = Get-Content -Path C:\\temp\\space.csv\n### Send Mail if $Report (<=10%) is true\n \nIf ($Report){\n\n \n$User = \"diskspace@\"\n$File = (Get-Content C:\\Temp\\pw.txt | ConvertTo-SecureString)\n\n$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential `\n-ArgumentList $User, $File\n\n\t\t$To = $Email\n\t\t$from = \"alert@\"\n\t\t$EmailSubject = \"Server $s storage space has dropped to less than 10 % on $View\"\n\t\t$smtp = \"auth.smtp.1and1.co.uk\"\n\n\t\t$DefaultMessage=\"\n\t\t\t<p>Dear Help,</p>\n\t\t\t<p>There is a hard drive space issue on $Computer IPv4: $IPAddy </p>\n\t\t\t<p>This message only fires off if one or more disks have less than 10% free space left on both $View.</p>\n <p> Current FreeSpace $Freespace</p>\n\t\t\t<p>The Robot Checker .<br><br>\n\t\t\t</p>\"\n\n\t\t$MailMessage = @{\n\t\t\t\tTo = $To\n\t\t\t\tFrom = $from\n\t\t\t\t# BCC = $Bcc\n\t\t\t\tSubject = $EmailSubject\n\t\t\t\tBody = $DefaultMessage\n\t\t\t\tpriority = \"High\"\n\t\t\t\tSmtpserver = $smtp\n Credential = $MyCredential\n\t\t\t\tErrorAction = \"SilentlyContinue\" \n\t\t\t}\n\t\t\t\n\t\tSend-MailMessage @MailMessage -bodyashtml\n\n\t}\n<\/code><\/pre>\nWhen it I run the following script, works perfectly but the email appears as such -<\/p>\n<\/use><\/svg>2020-06-01_14_26_59-.png<\/span>800×209 17.4 KB<\/span><\/use><\/svg><\/div><\/a><\/div>Is there an command or where to make it easier to read and in a better format ?<\/p>\nMany thanks!<\/p>","upvoteCount":3,"datePublished":"2020-06-01T11:27:58.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/1","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"$Freespace is a complex value not a simple int or string/.<\/p>\nTryu looking at $Freespae to see what you need to pull out of each CSV entry<\/p>","upvoteCount":0,"datePublished":"2020-06-01T11:46:38.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/2","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":"You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject?<\/p>","upvoteCount":0,"datePublished":"2020-06-01T11:59:29.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/3","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}},{"@type":"Answer","text":"I could simplify it by doing this -<\/p>\n$Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" | Select-Object -Property DeviceID,VolumeName,@{Label=\"TotalSize\";Expression={$_.Size / 1gb -as [int] }},@{Label=\"FreeSize\";Expression={$_.freespace / 1gb -as [int] }}\n\n$Device = $Space.DeviceID \n$Size = $Space.TotalSize \n$FreeSize = $Space.FreeSize\n<\/code><\/pre>\nI’ve made the variable less complex, just now need to insert into the email to make it more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:10:28.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/4","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"You can also get creative with HTML formatting to make it even more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:14:52.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/5","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}}]}} Spiceworks Community Disk Storage Script, Not getting the correct feedback Programming & Development powershell, windows-server, question andrewjohnson22 (SuperHeroBeard) June 1, 2020, 11:27am 1 ### Getting all domain-joined Server by Names $Computer = $env:COMPUTERNAME $SendIt = $Null $Email= @("diskspace@"); $IPAddy = Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content) | Select ip ### Get only DriveType 3 (Local Disks) foreach Server ForEach ($s in $Computer) {$Report=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.1'}} $View=($Report.DeviceID -join ",").Replace(":","") $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} | Export-Csv C:\temp\space.csv -NoTypeInformation $Freespace = Get-Content -Path C:\temp\space.csv ### Send Mail if $Report (<=10%) is true If ($Report){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = $Email $from = "alert@" $EmailSubject = "Server $s storage space has dropped to less than 10 % on $View" $smtp = "auth.smtp.1and1.co.uk" $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $Computer IPv4: $IPAddy </p> <p>This message only fires off if one or more disks have less than 10% free space left on both $View.</p> <p> Current FreeSpace $Freespace</p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml } When it I run the following script, works perfectly but the email appears as such - 2020-06-01_14_26_59-.png800×209 17.4 KBIs there an command or where to make it easier to read and in a better format ? Many thanks! 3 Spice ups DoctorDNS (DoctorDNS) June 1, 2020, 11:46am 2 $Freespace is a complex value not a simple int or string/. Tryu looking at $Freespae to see what you need to pull out of each CSV entry rockn (Rockn) June 1, 2020, 11:59am 3 You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject? andrewjohnson22 (SuperHeroBeard) June 1, 2020, 12:10pm 4 I could simplify it by doing this - $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="TotalSize";Expression={$_.Size / 1gb -as [int] }},@{Label="FreeSize";Expression={$_.freespace / 1gb -as [int] }} $Device = $Space.DeviceID $Size = $Space.TotalSize $FreeSize = $Space.FreeSize I’ve made the variable less complex, just now need to insert into the email to make it more readable. rockn (Rockn) June 1, 2020, 12:14pm 5 You can also get creative with HTML formatting to make it even more readable. andrewjohnson22 (SuperHeroBeard) June 1, 2020, 1:04pm 6 Redid the script with these suggestions and ideas - $a = @" <style> TABLE{border-width: 1px;border-style: solid;border-color:black;} Table{background-color:#DFFFFF;border-collapse: collapse;} TH{border-width:1px;padding:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-left:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-right:10px;border-style:solid;border-color:black;} </style> "@ $PC = $env:COMPUTERNAME function Result { $PCs = $env:COMPUTERNAME $drives = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -ComputerName $PC | Select SystemName,DeviceID,@{Name="Size(GB)";Expression={"{0:N0} GB" -f ($_.size / 1GB) } },@{Name="FreeSpace(GB)";Expression={ "{0:N0} GB" -f ($_.freespace / 1GB) } } foreach ($drive in $drives) { [PSCustomObject]@{ "PC Name" = $os.csname "OS Version" = $os.Caption "Device ID" = $drive.DeviceID "Size(GB)" = $drive."Size(GB)" "FreeSpace(GB)" = $drive."FreeSpace(GB)" } } } Result | ConvertTo-HTML -head $a | Out-File C:\temp\Inventory.htm If (Result){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = "diskspace@" $from = "alert@" $EmailSubject = "Storage is low on $PC" $smtp = "auth.smtp.1and1.co.uk" $body = get-content C:\temp\Inventory.htm $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $PC IPv4: $IPAddy </p> <p> $body </p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml } Related topics Topic Replies Views Activity Simple Disk Space Report Email script , powershell , data-storage 6 426 October 18, 2018 PowerShell script to check free disk spaces for servers Networking script , powershell , data-storage 23 394 March 20, 2019 Check Disks and StoragePool Networking script , powershell 0 58 June 22, 2018 hi i would like to get some help on this powershell script. Programming & Development powershell , question 2 214 July 24, 2020 Get Servers from Active Directory and Report Disk Space usage to HTML Email script , powershell 1 169 April 12, 2017
### Getting all domain-joined Server by Names\n \n$Computer = $env:COMPUTERNAME\n$SendIt = $Null\n$Email= @(\"diskspace@\");\n$IPAddy = Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri \"http://ifconfig.me/ip\").Content) | Select ip\n \n### Get only DriveType 3 (Local Disks) foreach Server\n \nForEach ($s in $Computer)\n \n{$Report=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.1'}}\n$View=($Report.DeviceID -join \",\").Replace(\":\",\"\")\n$Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" | Select-Object -Property DeviceID,VolumeName,@{Label=\"Total SIze\";Expression={$_.Size / 1gb -as [int] }},@{Label=\"Free Size\";Expression={$_.freespace / 1gb -as [int] }} | Export-Csv C:\\temp\\space.csv -NoTypeInformation\n$Freespace = Get-Content -Path C:\\temp\\space.csv\n### Send Mail if $Report (<=10%) is true\n \nIf ($Report){\n\n \n$User = \"diskspace@\"\n$File = (Get-Content C:\\Temp\\pw.txt | ConvertTo-SecureString)\n\n$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential `\n-ArgumentList $User, $File\n\n\t\t$To = $Email\n\t\t$from = \"alert@\"\n\t\t$EmailSubject = \"Server $s storage space has dropped to less than 10 % on $View\"\n\t\t$smtp = \"auth.smtp.1and1.co.uk\"\n\n\t\t$DefaultMessage=\"\n\t\t\t<p>Dear Help,</p>\n\t\t\t<p>There is a hard drive space issue on $Computer IPv4: $IPAddy </p>\n\t\t\t<p>This message only fires off if one or more disks have less than 10% free space left on both $View.</p>\n <p> Current FreeSpace $Freespace</p>\n\t\t\t<p>The Robot Checker .<br><br>\n\t\t\t</p>\"\n\n\t\t$MailMessage = @{\n\t\t\t\tTo = $To\n\t\t\t\tFrom = $from\n\t\t\t\t# BCC = $Bcc\n\t\t\t\tSubject = $EmailSubject\n\t\t\t\tBody = $DefaultMessage\n\t\t\t\tpriority = \"High\"\n\t\t\t\tSmtpserver = $smtp\n Credential = $MyCredential\n\t\t\t\tErrorAction = \"SilentlyContinue\" \n\t\t\t}\n\t\t\t\n\t\tSend-MailMessage @MailMessage -bodyashtml\n\n\t}\n<\/code><\/pre>\nWhen it I run the following script, works perfectly but the email appears as such -<\/p>\n<\/use><\/svg>2020-06-01_14_26_59-.png<\/span>800×209 17.4 KB<\/span><\/use><\/svg><\/div><\/a><\/div>Is there an command or where to make it easier to read and in a better format ?<\/p>\nMany thanks!<\/p>","upvoteCount":3,"datePublished":"2020-06-01T11:27:58.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/1","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"$Freespace is a complex value not a simple int or string/.<\/p>\nTryu looking at $Freespae to see what you need to pull out of each CSV entry<\/p>","upvoteCount":0,"datePublished":"2020-06-01T11:46:38.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/2","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":"You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject?<\/p>","upvoteCount":0,"datePublished":"2020-06-01T11:59:29.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/3","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}},{"@type":"Answer","text":"I could simplify it by doing this -<\/p>\n$Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" | Select-Object -Property DeviceID,VolumeName,@{Label=\"TotalSize\";Expression={$_.Size / 1gb -as [int] }},@{Label=\"FreeSize\";Expression={$_.freespace / 1gb -as [int] }}\n\n$Device = $Space.DeviceID \n$Size = $Space.TotalSize \n$FreeSize = $Space.FreeSize\n<\/code><\/pre>\nI’ve made the variable less complex, just now need to insert into the email to make it more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:10:28.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/4","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"You can also get creative with HTML formatting to make it even more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:14:52.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/5","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}}]}} Spiceworks Community Disk Storage Script, Not getting the correct feedback Programming & Development powershell, windows-server, question andrewjohnson22 (SuperHeroBeard) June 1, 2020, 11:27am 1 ### Getting all domain-joined Server by Names $Computer = $env:COMPUTERNAME $SendIt = $Null $Email= @("diskspace@"); $IPAddy = Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content) | Select ip ### Get only DriveType 3 (Local Disks) foreach Server ForEach ($s in $Computer) {$Report=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.1'}} $View=($Report.DeviceID -join ",").Replace(":","") $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} | Export-Csv C:\temp\space.csv -NoTypeInformation $Freespace = Get-Content -Path C:\temp\space.csv ### Send Mail if $Report (<=10%) is true If ($Report){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = $Email $from = "alert@" $EmailSubject = "Server $s storage space has dropped to less than 10 % on $View" $smtp = "auth.smtp.1and1.co.uk" $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $Computer IPv4: $IPAddy </p> <p>This message only fires off if one or more disks have less than 10% free space left on both $View.</p> <p> Current FreeSpace $Freespace</p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml } When it I run the following script, works perfectly but the email appears as such - 2020-06-01_14_26_59-.png800×209 17.4 KBIs there an command or where to make it easier to read and in a better format ? Many thanks! 3 Spice ups DoctorDNS (DoctorDNS) June 1, 2020, 11:46am 2 $Freespace is a complex value not a simple int or string/. Tryu looking at $Freespae to see what you need to pull out of each CSV entry rockn (Rockn) June 1, 2020, 11:59am 3 You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject? andrewjohnson22 (SuperHeroBeard) June 1, 2020, 12:10pm 4 I could simplify it by doing this - $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="TotalSize";Expression={$_.Size / 1gb -as [int] }},@{Label="FreeSize";Expression={$_.freespace / 1gb -as [int] }} $Device = $Space.DeviceID $Size = $Space.TotalSize $FreeSize = $Space.FreeSize I’ve made the variable less complex, just now need to insert into the email to make it more readable. rockn (Rockn) June 1, 2020, 12:14pm 5 You can also get creative with HTML formatting to make it even more readable. andrewjohnson22 (SuperHeroBeard) June 1, 2020, 1:04pm 6 Redid the script with these suggestions and ideas - $a = @" <style> TABLE{border-width: 1px;border-style: solid;border-color:black;} Table{background-color:#DFFFFF;border-collapse: collapse;} TH{border-width:1px;padding:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-left:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-right:10px;border-style:solid;border-color:black;} </style> "@ $PC = $env:COMPUTERNAME function Result { $PCs = $env:COMPUTERNAME $drives = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -ComputerName $PC | Select SystemName,DeviceID,@{Name="Size(GB)";Expression={"{0:N0} GB" -f ($_.size / 1GB) } },@{Name="FreeSpace(GB)";Expression={ "{0:N0} GB" -f ($_.freespace / 1GB) } } foreach ($drive in $drives) { [PSCustomObject]@{ "PC Name" = $os.csname "OS Version" = $os.Caption "Device ID" = $drive.DeviceID "Size(GB)" = $drive."Size(GB)" "FreeSpace(GB)" = $drive."FreeSpace(GB)" } } } Result | ConvertTo-HTML -head $a | Out-File C:\temp\Inventory.htm If (Result){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = "diskspace@" $from = "alert@" $EmailSubject = "Storage is low on $PC" $smtp = "auth.smtp.1and1.co.uk" $body = get-content C:\temp\Inventory.htm $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $PC IPv4: $IPAddy </p> <p> $body </p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml } Related topics Topic Replies Views Activity Simple Disk Space Report Email script , powershell , data-storage 6 426 October 18, 2018 PowerShell script to check free disk spaces for servers Networking script , powershell , data-storage 23 394 March 20, 2019 Check Disks and StoragePool Networking script , powershell 0 58 June 22, 2018 hi i would like to get some help on this powershell script. Programming & Development powershell , question 2 214 July 24, 2020 Get Servers from Active Directory and Report Disk Space usage to HTML Email script , powershell 1 169 April 12, 2017
Many thanks!<\/p>","upvoteCount":3,"datePublished":"2020-06-01T11:27:58.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/1","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"
$Freespace is a complex value not a simple int or string/.<\/p>\n
Tryu looking at $Freespae to see what you need to pull out of each CSV entry<\/p>","upvoteCount":0,"datePublished":"2020-06-01T11:46:38.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/2","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":"
You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject?<\/p>","upvoteCount":0,"datePublished":"2020-06-01T11:59:29.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/3","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}},{"@type":"Answer","text":"
I could simplify it by doing this -<\/p>\n
$Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter \"Drivetype=3\" | Select-Object -Property DeviceID,VolumeName,@{Label=\"TotalSize\";Expression={$_.Size / 1gb -as [int] }},@{Label=\"FreeSize\";Expression={$_.freespace / 1gb -as [int] }}\n\n$Device = $Space.DeviceID \n$Size = $Space.TotalSize \n$FreeSize = $Space.FreeSize\n<\/code><\/pre>\nI’ve made the variable less complex, just now need to insert into the email to make it more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:10:28.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/4","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"You can also get creative with HTML formatting to make it even more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:14:52.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/5","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}}]}} Spiceworks Community Disk Storage Script, Not getting the correct feedback Programming & Development powershell, windows-server, question andrewjohnson22 (SuperHeroBeard) June 1, 2020, 11:27am 1 ### Getting all domain-joined Server by Names $Computer = $env:COMPUTERNAME $SendIt = $Null $Email= @("diskspace@"); $IPAddy = Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content) | Select ip ### Get only DriveType 3 (Local Disks) foreach Server ForEach ($s in $Computer) {$Report=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.1'}} $View=($Report.DeviceID -join ",").Replace(":","") $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} | Export-Csv C:\temp\space.csv -NoTypeInformation $Freespace = Get-Content -Path C:\temp\space.csv ### Send Mail if $Report (<=10%) is true If ($Report){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = $Email $from = "alert@" $EmailSubject = "Server $s storage space has dropped to less than 10 % on $View" $smtp = "auth.smtp.1and1.co.uk" $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $Computer IPv4: $IPAddy </p> <p>This message only fires off if one or more disks have less than 10% free space left on both $View.</p> <p> Current FreeSpace $Freespace</p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml } When it I run the following script, works perfectly but the email appears as such - 2020-06-01_14_26_59-.png800×209 17.4 KBIs there an command or where to make it easier to read and in a better format ? Many thanks! 3 Spice ups DoctorDNS (DoctorDNS) June 1, 2020, 11:46am 2 $Freespace is a complex value not a simple int or string/. Tryu looking at $Freespae to see what you need to pull out of each CSV entry rockn (Rockn) June 1, 2020, 11:59am 3 You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject? andrewjohnson22 (SuperHeroBeard) June 1, 2020, 12:10pm 4 I could simplify it by doing this - $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="TotalSize";Expression={$_.Size / 1gb -as [int] }},@{Label="FreeSize";Expression={$_.freespace / 1gb -as [int] }} $Device = $Space.DeviceID $Size = $Space.TotalSize $FreeSize = $Space.FreeSize I’ve made the variable less complex, just now need to insert into the email to make it more readable. rockn (Rockn) June 1, 2020, 12:14pm 5 You can also get creative with HTML formatting to make it even more readable. andrewjohnson22 (SuperHeroBeard) June 1, 2020, 1:04pm 6 Redid the script with these suggestions and ideas - $a = @" <style> TABLE{border-width: 1px;border-style: solid;border-color:black;} Table{background-color:#DFFFFF;border-collapse: collapse;} TH{border-width:1px;padding:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-left:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-right:10px;border-style:solid;border-color:black;} </style> "@ $PC = $env:COMPUTERNAME function Result { $PCs = $env:COMPUTERNAME $drives = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -ComputerName $PC | Select SystemName,DeviceID,@{Name="Size(GB)";Expression={"{0:N0} GB" -f ($_.size / 1GB) } },@{Name="FreeSpace(GB)";Expression={ "{0:N0} GB" -f ($_.freespace / 1GB) } } foreach ($drive in $drives) { [PSCustomObject]@{ "PC Name" = $os.csname "OS Version" = $os.Caption "Device ID" = $drive.DeviceID "Size(GB)" = $drive."Size(GB)" "FreeSpace(GB)" = $drive."FreeSpace(GB)" } } } Result | ConvertTo-HTML -head $a | Out-File C:\temp\Inventory.htm If (Result){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = "diskspace@" $from = "alert@" $EmailSubject = "Storage is low on $PC" $smtp = "auth.smtp.1and1.co.uk" $body = get-content C:\temp\Inventory.htm $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $PC IPv4: $IPAddy </p> <p> $body </p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml } Related topics Topic Replies Views Activity Simple Disk Space Report Email script , powershell , data-storage 6 426 October 18, 2018 PowerShell script to check free disk spaces for servers Networking script , powershell , data-storage 23 394 March 20, 2019 Check Disks and StoragePool Networking script , powershell 0 58 June 22, 2018 hi i would like to get some help on this powershell script. Programming & Development powershell , question 2 214 July 24, 2020 Get Servers from Active Directory and Report Disk Space usage to HTML Email script , powershell 1 169 April 12, 2017
I’ve made the variable less complex, just now need to insert into the email to make it more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:10:28.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/4","author":{"@type":"Person","name":"andrewjohnson22","url":"https://community.spiceworks.com/u/andrewjohnson22"}},{"@type":"Answer","text":"
You can also get creative with HTML formatting to make it even more readable.<\/p>","upvoteCount":0,"datePublished":"2020-06-01T12:14:52.000Z","url":"https://community.spiceworks.com/t/disk-storage-script-not-getting-the-correct-feedback/764534/5","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}}]}}
### Getting all domain-joined Server by Names $Computer = $env:COMPUTERNAME $SendIt = $Null $Email= @("diskspace@"); $IPAddy = Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content) | Select ip ### Get only DriveType 3 (Local Disks) foreach Server ForEach ($s in $Computer) {$Report=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.1'}} $View=($Report.DeviceID -join ",").Replace(":","") $Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} | Export-Csv C:\temp\space.csv -NoTypeInformation $Freespace = Get-Content -Path C:\temp\space.csv ### Send Mail if $Report (<=10%) is true If ($Report){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = $Email $from = "alert@" $EmailSubject = "Server $s storage space has dropped to less than 10 % on $View" $smtp = "auth.smtp.1and1.co.uk" $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $Computer IPv4: $IPAddy </p> <p>This message only fires off if one or more disks have less than 10% free space left on both $View.</p> <p> Current FreeSpace $Freespace</p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml }
When it I run the following script, works perfectly but the email appears as such -
Many thanks!
$Freespace is a complex value not a simple int or string/.
Tryu looking at $Freespae to see what you need to pull out of each CSV entry
You exported to CSV which is why it looks that way. What is wrong with the table output fro Get-WmiObject?
I could simplify it by doing this -
$Space = Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" | Select-Object -Property DeviceID,VolumeName,@{Label="TotalSize";Expression={$_.Size / 1gb -as [int] }},@{Label="FreeSize";Expression={$_.freespace / 1gb -as [int] }} $Device = $Space.DeviceID $Size = $Space.TotalSize $FreeSize = $Space.FreeSize
I’ve made the variable less complex, just now need to insert into the email to make it more readable.
You can also get creative with HTML formatting to make it even more readable.
Redid the script with these suggestions and ideas -
$a = @" <style> TABLE{border-width: 1px;border-style: solid;border-color:black;} Table{background-color:#DFFFFF;border-collapse: collapse;} TH{border-width:1px;padding:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-left:10px;border-style:solid;border-color:black;} TD{border-width:1px;padding-right:10px;border-style:solid;border-color:black;} </style> "@ $PC = $env:COMPUTERNAME function Result { $PCs = $env:COMPUTERNAME $drives = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -ComputerName $PC | Select SystemName,DeviceID,@{Name="Size(GB)";Expression={"{0:N0} GB" -f ($_.size / 1GB) } },@{Name="FreeSpace(GB)";Expression={ "{0:N0} GB" -f ($_.freespace / 1GB) } } foreach ($drive in $drives) { [PSCustomObject]@{ "PC Name" = $os.csname "OS Version" = $os.Caption "Device ID" = $drive.DeviceID "Size(GB)" = $drive."Size(GB)" "FreeSpace(GB)" = $drive."FreeSpace(GB)" } } } Result | ConvertTo-HTML -head $a | Out-File C:\temp\Inventory.htm If (Result){ $User = "diskspace@" $File = (Get-Content C:\Temp\pw.txt | ConvertTo-SecureString) $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, $File $To = "diskspace@" $from = "alert@" $EmailSubject = "Storage is low on $PC" $smtp = "auth.smtp.1and1.co.uk" $body = get-content C:\temp\Inventory.htm $DefaultMessage=" <p>Dear Help,</p> <p>There is a hard drive space issue on $PC IPv4: $IPAddy </p> <p> $body </p> <p>The Robot Checker .<br><br> </p>" $MailMessage = @{ To = $To From = $from # BCC = $Bcc Subject = $EmailSubject Body = $DefaultMessage priority = "High" Smtpserver = $smtp Credential = $MyCredential ErrorAction = "SilentlyContinue" } Send-MailMessage @MailMessage -bodyashtml }