This function will “stream” a file line-by-line, as a Generator.
Can be very useful if for example you need to process a big file, don’t want to read the whole thing into memory, but only process each line by itself.
This function will “stream” a file line-by-line, as a Generator.
Can be very useful if for example you need to process a big file, don’t want to read the whole thing into memory, but only process each line by itself.
Had a file with the following kind of data.
Wanted to read this in as a hashtable so that I could use it for lookup in a script. Tried doing the following, but ended up with an array of hashtables instead of one hashtable. This is because Get-Content
by default actually gives you an array of lines, which are then piped into ConvertFrom-StringData
one by one.
Turns out it was easy to fix by adding the -raw
parameter.
Keep running into scenarios where I need to scan through a file system and it’s actually pretty simple if you just know what classes to use. So… note to self and others:
This skips the annoying dots, properly excludes directories you don’t want and pretty much works the way it should.
Tried to find out how to convert windows-1252 code files to utf-8 without messing up Norwegian characters today. Couldn’t really find anything good other than linux tools and php stuff. Finally, *facepalm*, I remembered it might be possible using Notepad… And sure enough, seems to work great. Just open up the windows-1252 encoded file in Notepad, then choose ‘Save as’ and set encoding to UTF-8.
Hopefully I won’t forget this the next time I need it… *sigh*
Say you have a bunch of files and you want to quickly change or remove the file extension of all of them. Turns out that’s very simple to do with the command-line in Windows. I had no idea…
Will change all files with ‘old’ file extension to have the ‘new’ file extension.
Will remove the ‘old’ file extension.
Simple!