A nice, short function this one;
<# .SYNOPSIS Tests if a file is locked. #> function Test-FileLocked { param ( [string]$FilePath ) try { [IO.File]::OpenWrite($FilePath).close();return $false } catch {return $true} }
Family, Cool Stuff and Assorted Geekery; the finer things in life. Updated when I have something interesting to write :)
A nice, short function this one;
<# .SYNOPSIS Tests if a file is locked. #> function Test-FileLocked { param ( [string]$FilePath ) try { [IO.File]::OpenWrite($FilePath).close();return $false } catch {return $true} }
Often you need to record what a script does to a file. You can easily get something going with Start-Transcript but sometimes you want to control what is written with a bit more granularity.
So here’s a function I tend to re-use in my scripts. It takes text output and writes it both to a text log file and to the Verbose output stream. Continue reading “PowerShell: A Logging Function”
I got my wife a new digital picture frame as a present. It looks cool but the attached storage options (USB or card) aren’t big enough to take all our digital photos.
The decision about which pictures to include relies on either organisational skills OR an artistic eye, neither of which I have.
So what about making it strictly random? Copying the entire directory structure but only a random sample of the files in each folder?
That I CAN do 🙂 Continue reading “PowerShell: Copy Directory Structure and a Random Sample of Files from Each Directory”
The Windows 10 release is just around the corner and I’m going to do a fresh install on a new hard-drive. I’ve redirected most of my working directories to network locations so most of my files should just appear ‘auto-magically’ but I’m sure there’s a few files dotted around the place that are important that I’ve just ‘temporarily’ left outside one of the redirected folders.
So what I want is some PowerShell to find all the files owned by me on my hard-drives. I can do this with a one-line PowerShell command as follows; Continue reading “PowerShell : Find all Files Owned By A User”