New-Item 2.bat -type file -force -value "'
$passwd='Umesh_Pithiya' `r`n
$pass=$passwd.substring(9) `r`n
$pass=$pass.substring(1,$pass.length-2) `r`n
$pass=convertto-securestring $pass -asplaintext -force `r`n
"
'
='Umesh_Pithiya'
=.substring(9)
=.substring(1,.length-2)
=convertto-securestring -asplaintext -force
$passwd='Umesh_Pithiya'
$pass=$passwd.substring(9)
$pass=$pass.substring(1,$pass.length-2)
$pass=convertto-securestring $pass -asplaintext -force
'
答案 0 :(得分:2)
'
而不是"
来创建逐字字符串。将其构造为here-string @''@
,以避免文本中的单引号终止字符串:
New-Item 2.bat -type file -force -value @'
$passwd='Umesh_Pithiya'
$pass=$passwd.substring(9)
$pass=$pass.substring(1,$pass.length-2)
$pass=convertto-securestring $pass -asplaintext -force
'@
答案 1 :(得分:0)
您可以使用here string:
New-Item 2.bat -type file -force -value @'
$passwd='Umesh_Pithiya'
$pass=$passwd.substring(9)
$pass=$pass.substring(1,$pass.length-2)
$pass=convertto-securestring $pass -asplaintext -force
'@
请注意,您现在不需要退出回车符和换行符。另外,使用单引号来避免变量扩展。