Powershell Start-Process 文件名或扩展名太长

问题描述

在带有加密密码文件启动进程中使用凭据时,我收到一条错误消息。在我看来, start-process 参数凭据无法处理加密密码文件的长度。我通过将普通密码转换为安全字符串来测试代码,并在启动过程中使用安全字符串这将起作用。但是当我使用加密 pw 文件时出现以下错误消息。

start-process: 由于错误,此命令无法运行;文件名或扩展名太长

Invoke-Command 使用加密的 pw 文件没有问题。我认为变量的长度太长了 start-process 的参数 deklaration。内容长度为 324 个字符。 有人有想法吗?

$hostname = $env:computername
$pw_file_individual = 'c:\Scripts\secure_password_' + $hostname + '.txt'
$PW_File = Get-Content $pw_file_individual
$password = ConvertTo-securestring $PW_File -AsPlainText -Force
$username = "contoso\account"
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList ($username,$password)
$scriptfile = "C:\Skripte\test.ps1"

start-process powershell.exe -credential $creds -NoNewWindow -ArgumentList '-executionpolicy bypass','-file',$scriptfile -WorkingDirectory c:\windows\system32

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)