7

After installing nushell (https://www.nushell.sh/) in my windows environment, I want to use the power of nushell in conjunction with powershell.

For example, I need to invoke common powershell commands in my daily work like

> get-service *myservice -computername remote | restart-service

But how to invoke such command (with pipeline) from nu shell?

Do I need to start nu shell from powershell or vica versa? Also the invocation with the ^ sign seems to not work. I always get "command not found" and for sure it is no DOS command.

It would be nice to get the power from both worlds on windows ... nu shell and powershell

2 Answers 2

3

You can run a one-off command in PowerShell using the -command flag.

So from Nu (or cmd.exe or any other shell), something like this will work:

pwsh -command "echo 'Hello from PowerShell'"

(you may need to replace pwsh with powershell if you want an older Windows Powershell version)

Sign up to request clarification or add additional context in comments.

Comments

3

Given your example, I'm not sure there's much there that you could use to combine PowerShell and Nushell. In that particular case, you'd just run the PowerShell command from inside Nushell as mentioned in the previous answer, such as:

pwsh -c "get-service *myservice -computername remote | restart-service"

However, let's say that you want to convert structured PowerShell output to structured Nushell objects. You can use JSON for that purpose. For example, in Nu:

(pwsh.exe -c "Get-Service -ErrorAction Ignore | ConvertTo-Json -WarningAction Ignore") | from json | where Status == 1

Note, however, that you may pretty quickly run into the issue that I describe in this Unix & Linux question, in that JSON results typically end up as a Nushell list rather than a table.

It's possible to start the pipeline from either inside Nu, calling PowerShell, or vice-versa.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.