You'll want to either cast the field to the proper field type or use the PSFields
collection to access it for you.
Read more here.
Example: The following gets the home item of a site, accesses the HeroImage field and expands the Alt text.
$item = Get-Item -Path "master:" -ID "{961563FC-3445-4558-BF3A-06DF06BA6298}"
$item.PSFields.HeroImage.Alt
Update
Based on your revised requirements here is what I've learned.
When accessing the Alt field on the ImageField
type the text is first extracted from the xml in the field followed by a fallback to the text on the media item. Doesn't appear that the Alt property provides a way to know whether or not it's the default value.
You could try something like the following:
$item = Get-Item -Path "master:" -ID "{961563FC-3445-4558-BF3A-06DF06BA6298}"
$detectedValue = $item.PSFields.HeroImage.Alt
$defaultValue = $item.PSFields.HeroImage.MediaItem["Alt"]
if($defaultValue -ne $detectedValue) {
Write-Host "This has been overridden"
} else {
Write-Host "This is the default value"
}
$rawValue = $item.PSFields.HeroImage.GetAttribute("alt")
if($detectedValue -ne $rawValue) {
Write-Host "It's showing the default value"
}
"ABC" is stored in $rawValue
and $detectedValue
. If I cleared it out $detectedValue
would match $defaultValue
and $rawValue
would be blank.