# Cannot find an overload

**URL:** <https://forums.powershell.org/t/cannot-find-an-overload/1931>\
**Category:** PowerShell Help\
**Created:** [October 4, 2013, 1:25am UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931 "2013-10-04T01:25:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![windows-liveuser19](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@windows-liveuser19](https://forums.powershell.org/u/windows-liveuser19)\
**Post date:** [October 4, 2013, 1:25am UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/1 "2013-10-04T01:25:10Z")

</div>

I am trying to figure out why I am getting this error:  
New-Object : Cannot find an overload for “MailMessage” and the argument count: “4”.  
5th line from the end…

```
`
$smtpServer = â€œsmptservername"
$smtpFrom = â€œtest@test.orgâ€
$smtpTo = â€œme@test.orgâ€
$DiskResults = @()

# destination hosts to check

[Array] $machines = â€œservername", â€œlocalhostâ€

foreach ($computername in $machines)  
{  
$emailflag = 0;  
Write-Host $computerName  
$objDisks = Get-WmiObject -Computername $computerName -Class win32\_logicaldisk | Where-Object { $\_.DriveType -eq 3 }  
ForEach( $disk in $objDisks )  
{  
$ThisVolume = "" | select ServerName,Volume,Capacity,FreeSpace,PercentFree  
$ThisVolume.ServerName = $computerName  
$ThisVolume.Volume = $disk.DeviceID  
$ThisVolume.Capacity = $([Math]::Round($disk.Size/1073741824,2))  
$ThisVolume.FreeSpace = $([Math]::Round($disk.FreeSpace/1073741824,2))  
$ThisVolume.PercentFree = $ThisVolume.FreeSpace/$ThisVolume.Capacity\*100  
if ($ThisVolume.PercentFree -gt 10.0)  
{  
$emailflag = 1  
}  
$DiskResults += $ThisVolume  
}  
if ($emailflag -eq 1)  
{  
$subject = â€œAttention: Disk space is running low on â€ + $computerName + â€œâ€;  
$body = $ThisVolume

```
    # Send e-mail

    $smtpClient = New-Object Net.Mail.SmtpClient($smtpServer);
    $emailFrom = New-Object Net.Mail.MailAddress $smtpFrom, $smtpFrom;
    $emailTo = New-Object Net.Mail.MailAddress $smtpTo, $smtpTo;
    $mailMsg = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $body);
    $smtpClient.Send($mailMsg)

```

}  
}  
$DiskResults | ft  
`
```
  
Thanks for your help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 4, 2013, 1:41am UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/2 "2013-10-04T01:41:41Z")

</div>

The 4-argument constructor for MailMessage expects 4 Strings. PowerShell is usually pretty good about converting data for you, but maybe it’s having trouble here. Try this change:

```
$body = $ThisVolume | Out-String
```

---

<div class="post-metadata">

**Author:** ![proxb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/proxb/32/611_2.png) [@proxb](https://forums.powershell.org/u/proxb)\
**Post date:** [October 4, 2013, 12:26pm UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/3 "2013-10-04T12:26:09Z")

</div>

I agree with David. For some reason, the constructor just does not like the way the object built. Using his approach above will work to resolve that error you are getting.

Just out of curiosity, why aren’t you using the Send-MailMessage cmdlet instead of building out your own email command?  
Using splatting and Send-MailMessage would simplify your code a little more.  
Side note: Consider the use of the -Filter parameter with your WMI query as well.

```
`
$mailParams = @{
    To = â€œme@test.orgâ€
    From = â€œtest@test.orgâ€
    SMTPServer = $smtpServer
}
$DiskResults = @()
# destination hosts to check
[Array] $machines = â€œservername", â€œlocalhostâ€
foreach ($computername in $machines)
{
 $emailflag = 0;
 Write-Host $computerName
  $objDisks = Get-WmiObject -Computername $computerName -Class win32_logicaldisk -Filter "DriveType = '3'"
  ForEach( $disk in $objDisks )
  {
    $ThisVolume = "" | select ServerName,Volume,Capacity,FreeSpace,PercentFree
    $ThisVolume.ServerName = $computerName
    $ThisVolume.Volume = $disk.DeviceID
    $ThisVolume.Capacity = $([Math]::Round($disk.Size/1073741824,2))
    $ThisVolume.FreeSpace = $([Math]::Round($disk.FreeSpace/1073741824,2))
    $ThisVolume.PercentFree = $ThisVolume.FreeSpace/$ThisVolume.Capacity*100
    if ($ThisVolume.PercentFree -gt 10.0)
    {
        $emailflag = 1
    }
    $DiskResults += $ThisVolume
  }
  if ($emailflag -eq 1)
  {
        $body = $ThisVolume
        $emailParams.Subject = â€œAttention: Disk space is running low on $computerName"
        $emailParams.Body = ($ThisVolume | Out-String)
        Send-MailMessage @emailParams
  }
}
`
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [October 4, 2013, 9:51pm UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/4 "2013-10-04T21:51:03Z")

</div>

Definitely use a filter against remote machines - it reduces the amount of data returned from the remote server

Also use 1Gb instead of 1073741824

---

<div class="post-metadata">

**Author:** ![dba421](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dba421](https://forums.powershell.org/u/dba421)\
**Post date:** [January 10, 2017, 8:40am UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/5 "2017-01-10T08:40:50Z")

</div>

Hello All,

Hope everyone is doing well.

I’m getting the following error message while executing the powershell script …Requesting you please help me to resolve this issue.  
Script here is :

Function writeServiceInfo  
{  
param($fileName,$machinename,$dbname,$tbname,$ixname,$dbfrg,$dbpc)  
Add-Content $filename “”  
Add-Content $filename “$machineName”  
Add-Content $filename “$dbname”  
Add-Content $filename “$tbname”  
Add-Content $filename “$ixname”  
$frg = [Math]::Round($dbfrg,2)  
If ($frg -gt “30”)

Error message

Cannot find an overload for “Round” and the argument count: “2”.  
Cannot find an overload for “Round” and the argument count: “2”.  
At line:108 char:2

- $frg = [Math]::Round($dbfrg,2)
- 

```auto

```

- CategoryInfo : NotSpecified: (🙂 , ParentContainsErrorRecordException
- FullyQualifiedErrorId : MethodCountCouldNotFindBest

Thanks in advance for your quick help!!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 10, 2017, 9:28am UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/6 "2017-01-10T09:28:39Z")

</div>

please do not recycle old posts.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/cannot-find-an-overload/1931/7 "2024-05-16T20:40:28Z")

</div>


