0

Thanks for reading, I'm working on something a bit outside my element and trying to write a powershell script that can install some SSL Certificates into some Veeam Products.

This works.

Add-PSSnapin VeeamPSSnapin
Connect-VBRServer
$certificate = Get-VBRCloudGatewayCertificate -FromStore | Where FriendlyName -like "*12/10/2019*"
Add-VBRCloudGatewayCertificate -Certificate $certificate
Disconnect-VBRServer 

What I need though is a way for the -like "*12/10/2019*" to be a variable that inserts today's date.

I've tried using a variable like this:

 $date = Get-Date -Format "MM/dd/yyyy"

Then using

-like "*$date*" 

I've tried something like this

-like "*(Get-Date -Format "MM/dd/yyyy")*"

Here's an output from a failed attempt with formatting recommended below and what Power Shell Returns

Add-PSSnapin VeeamPSSnapin
Connect-VBRServer
$certificate = Get-VBRCloudGatewayCertificate -FromStore | Where FriendlyName -like "*$(Get-Date -Format "MM\/dd\/yyyy")*"
Add-VBRCloudGatewayCertificate -Certificate $certificate
Disconnect-VBRServer 

Powershell return

Add-VBRCloudGatewayCertificate : Cannot validate argument on parameter 'Certificate'. The argument is null. Provide a valid value for the argument, and then try running the command again. At line:5 char:45 + Add-VBRCloudGatewayCertificate -Certificate $certificate + ~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Add-VBRCloudGatewayCertificate], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.AddVBRCloudGatewayCertificate

Go easy on me I'm sure I'm missing something dumb and obvious but I'm not a programmer and my scripting skills are pretty minimal.

Thanks for taking a look and helping out.

iKnowTech
  • 13
  • 4
  • Using a variable should work. If you want to use a nested expression you need `"*$(...)*"`, not `"*(...)*"`. Note that you may need to escape the forward slashes in the format string (`MM\/dd\/yyyy`), b/c IIRC the underlying .net routines replace unescaped forward slashes with the date separator defined in the system's regional settings, which may or may not be a forward slash. – Ansgar Wiechers Oct 13 '19 at 20:40
  • Still not able to get this to work. I tried. ` Where FriendlyName -like "*$(Get-Date -Format "MM\/dd\/yyyy")*" ` – iKnowTech Oct 13 '19 at 22:37
  • Also tried without the escaping backslashes. Also tried populating the $date variable separately and using `-like "*$(date)*"` – iKnowTech Oct 13 '19 at 22:43
  • "Not able to get this to work" is not a valid problem description. Please show an example of a friendly name and the output of `"*$(Get-Date -Format "MM\/dd\/yyyy")*"`. – Ansgar Wiechers Oct 14 '19 at 08:57
  • Here's an example of Friendly Name. `*.xxxx.xxx [Certify] - 10/12/2019 12:37:39 AM to 1/9/2020 11:37:39 PM` – iKnowTech Oct 15 '19 at 12:49
  • Here's the last full command I ran. ` Add-PSSnapin VeeamPSSnapin Connect-VBRServer $date = Get-Date -Format "MM/dd/yyyy" $certificate = Get-VBRCloudGatewayCertificate -FromStore | Where FriendlyName -like "*$(Get-Date -Format "MM\/dd\/yyyy")*" Add-VBRCloudGatewayCertificate -Certificate $certificate Disconnect-VBRServer ` – iKnowTech Oct 15 '19 at 12:51
  • Well, today is neither 10/12/2019 nor 1/9/2020, so of course `FriendlyName -like "*$(Get-Date -Format "MM\/dd\/yyyy")*"` won't match. – Ansgar Wiechers Oct 15 '19 at 12:55
  • Good point, I would only be running the script on the date the Cert was generated so the Friendly Name and Date should match. I added some additional information to the original post. I'll need to go back and regenerate the Cert to today's date and retest this. – iKnowTech Oct 15 '19 at 12:59
  • Yep, I'm an idiot. Looks like `FriendlyName -like "*$(Get-Date -Format "MM\/dd\/yyyy")*"` does work, assuming there is an existing Cert with that date in the store. Sorry that should have been obvious forgot I've been working on this multiple days. – iKnowTech Oct 15 '19 at 13:07

0 Answers0