Jan 14 2021 11:05 AM
Jan 14 2021 11:05 AM
Using the 'Get-GPInheritance' command in Powershell 7 returns the GPOLink class rather than the GPO name for each GPO listed in the 'InheritedGpoLinks' property.
Get-GPInheritance -Target $ou | Select-ExpandProperty InheritedGpoLinks | FT
But the same command outputs the GPO names successfully in Windows PowerShell 5.1.
How can I get this to work in Powershell 7?
Jan 17 2021 01:35 AM - edited Jan 17 2021 01:39 AM
I am checking the issue and notice that there are a lot of different between running the command on Powershell 5.1 (Infrastructure version) vs Powershell 7
even the object type and the return is different,
Powershell 5.1, Notice that the name is GPOLink, which seems to be an object holding the value
PS C:\Users\Administrator> ((Get-GPInheritance -Target $ou ).InheritedGpoLinks).gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False GpoLink System.Object
Powershell 7.1, Notice that the Value type is String not GPOLink
PS C:\Program Files\PowerShell\7> ((Get-GPInheritance -Target $ou ).InheritedGpoLinks).gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object
Even when you run Get-GPInheritance -Target $ou
Powershell 5.1: will return the GPNmae
Powershell 7.1: will return Microsoft.GroupPolicy.GpoLink
I will do more checks on this, this is maybe because the GroupPolicy module was written and tested in PS5.1 but not 7
Mar 17 2023 12:55 AM
Any progress on this? It's been 2 years and this issue still persists in PowerShell 7.
Henrik André Olsen
Aug 18 2023 07:03 AM
Aug 18 2023 05:55 PM - edited Aug 18 2023 06:37 PM
I'm not a habitual PowerShell (as distinct from Windows PowerShell) user, but working with the Get-GPInheritance commandlet in this thread:
Import-Module -Name GroupPolicy;
Import-Module -Name GroupPolicy -SkipEditionCheck
It's worth noting that - at least under my now out-of-date PowerShell 7.2.6 - it provides a warning message upon loading this module that it's using the compatibility process described in the documentation:
This may or may not having been around back when this post was created - I have no idea (as I don't use PowerShell.)
I should add that this is assuming you're on Windows (I'm not sure if the GroupPolicy module exists for other platforms), and I fully recognise that testing this one specific scenario is a very long way from being comprehensive.
That disclaimer out of the way, when running the same type check against InheritedGpoLinks (having used -SkipEditionCheck) - in line with the previous posts, it confirms the module is running in-process, meaning serialisation and de-serialisation are no longer an issue.
Aug 20 2023 10:59 PM
Aug 27 2023 01:16 PM