Ok, this one is perhaps a little silly, but have you ever struggled with writing output involving an integer with an unknown value together with some text? Don’t know what I’m talking about? I don’t blame you!

I mean this kind of output:

1 file processed
2 files processed
0 files processed
125 files processed

The easy way out would be to write something like this:

Write-Output "$int files processed"

This would mean that for int = 1, the output will be “1 files processed”, but hey – who cares right? I have tried using an if-statement to get the desired result, and while it works, the code don’t look pretty.

So I thought I’d take the time to write a proper function for this. I decided to write a full advanced function, which means that it might feel a bit bloated, but luckily copy/paste don’t care about number of lines.

Anyway, here is the code:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s