Hi guys,
Can you please help how i can be possible called upon multiple vCenters from rvtoolsbatch and will send all it all as different attachment but in a single mail?
From what i read on rvtools documentation, it was suggesting to use a colon as a separator, but i couldnt get like what i want to have and Keep getting error Unhandled exception: Invalid URI: The hostname could not be parsed.
I can write multiple lines to invoke multiple vcenters and send email or attachment likewise, but that would beat a purpose as i wanted to have all rvtools report of all vcenters in a single email.
Please help.
Cheers
Have a look at the New-VICredentialSToreItem and Get-VICredentialStoreItem.
It allows you to add credentials per host.
Retrieve the credentials with the hostname, in this case the vCenter name.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD for the reply and comments. Could you please help to give some reference how this PowerCli cmdlet (New-VICredentialStoreItem) can be incorporated with the existing script?
i have tried below like additional line for the 2nd vCenter server
$ExportPath = 'C:\Temp\testing'
$Servers = 'vCenter1'
$Servers1 = 'vCenter2'
$Servers | %{
. "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u root1 -p _RVToolsPWDRHyqpGC78/X+vSBdoAHn3n0d3xGrJzoQrIsq423hxzs= -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"
}
$Servers1 | %{
. "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u temp1 -p _RVToolsPWD37jLee6Zi+WKbwTIuj9alLMVi0cBORQj0/8XlanLPv2Q9zqbiaHYIPC17E7m+e8I -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"
}
$smtpServer = 'smtp.globedev.com'
$to = ''
$from = ''
Start-Sleep -s 60
$att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName
Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att
You need to set it up first (see comment)
#
# New-VicredentialStoreItem -Host vCenter1 -User root1 -Password _RVToolsPWDRHyqpGC78/X+vSBdoAHn3n0d3xGrJzoQrIsq423hxzs=
# New-VicredentialStoreItem -Host vCenter2 -User temp1 -Password _RVToolsPWD37jLee6Zi+WKbwTIuj9alLMVi0cBORQj0/8XlanLPv2Q9zqbiaHYIPC17E7m+e8I
#
$ExportPath = 'C:\Temp\testing'
$Servers = 'vCenter1','vCenter2'
$Servers | %{
$cred = Get-VICredentialStoreItem -Host $_
. "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u $($cred.User) -p $($cred.Password) -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"
}
$smtpServer = 'smtp.globedev.com'
$to = ''
$from = ''
Start-Sleep -s 60
$att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName
Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for the reply.
Do I need to run this as command on PowerCli seperately to set up the VICredentialstoreItems for the vCenters. Then we need to schedule the task to run the script to get the report?
Moreover after specifying the date in the script, it sending all the RVtools attachments instead of that date report only.
Kindly help to advise with your comments.
Regards
Narayanan.
Yes, you will need to set up the VICredentialSToreItems separately, before running the RVTools script.
To get only the files with the specific reports, try like this
$Servers = 'vCenter1','vCenter2'
$files = @()
$Servers | %{
$cred = Get-VICredentialStoreItem -Host $_
$reportName = "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"
$files += $reportName
. "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u $($cred.User) -p $($cred.Password) -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f $reportName
}
$smtpServer = 'smtp.globedev.com'
$to = ''
$from = ''
Start-Sleep -s 60
$att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName
Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
i am getting the below error after i have tried for one vCenter server via PowerCLI console & powershell as well.
Please advise
PowerCLI C:\temp\testing> .\rvtools_cred.ps1
Get-ChildItem : A positional parameter cannot be found that accepts argument
'System.Object[]'.
At C:\temp\testing\rvtools_cred.ps1:28 char:8
+ $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterB
indingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.GetChildItemCommand
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The
argument is null or empty. Provide an argument that is not null or empty, and
then try the command again.
At C:\temp\testing\rvtools_cred.ps1:30 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBi
ndingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.SendMailMessage
Note: Tried the same via powershell console, getting below error. May be i need to import the latest vmware modules into the powershell.
Get-VICredentialStoreItem : The term 'Get-VICredentialStoreItem' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\Temp\testing\rvtools_cred.ps1:9 char:13
+ $cred = Get-VICredentialStoreItem -Host $_
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-VICredentialStoreItem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-ChildItem : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At C:\Temp\testing\rvtools_cred.ps1:28 char:8
+ $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\Temp\testing\rvtools_cred.ps1:30 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
PS C:\Temp\testing>
Regards
Narayanan.
The Get-VICredentialStoreItem cmdlet is in the VMware.VimAutomation.Core module.
If your PowerCLI modules are in a folder that is listed in $env:PSModulePath and your PS version is 4 or 5, there should be no need to explicitly import a module.
But you can add an Import-Module just to make sure.
Also note that in PS 6 or 7 the Get-VICredentialStoreItem is not supported.
Are you running the script in PS v6 or v7?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
PowerCli version below for your reference
PowerCLI C:\temp\testing> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.8 Release 1 build 2057893
Can you please suggest for the below error which earlier mentioned for attaching the specific date file to the email from the export path directory.
Get-ChildItem : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At C:\Temp\testing\rvtools_cred.ps1:28 char:8
+ $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\Temp\testing\rvtools_cred.ps1:30 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
Regards
Narayanan.
That is a really old PowerCLI version, I strongly suggest to upgrade (unless you have a valid reason to stay with this old version).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
Upgraded powercli to 6.5 version (4624819) but still getting the below error. i can see the report generated but getting error in the attachment during the email send.
Can you suggest.
PowerCLI C:\temp\testing> .\rvtools_cred.ps1
Get-ChildItem : A positional parameter cannot be found that accepts argument
'System.Object[]'.
At C:\temp\testing\rvtools_cred.ps1:28 char:8
+ $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterB
indingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.GetChildItemCommand
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The
argument is null or empty. Provide an argument that is not null or empty, and
then try the command again.
At C:\temp\testing\rvtools_cred.ps1:30 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBi
ndingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.SendMailMessage
PowerCLI C:\temp\testing> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware PowerCLI 6.5 Release 1 build 4624819
Regards
Narayanan.
Why 6.5 R1?
PowerCLI is currently at version 12.0.0
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
Currently this is the max version using in our environment and need to check internally if this can be upgraded, as the existing scripts are running on this version.
Could you please let me know if the "Positional Parameter" error due to the PowerCLI version?
Please help to advise if this can be modified according to the 6.5 R1 version?
Regards
Narayanan.
Which PowerShell version are you using?
What does $PSVersionTable show?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Give it a try with
$Servers = 'vCenter1','vCenter2'
$files = @()
$Servers | %{
$cred = Get-VICredentialStoreItem -Host $_
$reportName = "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"
$files += "$ExportPath\$reportName"
. "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u $($cred.User) -p $($cred.Password) -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f $reportName
}
$smtpServer = 'smtp.globedev.com'
$to = ''
$from = ''
Start-Sleep -s 60
$att = Get-ChildItem -Path $files | select -ExpandProperty FullName
Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Please find the requested details for the same.
PS C:\Temp\testing> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Regards
Narayanan.
Works Perfectly LucD. Thank you so much for the help. Really great.
Note: i faced error during credential store set using New-VICredential if the password contains '&' '%' not allowed. So i have used Rvtoolspassword encryption to get the password
The ampersand (&) character is not allowed. The & operator is reserved for
future use; wrap an ampersand in double quotation marks ("&") to pass it as
part of a string.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : AmpersandNotAllowed
Regards
Narayanan.
Did you place the password within single quotes on the Password parameter?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Apology for the delay reply LucD.
Tried password without quotes, directly entered. Let me check and update you.
Regards
Narayanan.
How to delete the existing file on that folder if we try to send the report mail once in a week.
The file has a datestamp in its name, the email attachment is unique
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference