Christophe
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.Ma nufacturer Name)
UserFriendlyName = ConvertTo-Char($Monitor.us erfriendly name)
SerialNumber = ConvertTo-Char($Monitor.se rialnumber id)
}
}
$Results | Select Manufacturer,UserFriendlyN ame,Serial Number
I'd like to get monitor information and send by email.
Thank you in advance for your help
Christophe
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.Ma
UserFriendlyName = ConvertTo-Char($Monitor.us
SerialNumber = ConvertTo-Char($Monitor.se
}
}
$Results | Select Manufacturer,UserFriendlyN
I'd like to get monitor information and send by email.
Thank you in advance for your help
Christophe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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