Mail is going but with message "System.Collections.Specialized.OrderedDictionary

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Biswajit Biswajit 9 months, 3 weeks ago.

  • Author
    Posts
  • #35241
    Profile photo of Biswajit
    Biswajit
    Participant

    Hi,

    Mail is going but with message "System.Collections.Specialized.OrderedDictionary "
    Below is the code.
    ______________________________________________________________________
    $DHCPSERVERs = Get-Content "D:\DHCP.txt"
    $Prop = [ordered]@{}
    foreach ($DHCP in $DHCPSERVERs)
    {
    $Prop.ComputerName = $DHCP
    $MB = Get-Item "\\$DHCP\C$\Windows\System32\dhcp\dhcp.mdb" | select -ExpandProperty Length
    $prop.MDBSize =($MB/1MB).ToString("0.00"+" MB")
    New-Object PSObject -property $Prop

    }
    Send-MailMessage -To bshwjt@live.com -from DHCPADMINs@live.com -Subject "dhcp.mdb Size"-Body $Prop -SmtpServer 10.224.34.8

  • #35242
    Profile photo of Brendan DS
    Brendan DS
    Participant

    Hi Biswajit,

    Try this,

     $DHCPSERVERs = Get-Content "D:\DHCP.txt"
    $Prop = [ordered]@{}
    $Propobject = New-Object -TypeName PSobject
    
    foreach ($DHCP in $DHCPSERVERs)
    {
    $Prop.ComputerName = $DHCP
    $MB = Get-Item "\\$DHCP\C$\Windows\System32\dhcp\dhcp.mdb" | select -ExpandProperty Length
    $prop.MDBSize =($MB/1MB).ToString("0.00"+" MB")
    
    $Propobject | Add-Member -Membertype NoteProperty -Name $Prop.ComputerName -Value $Prop.MDBSize
    
    }
    

    Send-MailMessage -To bshwjt@live.com -from DHCPADMINs@live.com -Subject "dhcp.mdb Size"-Body $Propobject -SmtpServer 10.224.34.8

    In the original the new object was being created but it wasn't being assigned to a variable to be used in the Send-MailMessage -Body.

    In the example I've given the object is created outside of the loop and then has note properties added that contain the (Name) Computer name and (Value) MDBSize.

    Hope that helps.

  • #35261
    Profile photo of Biswajit
    Biswajit
    Participant

    Thanks Brendan. That works fine but output came in a Single line.

    @{srv0003.live.com=8,01 MB; srv0017.live.com=3,01 MB; srv0009.live.com=3,01 MB; srv0004.live.com=8,01 MB; srv0046.live.com=3,01 MB; srpacinf6013.live.com=3,01 MB}

    Need similar output below

    srv0003.live.com=8,01 MB
    srv0017.live.com=3,01 MB
    srv0009.live.com=3,01 MB
    srv0004.live.com=8,01 MB
    srv0046.live.com=3,01 MB
    srv0061.live.com=3,01 MB

  • #35263
    Profile photo of Bob McCoy
    Bob McCoy
    Participant
    #requires -version 3
    #https://powershell.org/forums/topic/mail-is-going-but-with-message-system-collections-specialized-ordereddictionary/
    
    $results = foreach ($server in (Get-Content -Path C:\Ephemeral\dhcp.txt))
    {
        [PSCustomObject]@{
            ComputerName = $server
            MDBSize = "{0:N2} MB" -f $((Get-Item "\\$server\C$\Windows\System32\dhcp\dhcp.mdb").Length / 1mb)
        }
    }
    Out-String -InputObject $results -OutVariable body | Write-Verbose
    
    Send-MailMessage -To bshwjt@live.com -from DHCPADMINs@live.com -Subject "dhcp.mdb Size" -Body $body -SmtpServer 10.224.34.8
  • #35267
    Profile photo of Biswajit
    Biswajit
    Participant

    Thanks Bob. Great

You must be logged in to reply to this topic.