Created
September 14, 2018 14:37
-
-
Save martin77s/b32ced8bd29f50ccce6c29e87748f3d8 to your computer and use it in GitHub Desktop.
Add-ExtendedAttribute
This file contains hidden or 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 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