简体   繁体   中英

Append variable name and date to PowerShell file output

I am trying to put together a quick little script to help when I am using OpenSSL, for some reason I can't seem to get PowerShell to append the hostname to the front of my CSR file. It is basically giving me things like _09_26_2017.txt instead of something like hostname_09_26_2017.txt .

I have the following

$date = Get-Date -format MM_dd_yyyy
$csrName = $siteName + "_" + $date

$siteName = Read-Host "Enter the site name"

.\openssl.exe req -newkey rsa:4096 -sha256 -nodes -keyout "$siteName.pem" -out "$csrName.txt"

Any help would be greatly appreciated. Thank you very much in advance.

You define $sitename after you define $csrname . So

$csrName = $siteName + "_" + $date 

is behaving as

$csrName = $null + "_" + $date

Simply define $sitename before you try to use by moving the line up:

$date = Get-Date -format MM_dd_yyyy
$siteName = Read-Host "Enter the site name"
$csrName = $siteName + "_" + $date

.\openssl.exe req -newkey rsa:4096 -sha256 -nodes -keyout "$siteName.pem" -out "$csrName.txt"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM