Skip to content

Instantly share code, notes, and snippets.

@martin77s
Created September 14, 2018 14:37
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 martin77s/b32ced8bd29f50ccce6c29e87748f3d8 to your computer and use it in GitHub Desktop.
Save martin77s/b32ced8bd29f50ccce6c29e87748f3d8 to your computer and use it in GitHub Desktop.
Add-ExtendedAttribute
function Add-ExtendedAttribute {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias(‘FullName’, ‘PSPath’)]
[string[]]$Path,
[Parameter(Mandatory = $true)]
[ValidateRange(0,287)]
[int[]]$ExtendedAttributeId
)
begin {
$oShell = New-Object -ComObject Shell.Application
}
process {
$Path | ForEach-Object {
if (Test-Path -Path $_ -PathType Leaf) {
$FileItem = Get-Item -Path $_
$oFolder = $oShell.Namespace($FileItem.DirectoryName)
$oItem = $oFolder.ParseName($FileItem.Name)
$ExtendedAttributeId | ForEach-Object {
$ExtPropName = $oFolder.GetDetailsOf($oFolder.Items, $_)
$ExtValName = $oFolder.GetDetailsOf($oItem, $_)
$params = @{
InputObject = $FileItem
MemberType = ‘NoteProperty’
Name = $ExtPropName
Value = $ExtValName
}
$FileItem = Add-Member @params -PassThru
}
}
$FileItem
}
}
end {
$oShell = $null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment