PowerShell inside script.

Discuss and share scripts and script files...
Post Reply
XSreyfQT4hV6
Posts: 18
Joined: 19 Nov 2017 00:06

PowerShell inside script.

Post 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.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: PowerShell inside script.

Post by highend »

Em, doing what exactly, returning data?
Use set-clipboard/out-clipboard and read that from XY instead of creating a file...
One of my scripts helped you out? Please donate via Paypal

XSreyfQT4hV6
Posts: 18
Joined: 19 Nov 2017 00:06

Re: PowerShell inside script.

Post 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

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: PowerShell inside script.

Post by highend »

Use a Heredoc/Nowdoc
One of my scripts helped you out? Please donate via Paypal

XSreyfQT4hV6
Posts: 18
Joined: 19 Nov 2017 00:06

Re: PowerShell inside script.

Post by XSreyfQT4hV6 »

I will check it out. Thank you.

Post Reply