Twelve PowerShell command line tips, tricks and helpful hints

Don't let the PowerShell command line overwhelm you. We collected some of the most important info, and broke it down into 12 easy-to-digest pieces.

Windows continues to place more and more emphasis on the PowerShell command line, with the scripting language now forming the basis of many of the vendors' core products. While more widespread use means PowerShell is more powerful than ever, it has also led to a staggering number of cmdlets to sort through, which can make learning the syntax that much more difficult.

Even if you're already a PowerShell pro, here are 12 straightforward tips that can help you up your game.

  1. PowerShell and XML: For PowerShell to understand XML, you must force it to parse XML, which runs it through the .NET Framework's XmlDocument class and builds a document object model from it. If the XML doesn't parse or validate, then you'll get an error.
  2. PowerShell remoting: Remoting is enabled by default in Windows Server 2012, but to manually enable the feature in earlier versions, consult the free e-book Secrets of PowerShell Remoting.
  3. PowerShell and WWF: The PowerShell code in a workflow must be translated to something WWF understands, so the switch construct can't be used in WWF, but you can use a special parallel for each construct to have PowerShell perform multi-threaded activities.
  4. Searching for commands: PowerShell v3 automatically includes commands from all installed modules when it searches for commands, but if you try to run a command that isn't loaded, the shell implicitly loads it in the background for you.
  5. PowerCLI and vCloud: The abstraction layer introduced by vCloud Director 1.5 allows you to use PowerCLI scripts to search for virtual machines (VMs) and collect granular information.
  6. PowerCLI and View management: Using PowerShell scripts to reset and rebuild your environment is often faster than using the Web-based administration tools. The cmdlets and scripting can also be used to build a consistent layout to your View environment.
  7. Migrating VMs: You can migrate any VM, regardless of what cluster it's in, with a PowerShell script. You simply need the name of the cluster alias, the exact name of the clustered VM resource and the destination node.
  8. XenServer PowerShell snap-in: To run the PowerShell snap-in on a 64-bit system, run the following command from an elevated command prompt to register the DLL with the 64-bit .NET Framework: C:\windows\microsoft.net\frameowkr64\v2.0.50727\installutil.exe "c:\program files (x86)\citrix\xenserverpssnapin\xenserverpssnapin.dll"
  9. VMware vSphere PowerShell snap-ins: VMware.ImageBuilderallows for the creation of custom ESXi images and media that you can launch with Auto Deploy, or you can also use these images as standalone installation media.
  10. PowerShell Web Access: Introduced with PowerShell v3, PowerShell Web Access is acomplete Web-based command-line window that supports multiple simultaneous connections and tab completion and can be secured with an HTTPS connection. Just remember Internet Information Services is a prerequisite for this feature.
  11. Windows Task Scheduler and PowerShell: With scheduled PowerShell scripts, you need to ensure that the proper execution policies are in place. All scripts you execute using the Task Scheduler should be signed using a code signing certificate issued by a certificate authority.
  12. PowerCLI and the vSphere API: The vSphere API is much more structured than an operating system. PowerCLI is built on top of the same API, which means that you can't use PowerCLI to directly perform tasks inside the console OS.
This was first published in September 2013

Dig deeper on Virtual machine provisioning and configuration

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close