Powershell: Pipe problems when using import-pssession

Amdi Thomsen 21 Reputation points
2021-03-09T09:04:53.597+00:00

I am a very fond user of Windows Terminal, and use it a lot for WSL, Powershell, etc.
I run it in my normal user context, but I sometimes need administrative privileges to our domain controllers.

Therefore I save my admin credentials and use them in a pssession command, and imports that pssession. But when doing this, piping does not work.

A simple command like: "get-aduser <username> | Get-ADPrincipalGroupMembership" throws an exception.

"Cannot validate argument on parameter 'Identity'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."

From the error message, I conclude that the current object '$_' is for whatever reason not passed through to the next command, but why?
And is there some way to correct this?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,449 questions
{count} votes

Accepted answer
  1. Rich Matheisen 45,671 Reputation points
    2021-03-09T16:06:28.177+00:00

    I don't think the problem is that piping doesn't work. I think your problem is that you probably receive a deserialized version of the user object. The Get-ADPrincipalGroupMembership may depend on the object in the pipeline having a specific object type, or it may be trying to find the "Identity" property in the object that it receives from the pipeline.

    Start by having a look at the properties in the user object returned by Get-ADUser. Have a look at the "Inputs" section of the cmdlet's help. Is the object type you got from the Get-ADUser an "ADPrincipal" or one of the derived types? If not, is there an "Identity" property in the object?


0 additional answers

Sort by: Most helpful