Powershell is for scripting, but that doesn’t mean you can get away with sloppy coding. You should never write more than you need to and you need to be able to reuse as much as possible. This means you write small little modules that do a few things, rather than one huge script that only works for one task.
A great example is something like today’s task. I needed to change some permissions in a folder. The problem was, to expand on the task, I would need to feed in the rest of the folders I needed to work on, but this would not allow me to run things in parallel.
Ideally, I needed to have a task schedule where the same script worked on 3 different folders at once. The only way to do that is to trigger the Task Scheduler 3 times. But using that process, I would need 3 different scripts – which breaks the first rule, never write more than you need.
The answer is quite easy – feed the name of the new folder into the script at launch. So, at the top line of the script, add:
This will create a variable you can place where you need it in the real code.
write-host "This is the magic " $unique
The way you add the details is like this:
This is very flexible now, and I can create 3 task scheduled processes that all triggered the same time, but deal with 3 unique folders, using the same code.
How easy was that?
In the UK we have a petition system where anyone can set up a petition and if it reaches 100K names, the subject gets debated in Parliament. Its an idea that gets misused by various lobby groups and there are often news stories where some political idea gets forced into debate by a group who can’t accept the status quo.
Anyway, enough politics, the interesting part is getting to the numbers. Take the last big petition – all about Brexit. Each petition has a JSON page where all those lovely numbers are easy to see – but while JSON is easier to read than XML, its no Infographic!
People like to travel. It has always been true, and is the reason we no longer live in Africa as a species. The easiest way from one place to another is via a path. If enough people use that path and it becomes a road. Eventually, the people will spend their own time and effort to make their road easier to use. It gets straighter and flatter and more damage resistant over time. This is the life of a road.
So when did we first start using roads? In the UK, we were always taught it was all due to the Romans. They brought the roads and built them nice and straight from one town to another. As these roads wore out, we rebuilt them and made them better. A great example is the A5 from London to Holyhead in Anglesey. A real Roman road that still exists and is full of traffic every day. The problem is that Roman road isn’t actually Roman.
This is the first post of my new blog. I’ve hosted blogs before. I like to share ideas but have never given the publishing element enough effort. That changes this time.
I have two ideas that keep my attention.
One is how old is civilisation in the west? When did we really start to live how we do today? Where is the evidence of how we used to live? How much of what we think we know about the past is true? How can we prove the past without physical evidence or written documents?
My other idea is cutting edge technology. Just how will the future pan out and what is the cutting edge? I love concepts like virtual services, robots, big data and other technologies that people talk about, but not many people actually do.
I aim to post on both these ideas under the banner of Old and New.
I hope you enjoy my ideas and look forward to reading your comments