Skip to content

Instantly share code, notes, and snippets.

@gravejester
Last active August 9, 2016 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravejester/a73744ecccecfbddca3f6e18def4dd90 to your computer and use it in GitHub Desktop.
Save gravejester/a73744ecccecfbddca3f6e18def4dd90 to your computer and use it in GitHub Desktop.
function Get-DPMActiveOwner {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string[]] $Path
)
PROCESS {
foreach ($thisPath in $Path) {
$fileStream = New-Object -TypeName System.IO.FileStream -ArgumentList ($thisPath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
$fileReader = New-Object -TypeName System.IO.BinaryReader -ArgumentList $fileStream
$outputString = ''
$continue = $false
do {
$readBytes = $fileReader.ReadBytes(2)
$unicodeString = [System.Text.Encoding]::Unicode.GetString($readBytes)
if ($unicodeString -eq '') {
$continue = $true
}
else {
$outputString += $unicodeString
}
} until ($continue)
$fileReader.Close()
$fileStream.Close()
Write-Output $outputString
}
}
END {
$fileReader.Dispose()
$fileStream.Dispose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment