Time-Saving PowerShell Solutions for the Busy Admin
Time-Saving PowerShell Solutions for the Busy Admin
By Rod Trent
Brought to you by Windows IT Pro
sponsored by
Sponsored by NetApp
NetApp
Tech Advisor ? Windows IT Pro | p. 2
Contents
Time-Saving PowerShell Solutions for the Busy Admin
Simple Hyper-V Virtual Machine Management Using PowerShell
PowerShell One-liner:
Creating a new VM 10
Quickly Finding the IP Address
for Hostname and Vice Versas4 Removing an Existing VM 10
Run the Access Control App
Starting an Existing VM 10
to Configure Windows Remote
Management with PowerShell5 Stop a Running VM 10
Pausing PowerShell Script
Pause a Running VM 11
Execution6
Restart a Paused VM 11
PowerShell One-Liner:
Getting Local Environment
Save and Hibernate a VM 11
Variables6
Changing the Name of a VM 11
PowerShell Tip:
Outputting Information
Moving a VM to another
to HTML8 Hyper-V Server 11
Forcing PowerShell to Wait
Export and Importing
for a Process to Complete9 a Working VM 11
Brought to you by Windows IT Pro
Sponsored by NetApp
Rod Trent is the IT Community Manager for Windows IT Pro. He is a leading expert on Microsoft System Center technologies and has more than 25 years of IT experience, with over 20 years dedicated to System Center. Rod has written many books, thousands of articles, and speaks at various conferences and user groups. His professional focus is evangelizing technical community on the web and in person. Rod was a Microsoft MVP for 10 years and is a charter member of the Dell TechCenter Rockstar program.
Tech Advisor ? Windows IT Pro | p. 3
Introduction
PowerShell is the scripting language now embedded into every Microsoft business software product, allowing seemingly simple commands to expose powerful, automated solutions. For many Microsoft products, PowerShell is required to control, extend and manage various processes. PowerShell can be used to initiate simple tasks and inquiries and can also be strung together to automate more complex sets of operations, for instance within a private cloud environment. In the past, various scripting languages required months of study to do simple things, but PowerShell has changed all of that. Learning PowerShell seems extremely daunting to some, but once study starts, users find the simplicity to be refreshing.
PowerShell is a hugely powerful (pun intended) scripting language and Microsoft has invested a lot of resources and support behind making it an integrated part of every piece of the company's software offerings. It's really nothing to be afraid of and those that start down the path to learning find it simple and easy to understand. And, as the education progresses, it gets easier and easier.
This guide is intended to help IT professionals build a relationship with PowerShell, and aid in understanding how powerful simple, one-line commands can be.
Brought to you by Windows IT Pro
Sponsored by NetApp
NetApp creates innovative storage and data management solutions that deliver outstanding cost efficiency and accelerate business breakthroughs. Our deep integration with Microsoft products and technologies has been recognized and awarded by Microsoft when NetApp was named their 2012 Private Cloud Partner of the Year and 2013 Server Platform Partner of the Year. NetApp provides a comprehensive PowerShell Module with over 1,400 PowerShell cmdlets in our Data ONTAP PowerShell Toolkit for everything from simple task initiation to complex private cloud, back-up, and disaster recovery automation. Learn more at NetApp's PowerShell Toolkit Community
Sponsored by NetApp
Tech Advisor ? Windows IT Pro | p. 4
Time-Saving PowerShell Solutions for the Busy Admin
PowerShell One-liner: Quickly Finding the IP Address for Hostname and Vice Versa
When you're curious what the IP Address of a specific hostname might be, you can use a quick PowerShell one-liner to retrieve the information.
Run the following scriptlet in the Windows PowerShell window and insert your own hostname for which you're wanting to locate the IP Address.
[.Dns]::GetHostAddresses("")
Output:
Alternatively, if someone gives you an IP Address and you'd like to determine the hostname to which it is associated, run the following scriptlet:
[.Dns]::GetHostbyAddress("206.72.117.68")
Output:
Brought to you by Windows IT Pro
Sponsored by NetApp
Tech Advisor ? Windows IT Pro | p. 5
Run the Access Control App to Configure Windows Remote Management with PowerShell
PowerShell is powerful, for sure. But, with that power comes great, uh, responsibility. Part of that responsibility is ensuring commands can be run remotely, and by the right people. If you need to adjust the Access Control List for utilizing PowerShell commands on remote computers, you'll first need to know how to open the UI for managing and modifying the ACLs.
Do this:
1. As an Administrator, run the following at a PowerShell prompt:
Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell ?Force
2. You'll be prompted to ensure that the WinRM service is running. Answer "Y" (Yes) to start the Windows service.
3.Once the service is started the Access Control applet will run, allowing you to make modifications:
We'll go deeper into PowerShell remoting in future articles, but, this will get you started down the path and give you another "cool thing" to know.
Brought to you by Windows IT Pro
Sponsored by NetApp
Tech Advisor ? Windows IT Pro | p. 6
Pausing PowerShell Script Execution
There are various reasons to pause a script. For one, you may need to verify that a section of your script has processed correctly before allowing it to continue. In other cases, you may want to halt the script's execution so you can perform some manual tasks or run a second script to compare results. And, another example might simply be that you want to give the end-user some instructions or allow them to take part in the flow of what is happening on their PC.
Here's a quick scriptlet to add to your own scripts that displays a message and also waits for a key to be pressed before the PowerShell script continues.
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
PowerShell One-Liner: Getting Local Environment Variables
Before you can start working with the computer's environment variables, it helps to be able to retrieve the current list to show what's available to work with. In some upcoming articles, I'll show how to add, modify, and delete environment variables, and then give some examples of how to utilize them. But, let's start by finding out what's available for use.
Retrieving the list of current environment variables is as simple as running this in Windows PowerShell:
Brought to you by Windows IT Pro
Sponsored by NetApp
Tech Advisor ? Windows IT Pro | p. 7
Get-ChildItem Env: Once you kick off that quick command, something similar to the following will display for you:
After you have the names and values, you can even pare down your results to specific environment variables. Using the PATHEXT from the Namecolumn, run the same command as before except insert PATHEXT at the end like this:
Get-ChildItem Env:PATHEXT
Quick and simple, that single modification retrieves just the Value for the PATHEXT as shown in the following image:
Brought to you by Windows IT Pro
Sponsored by NetApp
Tech Advisor ? Windows IT Pro | p. 8
PowerShell Tip: Outputting Information to HTML
Working within the PowerShell cmd window can be somewhat limiting, particularly if the command you entered contains lines and lines of return data. For example, running the Get-Service command on its own will retrieve and list all of the installed services on the computer. As shown in the following image, the displayed information scrolls the information off the screen.
Yes, you can use the scrollbar to review the retrieved data, but what if the information is 10, 20, or 50 scroll pages long?
Here's a quick tip.
Using the ConvertTo-HTML command, you can push collected information to an HTML file in the file system. This is useful, too, if you simply want to store the data to read later, or use as an archive for comparative processes.
Here's the format (still using the Get-Service example):
Get-Service | ConvertTo-HTML > C:\temp\services.htm
Here's an example output:
Brought to you by Windows IT Pro
Sponsored by NetApp
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- powershell progress bar examples
- time saving powershell solutions for the busy admin
- powershell 2 0 one cmdlet at a time
- powershell umd
- 안 전문가를위한파워쉘 amazon s3
- windows powershell for
- attackers arsenal cybereason
- this data step has been running for ages can you
- script to run few actions from control panel configuration
Related searches
- natural solutions for pink eye
- for the first time meaning
- for the time being poem
- crm solutions for small business
- ed solutions for senior men
- saving bond calculator for windows 10
- email solutions for small business
- solutions for ed
- ncert solutions for class 8
- solutions for rising college tuition
- find solutions for quadratic equation
- ncert solutions for class 9 science