Reputation: 61
I would like to create a script powershell, but for it to work properly I need the MAC address of the workstation I am looking for (they are thin clients). For that I want to get the name of the configuration file in this form: $mac.ini
.
For that I tried an interesting command that works well: I enter the name of the Wyse (thin client) in the command and I send, but unfortunately I get a result in this form:
Name ---- \\***\WnosIniManager\inc\847BEBEF****.ini
or like that with a "[string]":
@{Name=\\***\WnosIniManager\inc\847BEBEF****.ini}
$fromDir = "\\***\WnosIniManager\inc\"
$mac = Get-ChildItem -Path $fromDir\*.ini |
Select-String -Pattern "TWYD512" |
group Path |
select -Unique Name
I only need the file name, and no extension, I have to remove the path and extension to keep only the MAC address like this: 847BEBEFABAB.
Upvotes: 2
Views: 311
Reputation: 200523
Run Select-String
in a Where-Object
filter, then expand the BaseName
of the files.
Get-ChildItem -Path $fromDir -Filter '*.ini' | Where-Object {
Select-String -Path $_.FullName -Pattern 'TWYD512' -SimpleMatch
} | Select-Object -Expand BaseName -Unique
Upvotes: 2