Posted On June 13, 2020

PowerShell: Stream Reader

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Stream Reader

Have you ran into scripting situations where opening a file would result in locking from being editable by other users or processes? As a standard practice, it’s a good idea to have a habit of setting the correct intention of accessing a file using this example sequence:

$file='someXmlFile.xml'
$reader = New-Object System.IO.StreamReader($file)
$xml = $reader.ReadToEnd() # cast the variable as XML so PowerShell would handle it correctly
$reader.Close()

Leave a Reply

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

Related Post

PowerShell: Generate a CSV Report of O365 Exchange Online Mailboxes

# Office 365 Global Admin Credential$username="[email protected]"$password=ConvertTo-securestring "PASSWORD" -AsPlainText -Force$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$passwordfunction…

PowerShell RandomPassword Function

function randomPassword{    # return a reasonably randomized password that starts with "KimConnect:" plus 25…

PowerShell: Change Windows Autolock

# Disable_AutoLock.ps1function changeAutoLock{ param ( [Switch]$disable, [Switch]$enable ) $registryHive = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization" $registryKey="NoLockScreen" $keyItem = Get-ItemProperty…