Skip to main content

Posts

Showing posts from October, 2013

How Many ??? is in PowerShell?

When I start a PowerShell class, I am often asked “How many cmdlets are there in PowerShell?”  Well, the answer is “That depends.”  Once we start looking at cmdlets, I am often asked “How many parameters does a cmdlet have?”  The answer is “that depends.”  I also get asked “How many modules are there?” Once again, “that depends.”  This is not the answer that paying clients want to here, but it is the truth. How many cmdlets are there? It depends on what is available to the client/server you are working on. Also, did you add your own modules? Get-Command | Measure-Object | Select-Object –ExpandProperty Count How many modules are there?  What technologies are installed on the local client/server?  Again this is a variable that I cannot answer.  Get-Module –ListAvailable | Measure-Object | Select-Object –ExpandProperty Count How many parameters are there?  That depends on which cmdlet you are using.  Utilizing the Help system will expose the different parameters that are available to

How to address Property Names with Spaces in them?

Things don’t always go as planned.  For example when my wife and I moved from Indiana to Arizona this spring.  We were planning on taking three days to drive the dogs from Indianapolis to Phoenix.  I was at the PowerShell Summit in Redmond and she was home finishing the packing.  I could tell by the way she was sounding on the phone that things were not going well so I jumped on an early flight to come home.  Well….I landed in Houston to find the plane was broken and no flights left to Indianapolis.  The airline was planning on getting me home around 2:30 PM the next day. Um,…no.  So I took a plane to Chicago that night and slept in the USO and got home at 10 AM to help my wife.  Sometimes you have to turn a challenge into an opportunity. Sometimes you need to work with data that was never indented to be used with PowerShell.  This can present a challenge.  Those of you who have taken my PowerShell classes know that I frown on any variable that has a space in it.  Take a look at what

I’ll be Speaking at the 2014 PowerShell Summit!

Good afternoon PowerShell fans.  Last week I found out that I will have the honor speaking to all of you at the 2014 PowerShell summit.  I’m be presenting a session titled “Empower your Help Desk with PowerShell”.  The PowerShell summit is a great way to learning new skills from the industry’s top PowerShell experts.  You can register at PowerShell.org .  This summit always sells out so don’t wait to long to register. I’ll see you all in April, Jason

Use PowerShell to discover all computer objects in AD

I’m sitting in my classroom while my class is doing a lab and answering some questions from PowerShell.com.  This scripter needs to discover all the computer objects in Active Directory with an empty description and provide a setting for it. 1 2 3 4 5 Import-Module ActiveDirectory # For PowerShell V2 Compatibility $Desc = "New Description String" Get-ADComputer -Filter * -Properties Description |     Where-Object { $_ . Description -eq $Null } |     Set-ADComputer -Description $Desc   Line 1 imports the Active Directory module into this session.  You can omit this line if you are running PowerShell V3 or V4 and have the PowerShell ActiveDirectory module installed locally. Line 2 is used to provide the new description property value. Line 3 gets all the computer objects from Active Directory.  I was not able to get a filter for a description that is NULL.  Hence the reason for line 4 which uses Where-Object to filter on the NULL Description prop

Discover Who is Logged Onto Your Clients

Recently I helped an IT Pro on PowerShell.com who needed to find out how to discover who was logged into his clients.  Here is the advanced version of the code that allows you to send information via the PowerShell Pipeline. This code was tested in a PowerShell V3 environment.  If you need to alter the code for a PowerShell V2 without WinRM turned on, make the following changes: Line 50: "ClassName" to "Class" Line 58: "Get-CIMInstance" to Get-WMIObject" 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10