Skip to content

Code OK on V5.1 does not run on V7.0.0RC2 #11782

@RG255

Description

@RG255
Name                           Value
----                           -----
PSVersion                      7.0.0-rc.2
PSEdition                      Core
GitCommitId                    7.0.0-rc.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The code in the attached script runs OK on V5 but generates the following error on V7:

MethodInvocationException: S:\PowerShellScripts\TestUserIngroup_1.ps1:5
Line |
   5 |  … t -Process {$_.GetType().InvokeMember('Name', 'GetProperty', $null, $ …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "InvokeMember" with "5" argument(s): "Unknown name. (0x80020006 (DISP_E_UNKNOWNNAME))"

The script:

$user = $env:USERNAME
$group = 'Users'
$groupObj = [ADSI]"WinNT://./$group,group"
$membersObj = @($groupObj.psbase.Invoke('Members'))
$members = ($membersObj | ForEach-Object -Process {$_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)})

If ($members -contains $user) 
{Write-Host -Object "$user exists in the group $group"}
Else 
{Write-Host -Object "$user does not exists in the group $group"}

TestUserIngroup_1.zip

Metadata

Metadata

Assignees

Labels

Resolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions