# using user name to get-computer name

**URL:** <https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989>\
**Category:** PowerShell Help\
**Created:** [October 21, 2013, 2:10am UTC](https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989 "2013-10-21T02:10:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-rojas](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jason-rojas](https://forums.powershell.org/u/jason-rojas)\
**Post date:** [October 21, 2013, 2:10am UTC](https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989/1 "2013-10-21T02:10:58Z")

</div>

$computerlist = Get-ADComputer -Filter \* | select -expand name  
icm -ComputerName $computerlist {Get-WmiObject win32\_computersystem -ComputerName ‘localhost’ | where username -like “crojas” | select username, name  
}

when I run this script this is returned for all computers on my network, thank god its a small one. Am I able to do this, I am a newbie so I am experimenting.

> Cannot bind parameter 'FilterScript'. Cannot convert the "username" value of type "System.String" to type "System.Management.Automation.ScriptBlock". + CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand + PSComputerName : ARRIS-20

I would like to be able to enter a user name and find the computer name that the user has logged into so that I can remote into for support purposes.

thanks for your time and knowledge

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 21, 2013, 2:15am UTC](https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989/2 "2013-10-21T02:15:51Z")

</div>

Most likely, some of these computers are running PowerShell 2.0, and your “where” syntax only works on PowerShell 3.0 or later. You can try changing:

```
# This:
where username -like "crojas"

# to this:
Where-Object { $_.username -like "crojas" }
```

Edit: On a side note, Get-WmiObject has its own remote capabilities, if you would prefer to let WMI do the work instead of PowerShell Remoting. That’s up to you; it will eventually work either way, once the bugs are fixed.

---

<div class="post-metadata">

**Author:** ![jason-rojas](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jason-rojas](https://forums.powershell.org/u/jason-rojas)\
**Post date:** [October 21, 2013, 11:31pm UTC](https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989/3 "2013-10-21T23:31:13Z")

</div>

I have tried that but I get the same error message. I tried to pipe in GM to see what data types it likes because according the message it does not like throwing a string at the script block.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 21, 2013, 11:53pm UTC](https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989/4 "2013-10-21T23:53:54Z")

</div>

So you ran it like this, and still got the same error message?

```
$computerlist = Get-ADComputer -Filter * | select -expand name
Invoke-Command -ComputerName $computerlist -ScriptBlock { Get-WmiObject win32_computersystem -ComputerName 'localhost' | Where-Object { $_.username -like "*crojas*" } | select username, name }
```

If I were doing this, I’d probably rewrite it this way (not using Invoke-Command at all, since WMI already works remotely, and making a few small performance tweaks):

```
$computerlist = Get-ADComputer -Filter * -Properties Name | Select-Object -ExpandProperty Name

Get-WmiObject -ComputerName $computerlist -Class Win32_ComputerSystem -Filter 'UserName LIKE "%crojas%"' -Property UserName,Name |
Select-Object -Property UserName, Name
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:56pm UTC](https://forums.powershell.org/t/using-user-name-to-get-computer-name/1989/5 "2024-05-16T20:56:57Z")

</div>

Closed on May 16, 2024, 8:56pm UTC


