Proper Powershell formatting SSL Cert Where | FriendlyName like $variable

290 views Asked by At

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.

0

There are 0 answers