Skip to content

Commit

Permalink
Add Get-ByteContent common function
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Guardian committed Apr 19, 2020
1 parent 9cb4669 commit 855e7e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
28 changes: 9 additions & 19 deletions source/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ $adPropertyMap = (Import-PowerShellDataFile -Path $adPropertyMapPath).Parameters
------------------------------|--------------------------
Get-ADUser | ActiveDirectory
Assert-Module | DscResource.Common
New-InvalidOperationException | DscResource.Common
Get-ADCommonParameters | ActiveDirectoryDsc.Common
New-InvalidOperationException | ActiveDirectoryDsc.Common
Get-ADObjectParentDN | ActiveDirectoryDsc.Common
Get-MD5HashString | MSFT_ADUser
#>
Expand Down Expand Up @@ -1833,6 +1833,13 @@ function Get-MD5HashString
.OUTPUTS
Returns a byte array of the image specified in the parameter ThumbnailPhoto.
.NOTES
Used Functions:
Name | Module
------------------------------|--------------------------
Get-PSEdition | ActiveDirectoryDsc.Common
New-InvalidOperationException | DscResource.Common
#>
function Get-ThumbnailByteArray
{
Expand All @@ -1851,24 +1858,7 @@ function Get-ThumbnailByteArray
if (Test-Path -Path $ThumbnailPhoto)
{
Write-Verbose -Message ($script:localizedData.LoadingThumbnailFromFile -f $ThumbnailPhoto)
$getContentParms = @{
Path = $ThumbnailPhoto
}

# Use Get-Content Encoding Byte for PowerShell Desktop and AsByteStream for PowerShell Core
if ($PSVersionTable.PSEdition -eq 'Desktop')
{
$getContentParms += @{
Encoding = 'Byte'
}
}
else
{
$getContentParms += @{
AsByteStream = $true
}
}
$thumbnailPhotoAsByteArray = Get-Content @getContentParms
$thumbnailPhotoAsByteArray = Get-ByteContent -Path $ThumbnailPhoto
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'Get-CurrentUser'
'Test-Password'
'Test-PrincipalContextCredentials'
'Get-ByteContent'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2063,3 +2063,32 @@ function Test-PrincipalContextCredentials

return $result
}

<#
.SYNOPSIS
Returns the contents of a file as a byte array
.PARAMETER Path
Specifies the path to an item.
#>
function Get-ByteContent
{
[CmdletBinding()]
[OutputType([System.Byte[]])]
param(
[Parameter(Mandatory = $true)]
[System.String]
$Path
)

if ($PSVersionTable.PSEdition -eq 'Core')
{
$content = Get-Content -Path $Path -AsByteStream
}
else
{
$content = Get-Content -Path $Path -Encoding 'Byte'
}

return $content
}

0 comments on commit 855e7e7

Please sign in to comment.