Microsoft Windows PowerShell command line shell and scripting language helps IT professionals achieve greater control and productivity. Using a new admin-focused scripting language, more than 130 standard command line tools, and consistent syntax and utilities, Windows PowerShell allows IT professionals to more easily control system administration and accelerate automation. Windows PowerShell is easy to adopt, learn, and use, because it works with your existing IT infrastructure and existing script investments, and because it runs on Windows XP, Windows Vista, and Windows Server 2003. Windows PowerShell is now included as part of Windows Server 2008 and can be evaluated in Windows Server 2008 Beta 3. Exchange Server 2007, System Center Operations Manager 2007, System Center Data Protection Manager V2, and System Center Virtual Machine Manager also leverage Windows PowerShell to improve administrator control, efficiency, and productivity.

Editing Mode

There are three editing modes:

I (Frédéric Perrin) started the second because of a lack of licence on Vivek’s mode. My version has more simple code for indenting (more robust and less imposing of a style in general than Vivek’s version), speedbar/imenu support, syntax highlighting (some features for v2 may be missing).
Frédéric told me he is ok with the ElispArea version being the version receiving long term maintenance (which I’m trying to provide) so hopefully we can now have just this one place for people to look. If I can’t be contacted or are unresponsive to your needs the license lets you pick up where we left off right here rather than creating yet another location for people to consider. Thanks.

Powershell as an Inferior Shell

Download Lisp:Powershell.el (updated 20 May 2010)


HTTP GET via Powershell

Some people report that the url.el exhibits problems when retrieving content from https: endpoints. This fn performs a “wget” using Powershell. Works only on Windows.

    (defun wget-via-powershell (url &optional ext)
      "get the contents of a URL into a file via powershell. The EXT
            is the extension to use on the destination file. It should begin
            with a dot.
      (flet ((rris (a1 a2 s) (replace-regexp-in-string a1 a2 s)))
        (let* ((ext (or ext ".txt"))
               (url-tmpf (make-temp-file "emacs-wget-" nil ext))
               (ps-cmd (concat
                        "(new-object System.Net.WebClient).DownloadFile("
                        (rris (char-to-string 34)
                              (char-to-string 39)
                              (pp-to-string url))
                        (rris "/"
                              (rris (char-to-string 34)
                                    (char-to-string 39)
                                    (pp-to-string url-tmpf)))
                (format "%s -Command %s"
                        (concat "\"& {" ps-cmd "}\""))))
          (shell-command-on-region (point) (point)
                                   nil nil nil)
          ;;(message "downloaded to %s" url-tmpf)


Just beginning to collect resources. I couldn’t archive copies of these files into the ElispArea, as there is no copyright info in either of them! – PatrickAnderson

FYI, there are copies of these files in EmacsW32 (which I am going to upload to Launchpad when I get time).

I’ve updated Powershell.el, with a copyright and proper license, as well as some tightening of the code. 20 May 2010. – DinoChiesa

Hi Dino. I upgraded to the latest version 0.2.1 from 0.1. The new version seems to have this problem. Start powershell, then close buffer. Then, when you start standard shell, it no longer have prompts, and is in fact running powershell, not bash or cmd.ex. – Xah Lee, 2010 June 24

Hi Xah. I’ll have to look into that. I’ve been out-of-the-office for an extended period, so I’m catching up on some old stuff. Will look into this and get back to you here. – DinoChiesa, 2010 Nov 13

When I ran it on emacs 23.1 it would fail with “invalid argument, looking for stringp got nil” (to that effect) on

    (if (string-match (concat "^" powershell-prompt-regex "\\(.*\\)\\'")

I changed the if statement to skip if power-shell-command-reply is null, and set it to “”, still get a startup error but it works (normally as far as I can tell but I’m not sure if I’m missing any highlighting I’m supposed to get. Here’s my workaround

        (if (and (not (null powershell-command-reply))
		    (string-match (concat "^" powershell-prompt-regex "\\(.*\\)\\'")
               (setq powershell-command-reply
                     (substring powershell-command-reply
                                (match-beginning 1)
                                (match-end 1)))
	     (setq powershell-command-reply "")