How do you use PowerShell?

2019-03-08 08:05发布

Windows PowerShell came out last year and got great reviews from many .net bloggers (Hanselman comes to mind). It seemed to be touted as a great new utility that somehow made everything that you would ever do on the command line easier, and integrated with .Net. However, the more I read about it, the more it seems to be a tool that is great for IT professionals, and not much use for developers.

Do you use PowerShell in your dev work? If so, how? Is it worth learning?

Note: After seeing the responses so far, I think it is valid to conclude that PowerShell can be very useful to a .Net developer. However, there is no one answer below that I can label as the answer (so please forgive me for not doing so). I am voting up each answer that I have found helpful.

14条回答
做个烂人
2楼-- · 2019-03-08 08:51

Personally, I'm using Python for automating tasks, using WMI if needed. I think that this combination covers most of my needs.

I tested PowerShell, it looks fine to me, but it doesn't worth learning a whole new tool. Besides that, there are excellent resources online to master PowerShell if you need or wants to (PowerShell Live), or even recipes to accomplish tasks without having to pass the whole learning curve for yourself.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-08 08:53

I'm an admin by trade and just starting in the "Dev" world, but I see that PowerShell can be very useful to developers in a number of ways.

  1. Task automation -> Lee Holmes (a developer on the PowerShell team) posted a proof-of-concept called BgShell, which was basically the PowerShell runtime hosted in a windows forms app that listened for keystrokes and kicked off actions written in PowerShell based on them. It also included some clipboard automation.
  2. Quick access to the .NET framework. You don't have to compile and run something or use another program like Snippet Compiler to test some functionality. Load the assembly into your PowerShell session and interact with it. You get all the discoverability of PowerShell (like Get-Member) to explore your object.
  3. Easy to build domain specific languages. James Kovacs wrote a simple build script language with PowerShell called Psake.
  4. It can provide a scripting language for your application. Since PowerShell is part of the 09 Common Engineering Criteria, a lot of Microsoft applications will have interfaces for PowerShell, and familiarity with the language syntax will grow. You can leverage that knowledge by embedding the PowerShell runtime in your application and providing a scripting interface to your users, choosing what objects they will have access to.
  5. Along the same line, if you need to create a command-line interface for your application, PowerShell provides a large part of the underlying plumbing needed for parsing arguments, and other basic tasks, leaving only the business logic for you to write, and providing a consistent interface with other applications (for example, if you have user accounts that need to be managed (that don't already integrate with Active Directory, an admin could (using the Quest AD Cmdlets and your applications interface) Get-QADUser | New-MyApplicationUser and be done. The Exchange 2007 team did this very well. All the functionality is based on PowerShell cmdlets, the GUI calls the cmdlets and shows the user what is being run, so they can build scripts based off of that.
  6. It's just cool! In about 250 lines (including comments), Rob Foust and Jeff Hicks wrote a network sniffer in PowerShell. Easier to use than WinDump for lightweight troubleshooting.
  7. Community - There is a great community focused around PowerShell, including developers. Find out more at PowerShellCommunity.org.
查看更多
你好瞎i
4楼-- · 2019-03-08 08:53

I use PoSH for any 'repetita' job I've to do for administering networks, domains, computers, AD users, text editing, files searching, file-servers migrations, monitoring and also have fun!

查看更多
爷的心禁止访问
5楼-- · 2019-03-08 08:54

I use it very little for actual dev work. I've used it to setup virtual directories automatically and execute a scipt that sets up IIS with the same settings on all our dev machines

查看更多
可以哭但决不认输i
6楼-- · 2019-03-08 08:56

I use it to automate as much things as I can. One example is Web UI Automation, to ease application development/testing.

i also use it to generate random input files for various programs. For example, one application is expecting an XML file, and I have a script to build that file with random values and a unique id based on the current time.

I don't use it heavily, but I use it every day.

查看更多
时光不老,我们不散
7楼-- · 2019-03-08 09:01

It's never come in use as part of my development role, but every now and then I get a task that I'd write a small program to automate, which I now force myself to do in powershell and it takes less time.

For example, I recently moved hundredsthousands of files from one server to another using xcopy and forgot to set the attribute to preserve the creation dates on the files. Powershell to the rescue. Within ten minutes I had a script written and tested that copied the creation dates over without having to re-copy the files.

查看更多
登录 后发表回答