Link to home
Start Free TrialLog in
Avatar of Christophe
ChristopheFlag for France

asked on

Powershell function

Hello,

I am a newbies about powershell script but I would like to understand how to do one thing.

I'd like to send a value by email from powershell.

I found a very nice function and I'd like to put the result of this function in my email body. My email is ready and works, no problem with that.

I do not know how I can get the result. I though I need to get function result into variable and use this variable for my email but I do not know how to do that and I am not sure I need to do that.

Please see below the function:

Function ConvertTo-Char
(      
      $Array
)
{
      $output = ""
      ForEach($char in $Array)
      {      $Output += [char]$char -join ""
      }
      return $Output
}

$Query = Get-WmiObject -Query "Select * FROM WMIMonitorID" -Namespace root\wmi


$Results = ForEach ($Monitor in $Query)
{    
      New-Object PSObject -Property @{
            Manufacturer = ConvertTo-Char($Monitor.ManufacturerName)
            UserFriendlyName = ConvertTo-Char($Monitor.userfriendlyname)
            SerialNumber = ConvertTo-Char($Monitor.serialnumberid)
      }
}

$Results | Select Manufacturer,UserFriendlyName,SerialNumber


I'd like to get monitor information and send by email.

Thank you in advance for your help

Christophe
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Christophe

ASKER

Thank you very much! It is working perfectly!

Now I will try to find how to modify result format because in my email, all values from $monitorstring are in the same line:

Monitor(s): Manufacturer UserFriendlyName SerialNumber ------------ ---------------- ------------ DEL DELL P2210 W416K05K0TDM SNY SDM-P232W 7701720  

Thanks again for your help!

Christophe