Skip to main content

Posts

Showing posts from March, 2014

How long can a variable name be in PowerShell?

Well, that is a good question.  Before I answer this, let’s just cover a few best practices when it comes to naming variables. Choose a variable name that gives you an idea of what is stored in the variable. Use letters, numbers, and “_” in your names. Do not use spaces.  They really make things look bad. Now, about how long can they be?  I wrote a little function to help be create long strings of random characters and the I used that string as the name of my variable. Function New-String { Param ( $Length )       $String = ""     For ( $X = 0 ; $X -lt $Length ; $X ++ )     {         $String += [ char ] (( Get-Random ( 26 )) + 65 )     }     Write-Output $String } New-String 10000   I copied this string into memory.  I then typed a dollar sign and pasted this string.  Automatic carriage returns were added by the ISE so I had to go to the end of the string and press Delete a few times to get it all back on the same line.  I then added = “Hello”. 

Comparison of PowerShell DISM Module and DOS DISM Commands

DISM has been used for many years to mount images and to make changes without actually first deploying the image and then re-capturing it. With the prevalence of Windows PowerShell. We now have DISM’s capabilities available to us in the familiar PowerShell syntax. One of the issues that I have always had with DISM is the cumbersome parameters. Here is a DISM command: DISM /Get-WimInfo /WimFile: Install.wim And its PowerShell counterpart: Get-WindowsImage –ImpagePath Install.wim The green highlights are the switches. You can see a difference. Also, by using PowerShell, you are using a technology that will be supported well into the feature as well as the search and help features of Windows PowerShell. Below are the commands used to add the BITS feature to a Windows 2012 R2 server image. The length of typing may appear to be the same, but with PowerShell’s TAB completion, you will most likely not have typos on the PowerShell side. Good luck with not making a typo with DISM. Power

How to hide my Windows 8.1 Task Bar on my 2nd Monitor

This week I’m delivering Microsoft course 20411C: Administering Windows Server 2012.  One of the members of the class asked if it was possible to hide the task bar on my extended screen.  Yes, my task bars were on both screens.  Here is how to do it.   Right click your taskbar and select Properties . Uncheck Show Taskbar on all displays and click OK.  Problem solved.

With the AD Recycle Bin Turned on, What Happens when you Create a User Account with a Password that does not meet the Password Policy?

This was an interesting observation from one of my Windows Server 2012 classes.  While working with the AD Recycle bin in a lab, one of my students discovered some interesting accounts that were created. When he created user accounts that did not meet password complexity requirements, an account is temporarily made and then deleted.  When a new password is provided that meets the password requirements, then a new account is made. We discovered this in two places.  First off in the Active Directory Administrative Center.  This is what caused the initial confusion.  Take a look.  This is in the Deleted Objects OU. You can see multiple deleted accounts for Test2 and one for Test3.  Test3 is a valid, functioning user account.  Using the PowerShell command Get-ADObject –IncludeDeletedObjects –Filter * –Properties ObjectSID we can see that indeed, two accounts were created, with one of them deleted. Notice the RID portion of the SID is different.   So, here is the big question, Can the

Testing connections with PowerShell and Sending a eMail Report

My budding PowerShell Rock Stars are at it again.  This time we helped out a Network Administrator with testing the connectivity to clients and then email a report.  I’ve come across this type of request several times before.  Those of you who attend my sessions at the SMB Nation Emerging Technology Tour have see some similar code demonstrated.  With this group, I decided to press them a bit and we tried out converting our object that contains our report to HTML.  Here is our result. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 # Dynamic array to hold the output. $Output = @()   # grab a list of computers from AD. $ComputerList = Get-ADComputer -Filter *   # Count the number of computers for the Write-Progress Cmdlet. $Count = $ComputerList |          Measure-Object |          Select-Object -ExpandProperty Count   # Control

Removing Identical Content from Multiple Text Logs

This week I am delivering an advanced PowerShell course in Norfolk, VA.  This is my second week with this group of inspiring PowerShell Rock Stars so I decided to push this group a little earlier than usual and I had them help me develop a script to help an individual who posted a question on PowerShell.com ( http://powershell.com/cs/forums/t/16403.aspx?PageIndex=1 )  His task was to examine 3 different text based logs.  Should there be a line that is the same in each of the 3 logs, that line was to be removed from each log.  Sounds simple.  The problem that he was looking at is that his logs were hundreds of thousands of lines long.  This is a perfect example of how to apply PowerShell to a real world situation. We did this as a brain storming session.  For the sake of time, we did not convert this into a cmdlet or a parameterized script.  We have to save some of the fun for the guy we were helping.  Here are our results:   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16