【发布时间】:2019-02-26 01:19:30
【问题描述】:
我正在尝试做的事情的简要总结。 我在 powershell 中有一个脚本,它需要 2 个文件并读取嵌入式凭据并将它们存储在一个变量中,然后我可以从中运行管理命令。
这很好用,但是,在读取文件并存储密钥后,我试图删除这 2 个文件,但我不断收到以下错误:
Start-Process : 参数集无法使用指定的解析 命名参数。在 \mars\Client-Installs\NetSmart Test3\Setup.ps1:137 字符:15 + Start-Process
Start-Process : 参数集无法使用指定的解析 命名参数。在 \mars\Client-Installs\NetSmart Test3\Setup.ps1:138 字符:15 + Start-Process
我运行的帐户是域管理员的一部分,当我查看任务管理器时,我可以看到它在管理模式下运行。
我还知道文件所在的文件夹路径也具有完全共享和安全访问权限。
这是我的代码片段(底部 2 行似乎不起作用)
function Authentication
{
#---------------------------------------------------
#Authenticate Admin Account using encrypted password
#---------------------------------------------------
$TempFolder = $env:temp
#The 2 lines underneath is if you are running the auth files from the same directory
#$global:AESKeyFilePath = $path + "\aeskey.txt"
#$global:SecurePwdFilePath = $path + "\credpassword.txt"
#Move the files to the temp folder
$global:file1 = $path + "\aeskey.txt"
$global:file2 = $path + "\credpassword.txt"
Copy-Item -Path $file1 -Destination $TempFolder -force
Copy-Item -Path $file2 -Destination $TempFolder -force
#If you choose to run it from the temp directory comment the lines above and uncomment the 2 below.
$global:AESKeyFilePath = $TempFolder + "\aeskey.txt"
$global:SecurePwdFilePath = $TempFolder + "\credpassword.txt"
$global:userUPN = "domain\user"
#use key and password to create local secure passwordtemp
$global:AESKey = Get-Content -Path $AESKeyFilePath
$global:pwdTxt = Get-Content -Path $SecurePwdFilePath
$global:securePass = $pwdTxt | ConvertTo-SecureString -Key $AESKey
#create a new psCredential object with required username and password
$global:adminCreds = New-Object System.Management.Automation.PSCredential($userUPN, $securePass)
#Remove the files below
Start-Process -FilePath "powershell.exe" -Credential $adminCreds -WindowStyle Hidden -ArgumentList "Remove-Item -Path $file1 -Force" -WorkingDirectory $path -NoNewWindow -PassThru
Start-Process -FilePath "powershell.exe" -Credential $adminCreds -WindowStyle Hidden -ArgumentList "Remove-Item -Path $file2 -Force" -WorkingDirectory $path -NoNewWindow -PassThru
}
【问题讨论】:
标签: powershell admin administrator start-process