Skip to content

Commit 8cd1974

Browse files
committed
Update readme
1 parent 58b8b35 commit 8cd1974

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

README.md

+66-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
1-
# lockfile
2-
PowerShell module to manage lock files
1+
# LockFile
2+
3+
PowerShell module to manage lock files using the current process and computer name.
4+
This type of locking is useful in the event there is a script that needs to be highly available running on multiple computers but only one instance can be active at a time.
5+
6+
## Install
7+
8+
```powershell
9+
# PowerShellGet
10+
Install-Module LockFile
11+
12+
# PSResourceGet
13+
Install-PSResource LockFile
14+
```
15+
16+
## Usage
17+
18+
### Create Lock File
19+
20+
If creating a lock file that needs to be read from multiple machines use a shared path.
21+
22+
```powershell
23+
Set-LockFile -Path \\scripts\myscript.lock
24+
```
25+
26+
### Get Lock File
27+
28+
To get the configuration of the lock file.
29+
30+
```powershell
31+
Get-LockFile -Path \\scripts\myscript.lock
32+
33+
ComputerName ProcessId ProcessName
34+
------------ --------- -----------
35+
TestDC 4800 pwsh
36+
```
37+
38+
### Test Lock File Validity
39+
40+
```powershell
41+
Test-FileLock -Path \\scripts\myscript.lock
42+
```
43+
44+
You can also pipe the outputs from `Get-LockFile`.
45+
46+
```powershell
47+
Get-LockFile -Path \\scripts\myscript.lock | Test-FileLock
48+
True
49+
```
50+
51+
If the process that created the lock is on another computer
52+
create a session to the computer for the cmdlet to check the validity.
53+
54+
```powershell
55+
$lock = Get-LockFile -Path \\scripts\myscript.lock
56+
57+
$results = if ($env:ComputerName -ne $lock.ComputerName) {
58+
$session = New-PSSession -ComputerName TestDC2
59+
$lock | Test-LockFile -Session $session
60+
} else {
61+
$lock | Test-LockFile -Session
62+
}
63+
64+
$results
65+
True
66+
```

0 commit comments

Comments
 (0)