Back to Basics: Generate Monthly Report Folders

I’m always using PowerShell to just, well, help out with day to day stuff I have to do. The other week I used PowerShell to generate a bunch of folders for 2017 that I’ll use to store my expense receipts in. All very mundane; all completed in milliseconds. $a = 1..12 | % {(Get-Date -Month $_ -f…

0

Back to Basics: Change an Attribute on a File

Today’s post is short and sweet… just like the PoSh Progeny! Here’s a short and sweet way to manipulate file attributes. Stuff like ‘Read-only’ and ‘File is ready for archiving’ in the below image.   First up, add an attribute. We have a file that is marked as Archive and Offline. Time to add ReadOnly. #Attribute…

2

Back to Basics: Is my Parameter Value from the Pipeline?

I was asked how to check if a supplied parameter value has come from the pipeline. I came up with two different methods, the first only works with v2. Here are the two test conditions: Test-ParamSource -MyParam $vals $vals | Test-ParamSource   Where $vals is an array of integers: $vals = 3,4,5,6,40,50   Right, we…

0

Back to Basics: A Casting Quandary

I could hear the screams of frustration from miles away! Not too long after my Skype for Business chimed in… it all became clear… a colleague has been struggling with some seemingly simple PowerShell. PoshChap to the Rescue We have a list of Active Directory computer accounts. $hosts = Get-ADComputer -Filter * -Properties ServicePrincipalName We need to enumerate a…

1

Back to Basics: Use PowerShell to Search Servers for Specific Software

An old acquaintance, Mr. Rupert Torquil-Smythe Esq. (yes, it is he), recently wanted to know whether a certain piece of software was installed on a particular list of servers in his test lab. I asked him for the list of servers (servers.txt) and the name of the software (Python). I then wrote and ran this: $Servers = Get-Content -Path .\servers.txt foreach…

5

Back to Basics: Use PowerShell to Generate a List of Week Commencing Dates

The other day I need a year’s worth of ‘week commencing’ dates to complete a work-related task. The thought of collecting them manually never entered my head! Here’s what I did: $Start = Get-Date 27/06/2016 $i = 1 Do { Add-Content -Value “$($Start.Day)/$($Start.Month)/$($Start.Year)“ -Path dates.txt $Start = $Start.AddDays(7) $i++ } Until ($i -eq 52)   Simple…

0