Last active
August 9, 2016 08:50
-
-
Save gravejester/a73744ecccecfbddca3f6e18def4dd90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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