仍在学习并且我很难尝试将信息输出到文件:不接受输出文件路径。
我的位置是PS Cert:\localmachine,这里是整个命令:
$cert = Get-ChildItem -Path cert: -Recurse | where { $_.notafter -le (get-date).AddDays(75) -AND $_.notafter -gt (get-date)} | select notafter, issuer, thumbprint, subject | sort-object notafter
$cert | Out-File -FilePath \\ad.dcpds.cpms.osd.mil\WinAdm\Logs\Expiring_Certificates\$hostname.log
Run Code Online (Sandbox Code Playgroud)
我收到的错误消息是:
Out-File : Cannot open file because the current provider (Microsoft.PowerShell.Security\Certificate) cannot open a file.
根据上面的评论,问题来自当前位置在证书提供者 ( cert:)中的某个位置。一种可能的解决方法/解决方案是在写入文件之前将当前位置更改回文件提供程序。
$cert = Get-ChildItem -Path cert: -Recurse | where { $_.notafter -le (get-date).AddDays(75) -AND $_.notafter -gt (get-date)} | select notafter, issuer, thumbprint, subject | sort-object notafter
Set-location c:
$cert | out-file -FilePath \\ad.dcpds.cpms.osd.mil\WinAdm\Logs\Expiring_Certificates\$h??ostname.log
Run Code Online (Sandbox Code Playgroud)
第二种解决方案:使用明确包含文件系统提供程序的路径:
$cert | out-file -FilePath FileSystem::\\ad.dcpds.cpms.osd.mil\WinAdm\Logs\Expiring_Certificates\$h??ostname.log
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4822 次 |
| 最近记录: |