Sharing thoughts, experiences and knowledge. Primarily focused on technologies in and around the Windows management space.
Thursday, December 18, 2014
Setting up a lab
Monday, December 1, 2014
Why are my cmdlets not working? Duh!
Friday, September 5, 2014
Windows Management Framework 5.0 - September Preview
Like a kid in a candy shop - well a sort of geeky kid
- Setting up Azure Virtual Machine to begin testing some upcoming products!
- Digging into some PowerShell/Azure synergy I haven't played with yet
- Reviewing the WMF 5.0 September Release
- Working on multiple sessions/webinars/conference proposals
- DSC and Group Policy - compliance for the desktop
- Longer is Stronger - why passphrases are powerful
- PowerShell basics - training sessions for our customers
- Manage Zip files! - the little things are sometimes great!
- Compress-Archive
- Expand-Archive
- Lots of DSC stuff
- Register a PSRepository with PowerShell Get sounds interesting - hosted modules - work from anywhere? we will soon see
- Switch management - more evolution
- ISE updates to make working with DSC easier
Friday, August 22, 2014
Group Policy 002: The Cmdlets - New-GPO
Simple!
Monday, August 4, 2014
C'Mon Man! - wasted time - PowerShell Help
PowerShell Help
- Get-Command
- Get-Module
- Get-Help
- Get-Help -Full
- Get-Help -ShowWindow
- Get-Help -Examples
- Get-Help -Online
The Problem
Saturday, June 28, 2014
PowerShell 009 - Get-Help -ShowWindow
Help... huh... what is it good for?
The help system in PowerShell is one of the features that makes the new shell so accessible. Once you get used to the system you ask PowerShell questions and it gives you answers. You ask it to clarify, and it does. You ask for more details, it gives you more details. You ask for examples, it gives you examples. It is really, really great.I was working through some best practices by some of the PowerShell MVPs and I was finding some sample scripts and advanced functions on TechNet and realized that often times writing good help is skipped.
I'm optimistic that the amount of help content I consume will burn into my brain the value of taking the time to write good help content.
-ShowWindow
You can write the help content to the screen and read it from the console. You could even send it right out to a printer, but don't! ("I speak for the trees, for the trees have no tongues" - The Lorax) Sending the help content to the console window is great. When working quickly I often will simply look at examples to get me started;PS> Get-Help Get-CimInstance -Examples
If I want to see all of the content in the console window;
PS> Get-Help Get-CimInstance -Full
Great. Quick, moves the ball forward nicely. But when learning the subtleties of cmdlets there is often an extensive amount of content to go through. PowerShell's ISE provides a way to throw the content into a single window. It also provides some very interesting features to assist. To get the full content in a separate window type;
PS> Get-Help Get-CimInstance -ShowWindow
Your help content is now in a separate windows. Makes research and troubleshooting much easier in my opinion.
My poor eyes! The text is small, my reading glasses are in the other room, my backup reading glasses are in the couch cushions and my backup, backup reading glasses are who knows! But look... in the bottom right hand of the screen there is a slider bar that allows you to magnify the text... nice! Thanks Microsoft! (you can also <CTRL> & + to increase the font size)
Narrow It Down
OK, now there is a lot of content. How do I find what I am looking for. Get-CimInstance (the cmdlet I chose for the example) seems pretty confusing. The first thing I see is syntax. Lots of syntax. There are almost 10 parameter sets to deal with. Seems to be lots of parameters. I'm betting there are lots of examples.Right at the top left side of the screen you will see a 'Find:' feature. Simply type in the word or phrase you are looking for and let PowerShell (well the ISE) help you.
In the upper right you will find a button called 'Settings'. Click this button and select only the 'type' of content you want displayed in the window.
It is all pretty self-explanatory. Make sure you spend time here. I have surely heard this message from the PowerShell gurus out there and taken it to heart. Another lesson I'm learning the more I develop scripts and tools with PowerShell is the importance of formatting... but that is a discussion for a different day.
Friday, June 20, 2014
PowerShell 008 - $Profile
$Profile - what is it good for?
What is put in the profile script?
- Add-PSSnapIn -Module specopssoft.specopspasswordpolicy
- Import-Module -Module specopsdeploy
- Update-Help
- Update-Help -Module Hyper-V
- Set-Location c:\psstuff
How to Update the profile script
And that is that
Wednesday, April 16, 2014
PowerShell 007 - Building the pipe
A Step Back
OK, so I’m a big fan of get-help. I use it just about every time I sit at the PowerShell_ISE. It is partly because I’m old and can’t remember everything, partly because there is simply too much to know, and, as Jeffrey Snover says “I am a flawed human being”. You should check out the Virtual Academy PowerShell Jumpstart session with Jeffrey Snover and Jason Helmick. These two are great Edutainers. So, even if I forget to mention the help system use it and the community to learn.As you may know, or possibly not yet, PowerShell is a system that returns objects back on request. Even though you may only see a small bit of data returned to the screen the object returned may include much more data. For a quick example, if I want to look at the most recent log entry in my application log I can type;
PS\> Get-EventLog –LogName Application –Newest 1
This returns something like this.
Index, Time, EntryType, Source, InstanceID and Message. It provides some very important data and often this is all I may need to look at. But if I want to see the whole object I can try;
PS\> Get-EventLog –LogName Application –Newest 1 |format-list *
The above means get the same data but display the object in a list, as opposed to a table, and show me the entire (*) object. It looks like this.
Lots more data. For different cmdlets there is going to be different data returned to the screen, which is a sub-set of the entire object.
I actually did something else here. I ‘piped’ the object returned from one cmdlet to another.
Pipeline
Above the simple example takes the single object output from my Get-EventLog cmdlet into the Format-List cmdlet. Great for organizing your output. What happens if you have a cmdlet that returns a lot of data?PS\> Get-EventLog –LogName Application |Measure
This counts how many objects to output. Right now I would return a measly 2685 events as individual objects. Small application log but way too much to handle. I want to pipe the output to another cmdlet, Select-Object, to trim down the output a bit.
When I pipe the output to Select-Object I can narrow down based on the properties of the object.
PS\> Get-EventLog –LogName Application | Select-Object –Property EventID, MachineName, –First 20
The above uses Select-Object to only show two properties, EventID and MachineName for the first 20 entries in the log.
You can narrow by any data that you are looking for. What if you want to see Source, or EntryType. Just use those properties in your list and you are good.
I find the pipeline to create an incredibly intuitive, readable system that at first glance can look very complex. It reads like a bit of a work flow.
- Get all events in the application log
- Select from that list the first 20 events
- only prepare the EventID, MachineName, Source and EntryType.
- Export the data to a webpage
Other than some typos…
Wednesday, April 9, 2014
SMH - Windows 8, Windows 8.1, Windows 8.1 Update 1
Not what you are expecting?
Saturday, April 5, 2014
PowerShell 006 – WMF v5 and OneGet
Windows Management Framework v5 Preview
WMF V5
Jeffrey Snover posted an announcement of the WMF V5 preview on the Windows Server Blog. The post and a download link to get the new bits is here.
There are a few very interesting pieces here and it is another step in the growth of the framework and PowerShell. I’m personally a little unsure of the reach and extension of the framework into realms ‘unmanaged’ or out of the control of Microsoft. When software vendors provide their modules they take responsibility, with the WFM V5 and especially the OneGet functionality the line is a bit blurred. Who is responsible if OneGet isn’t working? MSFT? Chocolatey? other source providers? At the end of the day, OneGet is pretty cool.
OneGet
From the Windows Server Blog “OneGet is a new way to discover and install software packages from around the Internet. It will simplify the acquisition of all kinds of software and make installation and discovery ‘easy peasy’ as they say.
Much of the OneGet capability is very interesting. I have a few areas that cause me some concern. I’m am willing to be convinced so I’ll spend some time checking it out. After I setup WMF 5 this morning I used the Get-Command cmdlet to find the OneGet cmdlets. After I found the basics I ran;
PS C:\> Find-Package |Export-csv packages.csv
This first informed me that it needed to retrieve NuGet Package Manager. It then gave me a list of all of the packages available via the provider Chocolatey. There are roughly 1750 packages today (4/4/2014). I wanted to learn more so I decided to check to see if my help files were up to date.
PS C:\> update-help
Uh Oh! update-help throws an error when grabbing help on the ‘OneGet’ and ‘NetworkSwitch’ Modules. Honestly not a great place to start but it is preview! So, learning what parameters are required, mandatory, allow for wildcards etc. may have to wait a bit. Or I can just sit at my computer for hours trying different things!
I did look through my .csv file and found Notepad++ and I decided to set that up.
PS C:\> Install-Package -Name notepadplusplus
After a brief warning about the package not being marked as safe and me ignoring the warning, it downloaded any dependencies and installed the package. Pretty cool if you ask me.
NetworkSwitch
Last year at TechEd I ran into Jeffrey between sessions and had a chance to catch up. Jeffrey is an incredibly accessible guy and so enthusiastic. Just a great person to chat with. I have a few great Jeffrey Snover stories from some projects I had the pleasure of working while at Microsoft, but those are for a different post <G>. During that brief discussion Jeffrey shared with me how one of his visions around Desired State Configuration (DSC) was managing switches, well… here we are! Read through the Windows Server Blog announcement on WMF v5 Preview to learn more about this capability.
Sunday, March 30, 2014
PowerShell 005 – Install-ADDSForest
Setting Up a Lab
DCPromo has come a long way in the past 13 + years. Windows Server all up is so incredibly different, more powerful, more intuitive, more manageable. It is simply a great operating system to work with. I have a very specific scenario that I want to talk about here. That is setting up a lab.
There are many ways to do this, and they all have their benefits. I want to start simply. The first machine in the lab, setup as the forest root, your first DC.
The Scenario
This is not simply building a new lab. This is the re-building process that many of us go through every couple of months to get a clear setup to test with. Building the lab manually is a powerful experience especially when you are being introduced to a new OS. In this case I’m running Windows Server 2012 R2. I want to walk through the creation process manually to see if anything noticeable has changed. In this case I have already installed the Active Directory Domain Services Role and now it needs to be configured. This is the DCPromo process we have used for years. The task is initiated from within Server Manager.
After you install the AD DS role you will notice a flag informing you that you now need to ‘promote’ this server to function as a Domain Controller.
Click ‘Promote this server to a domain controller’ and the ‘Deployment Configuration’ Wizard will start.
The purpose of this post is not to walk through the configuration of the domain. In summary you can add a new DC to a domain, add a new domain or create a new forest. I’m going to create a new forest.
After walking through basic configuration, naming your domain, DC options, functional levels, NetBIOS naming, paths to files etc. etc. etc. You will come to a page in the wizard called ‘Review Options’. Along the way there are lots of links to additional information. If you are new to AD or new to Windows Server 2012 R2, take the time to read this information. It will save you time in the future.
Notice the ‘View script’ button in the bottom of the dialog. Hmmm… what could that be?
A simple PowerShell script to configure your first DC. You don’t need to, or want to, run the wizard every time you need to rebuild your lab. Simply save this script as a .ps1 file. Save it in a place that you will keep to use every time you build out a new lab.
I am going to cancel the wizard after I save the script. I want to execute this DC Promotion in PowerShell. I like to use the PowerShell ISE for multiple reasons but when working with scripts you have both the scripting windows right along with the console. Makes things very easy.
You can hit F5 or click the green arrow or get into the ‘Debug’ menu for more options. For the quick and dirty I’m just clicking the green arrow. Provide your SafeModeAdministratorPassword and off it goes.
You may get some messages and warning along the way. PowerShell seems to provide great feedback to help you understand what is going on.
The server will reboot and your DC is setup.
Save the script, store it. You will find many others. I will explore Desired State Configuration (DSC) in the future to really fully leverage PowerShell to manage deployment and configuration of components across your enterprise. I have a long way to go before I’m ready for that! Just getting my feet wet with DSC at this point.
Enjoy!
Group Policy 001: Intro to the GPMC
Tools
Group Policy Management Console
GPMC |
Change DC |
Create Group Policy Objects
- Right click on the "Group Policy Objects" node and select 'New'
- Give the GPO a Name
- Choose to start from scratch or pick a 'Source Starter GPO' (Starter GPOs will have to be another post)
- Click OK
New GPO |
GPO Details |
Saturday, March 29, 2014
PowerShell 004 - Copy-VMFile
Working between Host and Guest Virtual Machines
Copy-VMFile
Thursday, March 27, 2014
PowerShell 003 - Get-ADObject
Get-ADObject
Get-Help
Get-ADObject
Saturday, March 22, 2014
PSV 001 - Get-EventLog - Video
VLOG Entry 001
PowerShell 002 - Test-Connection
Get-Help
Test-Connection
-ComputerName
-Count
-Source
As always, Enjoy!