Reputation: 28
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
'
Upvotes: 0
Views: 104
Reputation: 62472
You can use a 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
'@
Note that you don't need to escape the carriage return and line feeds now. Also, use the single quote to avoid variable expansion.
Upvotes: 0
Reputation: 174485
'
instead of "
to create a verbatim string. Construct it as a here-string @''@
to avoid the single-quotes inside the text terminating the 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
'@
Upvotes: 2