Page 1 of 1

PowerShell inside script.

Posted: 20 Dec 2017 23:02
by XSreyfQT4hV6
I am a completely newbie when learning scripting in XY
I am working on running powershell code from within XY and having it spit back data. Here is something i came up with.

Code: Select all

$cmd = """powershell.exe"" -ExecutionPolicy Bypass -Command ""mkdir c:\temp -ErrorAction SilentlyContinue;((ipconfig /all | Select-String IPv4) -replace '   IPv4 Address. . . . . . . . . . . : ','') -replace '\(Preferred\) ','' | Out-File C:\temp\IP.txt""";
 run $cmd,,1;
 echo readfile("C:\temp\IP.txt")
The powershell code doesnt really matter as it can be replaced but i am wondering if this is the best way to handle doing this.

Re: PowerShell inside script.

Posted: 20 Dec 2017 23:18
by highend
Em, doing what exactly, returning data?
Use set-clipboard/out-clipboard and read that from XY instead of creating a file...

Re: PowerShell inside script.

Posted: 20 Dec 2017 23:26
by XSreyfQT4hV6
Didnt even think of that :P
Thx

Is there an easy way to write a multi line file?

In bash you can do something like this. Wondering if there is a clean looking way to do it in XY

Code: Select all

cat >/etc/myconfig.conf <<EOL
line 1, ${kernel}
line 2, 
line 3, ${distro}
line 4 line
... 
EOL

Re: PowerShell inside script.

Posted: 20 Dec 2017 23:28
by highend
Use a Heredoc/Nowdoc

Re: PowerShell inside script.

Posted: 20 Dec 2017 23:31
by XSreyfQT4hV6
I will check it out. Thank you.