Posted On March 29, 2019

PowerShell: Simulate File Open Locking

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Simulate File Open Locking
# Simulate error by creating file in current directory with some contents; then, open file in locking mode
Add-Content ($directories+”\testlock.txt”) “cowabunga!”
$file=[System.IO.File]::Open(($directories+”\testlock.txt”), ‘Open’, ‘Read’, ‘None’)
 
# Close file afterward
$file.close();

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Transfer Domain Controller Roles (Legacy Commands)

# Simple commands: netdom query fsmo ntdsutil roles connections connect to server SRVI-DC01 q transfer…

PowerShell: How to Convert Multi-Line Texts Into an Array of Strings

Significance: we often run into situations where a list of items (such as usernames, computernames,…

Basic JavaScript: Constructing Strings with Variables

// Examplevar ourName = "freeCodeCamp";var ourStr = "Hello, our name is " + ourName +…