-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Run the following on Windows, with Microsoft Word installed:
- Creates a temp. sample document with 2 hyperlinks, which are then enumerated using various methods, only some of which work:
& {
$word = New-Object -ComObject Word.Application
# Create a sample document with 2 hyperlinks.
$thisDoc = $word.Documents.Add() # Open($doc.FullName)
$para = $thisDoc.Paragraphs.Add()
$null = $thisDoc.HyperLinks.Add($para.Range, 'https://example.org')
$para.Range.InsertAfter("`n")
$para = $thisDoc.Paragraphs.Add()
$null = $thisDoc.HyperLinks.Add($para.Range, 'https://wikipedia.org')
# Try to enumerate the hyperlinks using various methods.
[pscustomobject] @{
# OK
HyperLinks1 = $thisDoc.HyperLinks | ForEach-Object Address
# OK
HyperLinks2 = foreach ($lnk in $thisDoc.HyperLinks) { $lnk.Address }
# OK(!) - explicit use of enumerator
HyperLinks3 = $thisDoc.HyperLinks.GetEnumerator().Address
# !! Broken - .ForEach() method (ditto for .ForEach('Address'))
# !! No enumeration -> single-element collection containing $null
# !! Note: Fails fundamentally on WinPS.
HyperLinks4 = $thisDoc.HyperLinks.ForEach({ $_.Address })
# !! Broken - member-access enumeration:
# !! No enumeration -> $null
HyperLinks5 = $thisDoc.HyperLinks.Address
}
$thisDoc.Close($false) # $false seemingly suppresses a save prompt.
$word.Quit()
}Expected behavior
HyperLinks1 : {https://example.org/, https://wikipedia.org/}
HyperLinks2 : {https://example.org/, https://wikipedia.org/}
HyperLinks3 : {https://example.org/, https://wikipedia.org/}
HyperLinks4 : {https://example.org/, https://wikipedia.org/}
HyperLinks5 : {https://example.org/, https://wikipedia.org/}That is, all enumeration methods should work.
Actual behavior
HyperLinks1 : {https://example.org/, https://wikipedia.org/}
HyperLinks2 : {https://example.org/, https://wikipedia.org/}
HyperLinks3 : {https://example.org/, https://wikipedia.org/}
HyperLinks4 : {$null}
HyperLinks5 :That is, enumeration via the intrinsic .ForEach() method and via member-access enumeration did not work (except via an explicit .GetEnumerator() call); problem dates back to Windows PowerShell.
Error details
No response
Environment data
PowerShell 7.5.0-rc.1Visuals
No response
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime