We need to execute the command below using a specific domain account we created, but I am having trouble passing the command to the new Powershell session. The error I am getting is
"...The directory name is invalid"
However, when I execute something simple like running IE using the same code, everything works fine.
##Create new credential
$username = "DOMAIN\Username"
$password = "P@ssword"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
##ScriptBlock to pass to new PS Session started with new credential
$ScriptBlock = {
$args = "/s"
$username = "DOMAIN\Username"
$password = "P@ssword"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process -FilePath C:\TEMP\WinMagic\SecureDoc_64.exe -WorkingDirectory C:\TEMP\WinMagic\ -credential $credentials
}
##Execute new powershell session with new credential and scriptblock
Start-Process -FilePath powershell.exe -credential $credentials -ArgumentList "-noexit" , {$ScriptBlock}