When I am running a PowerShell script normally it's working fine, issue is raising when calling the same script from batch file.
Unt1.ps1
script:
$linux_app_user="ORXXXX\"+$args[0]
$pass_win=$args[1]
$path=$args[2]
$pass = ConvertTo-SecureString -AsPlainText $pass_win -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList
$linux_app_user, $pass
$Invoke-Command -ComputerName XXXXXXXX.XXXX.XXX.XXXX -Credential $cred -ErrorAction
Stop -ScriptBlock {
param($path)
Invoke-Expression $path
} -Arg $path
cal.bat
script:
@echo off
SET Server=slXXXXXXXX.XXX.XXXX.com
SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
CD /D "%PowerShellDir%
powershell.exe -ExecutionPolicy RemoteSigned -File
C:\Users\chaj\Documents\String\Unt1.ps1 'XXXX' 'XXXX@321' 'C:\cal.bat'
Error:
[xxxxxx.xx.xxxxx.xxx] Connecting to remote server xxxxxx.xx.xxxxx.xxx failed with the following error message : The user name or password is incorrect. For more information, see the about_Remote_Troubleshooting Help topic. At C:\Users\chafg\Documents\String\Unt1.ps1:7 char:1 + $Result=Invoke-Command -ComputerName xxxxxx.xx.xxxxx.xxx -Credenti ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (xxxxxx.xx.xxxxx.xxx) [], PSRemotingTransportException + FullyQualifiedErrorId : LogonFailure,PSSessionStateBroken
cal.bat
? The only correct line is currently@echo off
– Compocal.bat
content is still incorrect. These are non-critical:1.
It doesn't use the recommended syntax for theSET
commands, i.e.SET "VarName=StringValue"
,2.
There is a missing closing doublequote on yourCD
filepath. These are critical3.
you have missed a line concatenation character or added an unwanted line break, andcmd.exe
does not treat single quotes,'
, in the same way aspowershell.exe
does for strings. – Compocmd.exe
is incidental in this scenario (except if you had unescapedcmd.exe
metacharacters inside'...'
): the issues is that with-File
, PowerShell doesn't recognize single quotes as string delimiters either and considers them part of the data. – mklement0