VMware Cloud Community
ms5812
Enthusiast
Enthusiast

Send-MailMessage need to have popup to enter e-mail destination

I am looking to have several people who own specific VC's be able to enter their VC (see below) and then enter their e-mail address to have the output sent to them.

This is for the VC name to be entered

[CmdletBinding()]

param (

  [Parameter(Position = 0, Mandatory = $true)]

   [System.String]

   $VirtualCenterServer,

   [Parameter(Position = 1)]

   [System.String]

   $ClusterName,

   [Parameter(Position = 2)]

   [System.Boolean]

   $asLocalUser = $true

  )

I was working with the below in an attempt to get it working

#param (

# [Parameter(Position = 0)]

# [System.String]

# $mailto =

This is the current e-mail method

#Beginning Sending E-Mail

$attach1 = "$filepath$filename   $VirtualCenterServer   $date.csv"

$mailto = 'User01 powerCLI-Novice@whoohoo.com'

$mailfrom = 'powerCLI-Novice@whoohoo.com'

$mailsubject = "$VirtualCenterServer $filename"

$smtpserver = "mailserver"

$mailbody = "$VirtualCenterServer $filename"

Send-MailMessage -To $mailto -From $mailfrom -Subject $mailsubject -SmtpServer $smtpserver -Body $mailbody -Attachments $attach1

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

Not sure I got the question correctly, but if you make the $EmailAddress parameter mandatory, the user will be promted if no value was passed.

Like this for example

[CmdletBinding()]

param (

   [Parameter(Position = 0, Mandatory = $true)]

   [System.String]

   $VirtualCenterServer,

   [Parameter(Position = 1, Mandatory = $true)]

   [System.String]

   $EmailAddress,

   [Parameter(Position = 2)]

   [System.String]

   $ClusterName,

   [Parameter(Position = 3)]

   [System.Boolean]

   $asLocalUser = $true

)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

ms5812
Enthusiast
Enthusiast

Yes Sir that is what the doctor ordered,

Thank you,

I have two other questions that I was looking for answers, can I ask them here or should I open another request?

First is

How can I get the output of the following? I would like to export the VWR_PSP* to a csv with the Hostname followed to the left by the answer.

   $esxcli.storage.nmp.psp.fixed.deviceconfig.get

   $esxcli.storage.nmp.psp.generic.deviceconfig.get

   $esxcli.storage.nmp.psp.generic.pathconfig.get

I am currently using the following cmdlet to gather the information but it doesn't list the Hostname and lists the information under description, name in the output.

$esxcli.storage.nmp.psp.list()

pastedImage_1.png

Question 2

pastedImage_0.png

#Begin region setting varibles to prompt user for VC and destination e-mail

[CmdletBinding()]

param (

 

   [Parameter(Position = 0, Mandatory = $true)]

   [System.String]

   #The below will make entering the VC manually pop-up

   $VirtualCenterServer,

   [Parameter(Position = 1, Mandatory = $true)]

   [System.String]

   #The below will make entering the destination e-Mail address Mandatory at the pop-up

   $EmailAddress,

   [Parameter(Position = 2)]

   [System.String]

   $ClusterName,

   [Parameter(Position = 3)]

   [System.Boolean]

   $asLocalUser = $true

 

Write-Host "ALUA-Multipath-TCP-NFS and then output to CSV using PowerCLI"

$initalTime = Get-Date

$filepath = "F:\temp\XXXX\XXXX\"

$filename = "ALUA-Multipath-TCP-NFS"

$date = Get-Date ($initalTime) -uformat %Y%m%d

$time = Get-Date ($initalTime) -uformat %H%M

Write-Host "$(Get-Date ($initalTime) -uformat %H:%M:%S) - Starting"

$AllHosts = Get-VMHost | Sort Name

Write-Host "$(Get-Date -uformat %H:%M:%S) - $($AllHosts.length) hosts acquired"

$i = 0

ForEach ($VMHost in $AllHosts) {

   $i++

   Write-Host "$(Get-Date -uformat %H:%M:%S) - $($i) of $($AllHosts.length) - $($VMHost)"}

Write-Host "If there is an output above this line, there is a Disconnect-VIServer cmdlet next to make sure we start with a clean slate"

Disconnect-VIServer * -Force -Confirm:$false

Write-Host "The output below should show as 0, there should be no connected VC's at this point."

$Global:DefaultVIServers.count

 

Write-Host "If there is any number other than 0 shown above there will be a display below to show who it is"

$Global:DefaultVIServers | Select Name,ProductLine,Version,Build

if ($DefaultVIServers.name -ne $VirtualCenterServer)

   #Credentials imported for Virtual Center based on $VirtualCenterServer varable

   $cred = Get-VICredentialStoreItem -User sysdep  -Host $VirtualCenterServer  -File C:\cred.xml

   Connect-VIServer -Server $cred.Host -User $cred.User -Password $cred.Password | Out-Null

   Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore" -Confirm:$false

if ((Get-PSSnapin -Name VMware* -ErrorAction SilentlyContinue) -eq $null)

 

   Add-PsSnapin VMware*

if ($ClusterName)

 

   $VMHosts = Get-Cluster -Name $ClusterName | Get-VMHost | Where-Object { $_.ConnectionState -eq "Connected" }

 

   $VMhosts = Get-VMHost | Where-Object { $_.ConnectionState -eq "Connected" } | Sort #| Select Parent,ConnectionState,Version,Build,Model,{}

Reply
0 Kudos