windows 如何从 CMD.exe 切换到 Powershell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/868318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:29:44  来源:igfitidea点击:

How can I switch from CMD.exe to Powershell?

windowspowershellcmd

提问by Cheeso

I have this idea that I should switch over from cmd.exe to powershell. It's so much more powerful than the tried and tested cmd.exe. It is the shell of the future for Windows.

我有一个想法,我应该从 cmd.exe 切换到 powershell。它比久经考验的 cmd.exe 强大得多。它是 Windows 的未来外壳。

But my facility in powershell is so limited, in comparison with cmd.exe. Around every corner I discover another seemingly small obstacle that is insurmountable.

但是与 cmd.exe 相比,我在 powershell 中的功能非常有限。在每一个角落,我都发现了另一个看似无法逾越的小障碍。

Today I tried to ctrl-C to stop a running program, inside a powershell, and it had no effect. ??
Last time through it was "how to do a 'dir /o' in powershell?" I know how to do for loops in .cmd scripts, how do I do that in powershell?

今天我试图在 powershell 中按 ctrl-C 来停止正在运行的程序,但没有效果。??
上次通过它是“如何在powershell中执行'dir / o'?” 我知道如何在 .cmd 脚本中执行 for 循环,我如何在 powershell 中执行此操作?

I need some advice: First, is it a good idea to try to switch to powershell?

我需要一些建议:首先,尝试切换到 powershell 是个好主意吗?

If so, question 2 is: what are your recommendations on how to break the cmd.exe habit?

如果是这样,问题2是:您对如何打破cmd.exe习惯有什么建议?

  • Should I just post every question to Stackoverflow?
  • Should I dedicate a full day to learning powershell? is there a training course I can take?
  • is there a good cookbook of common powershell recipes? a powershell wiki I can ingest?
  • 我应该将每个问题都发布到 Stackoverflow 吗?
  • 我应该花一整天时间学习 powershell 吗?有我可以参加的培训课程吗?
  • 是否有一本关于常见 Powershell 食谱的好食谱?我可以摄取的 powershell wiki?

回答by ólafur Waage

回答by Peter Seale

To help ease the transition, remember you can always run the original DOS commands by prefixing any command with "cmd /c". E.g.

为了帮助简化转换,请记住您始终可以通过在任何命令前加上“cmd /c”来运行原始 DOS 命令。例如

cmd /c dir /s
cmd /c start .

There are, of course, PowerShell equvialents, but this trick will help you stay productive with what you know while learning PowerShell.

当然,也有 PowerShell 等效项,但这个技巧将帮助您在学习 PowerShell 时利用所学知识保持高效。

回答by aphoria

I've been in the same situation. What I finally did was close my CMD window that was normally open all day and keep the PowerShell window and force myself to only use it.

我一直处于同样的情况。我最终做的是关闭我通常整天打开的 CMD 窗口并保留 PowerShell 窗口并强迫自己只使用它。

I only resorted to CMD when something was urgent and I didn't feel I could take the time to figure it out in PS.

我只在有紧急情况时才求助于 CMD,我觉得我无法花时间在 PS 中弄清楚。

I'm still not quite as proficient in PS yet, but I'm getting better everyday.

虽然我的PS还不是很熟练,但我每天都在进步。

Below are a couple good books and some links to some good resources.

下面是一些好书和一些好资源的链接。

I liked these two books a lot:

我非常喜欢这两本书:

Also, check out these sites:

另外,看看这些网站:

回答by Keith Hill

I second the recommendation to read Windows PowerShell in Action. If however, you don't want to part with that much $$ just yet, check out this free eBook I put together: Effective PowerShell. Also, do give PowerShell some time. I think it will pay off in spades on the backend.

我支持阅读 Windows PowerShell in Action 的建议。但是,如果您还不想花那么多钱,请查看我整理的这本免费电子书:Effective PowerShell。另外,一定要给 PowerShell 一些时间。我认为它会在后端得到回报。

回答by Mark Broadhurst

It just seem isurmountable when you start stick with it.

当你开始坚持它时,它似乎是可以克服的。

in Powershell the key combo for critcal stop is Ctrl + Break

在 Powershell 中,关键停止的关键组合是 Ctrl + Break

Ir terms of sorting there is a Sort-Object commandlet so you can sort by any property.

就排序而言,有一个 Sort-Object commandlet,因此您可以按任何属性进行排序。

So you can call Get-ListItems | Sort-Object. Its worth trying to learn the commandlet names rather than the alias its associted to.

所以你可以调用 Get-ListItems | 排序对象。值得尝试学习命令行开关名称,而不是与其关联的别名。

If all else fails ask here theres always a lot of knoweldge to go around.

如果所有其他方法都失败了,请在这里询问总是有很多知识可供参考。