Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将值存储在同一文件中_Powershell_Ssl - Fatal编程技术网

Powershell 将值存储在同一文件中

Powershell 将值存储在同一文件中,powershell,ssl,Powershell,Ssl,我有以下代码提取ssl证书的功能并将其存储在一个文件中,但他将每个值都写在一行中,我想知道如何确保在循环的迭代中,三个值都写在同一行上 为了让我自己清楚,这是我现在的输出 CN=localhost BD94E0B92BEFFA09B2FB6EC302CE27792A7181 2022年10月4日凌晨1:00:00 CN=微软远程认证服务 9ED7510E0D1073B6CEEE72B4C9A614E9F79E921F 2018年10月3日上午9:34:47 CN=“Snaiso,aba@snai

我有以下代码提取ssl证书的功能并将其存储在一个文件中,但他将每个值都写在一行中,我想知道如何确保在循环的迭代中,三个值都写在同一行上 为了让我自己清楚,这是我现在的输出

CN=localhost

BD94E0B92BEFFA09B2FB6EC302CE27792A7181

2022年10月4日凌晨1:00:00

CN=微软远程认证服务

9ED7510E0D1073B6CEEE72B4C9A614E9F79E921F

2018年10月3日上午9:34:47

CN=“Snaiso,aba@snaiso.com“,C=DE

5AB0ED72FE73F300A17A2434BB9E9FEE9EB16

2006年10月14日上午8:50:20

我想要的是

CN=localhost BD94E0B92BEFFA09B2FB6EC302CE27792A7181 2022年10月4日凌晨1:00:00 CN=“Snaiso,aba@snaiso.com“,C=DE 5AB0ED72FE73F300A17A2434BB9E9FEE9EB16 2006年10月14日上午8:50:20

下面是我写的代码

`   
$route = "Cert:\LocalMachine\My\"
$count = (Dir Cert:\LocalMachine\My\*).Count
$count=$count-1

For ($i=0; $i -le $count; $i++)
{ 
$subject = (Get-ChildItem $route)[$i].Subject
$thumb = (Get-ChildItem $route)[$i].Thumbprint
$expiredate = (Get-ChildItem $route)[$i].NotAfter
$startDate = Get-Date
$diff = (New-TimeSpan -Start $startDate -End $expiredate)
Add-Content -Path C:\Users\hmk\Desktop\file.txt -Value 
$subject,$thumb,$expiredate
}`

您可以使用
-Join
操作符执行以下操作:

$subject,$thumb,$expiredate -Join " "

请参见

您可以将字符串用双引号括起来:

Add-Content -Path C:\Users\hmk\Desktop\file.txt -Value "$subject,$thumb,$expiredate"
如果要存储的项目数量可变,则.net字符串将处理该问题

Add-Content -Path C:\Users\hmk\Desktop\file.txt -Value [string]::join(',' , @( $subject,$thumb,$expiredate) )

这篇文章的背景和最终目的是什么?对于结构化数据(如csv),可能有更好的拟合单行选项,而不是简单地将值集中在单行上