PowerShell for Windows Admins:

Powershell


September 26, 2017  10:04 AM

CIM not WMI

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

I still see a lot of people using the WMI cmdlets – Get-WmiObject etc. You really should be using CIM nit WMI. In other words use Get-CimInstance rather than get-WmiObject etc etc. Why do I say that? Two main reasons. Firstly, the WMI cmdlets are effectively deprecated. Any further...

September 25, 2017  1:08 PM

Write text to a file with Powershell

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell is all about working with objects but sooner or later you’ll need to write text to a file with Powershell. You have two options. The *-Content cmdlets and Out-File

PS> Get-Command *-Content

CommandType Name
 ----------- ----
 Cmdlet Add-Content
 Cmdlet Clear-Content
...


August 31, 2017  1:54 PM

PowerShell string concatenation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Strings - a list of characters such as ‘abcd’ – are a common feature of programming or scripting. Sometimes you need to join – concatenate – two or more strings together. This is how PowerShell string concatenation works. First you need to know that strings can be defined with single...


August 31, 2017  8:43 AM

PowerShell operators

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell has operators – lots of operators. So many operators that it took us TWO chapters to work through them all in PowerShell in Action, third edition - https://www.manning.com/books/windows-powershell-in-action-third-edition. Here’s how you can discover the PowerShell...


August 30, 2017  8:59 AM

Comparing AD group membership on EmployeeId

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

Back in this post - http://itknowledgeexchange.techtarget.com/powershell/comparing-group-membership/ I showed how to compare the membership of two groups using Compare-Object. The comparison was based on the samAccountName. A question raised the issue of comparing AD group membership on...


August 28, 2017  1:26 PM

PowerShell substrings

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell is all about working with objects but you often have to drop to a lower level and work with properties and their values. Many objects have properties that are strings – a string is one of the standard PowerShell literals – and sometimes you want to extract part of a string – a...


August 23, 2017  10:37 AM

PowerShell pause

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell pause – how can you pause a PowerShell script? Two ways come to mind. First if you just want the script to pause for a specified time period then you can use Start-Sleep 1..10 | foreach { $PSItem if ($PSItem -eq 5) { Write-Warning -Message "Starting sleep" Start-Sleep...


August 20, 2017  2:10 PM

PowerShell for loop

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Loops are a construction seen in most scripting and programming languages. A loop is used to repeat a set of statements a set number of times or until a specific criterion is met or while a specific criterion is true. In this post I’ll describe the PowerShell for loop. For loops are found in...


August 19, 2017  7:52 AM

Create a directory

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell enables you to work with the file system on your machine – one question that often comes up is how to create a directory. When working interactively you can use md

PS> md c:\testf1


 Directory: C:\


 Mode LastWriteTime Length Name
 ---- ------------- ------ ----
...


August 18, 2017  3:00 AM

PowerShell foreach

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell has a number of ways to perform a loop – I recently counted seven distinct methods. If you can’t list them all don’t worry one is very esoteric and unexpected. I’ll enumerate them in a future post. For now I want to concentrate on a source of confusion – especially to newcomers...


Forgot Password

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

Your password has been sent to: