如何只恢复没有路径和文件扩展名的文件名?

How to recover only the file name without the path and file extension?

我想创建一个脚本 powershell,但要使其正常工作,我需要我正在寻找的工作站的 MAC 地址(它们是瘦客户端)。为此,我想以这种形式获取配置文件的名称:$mac.ini.

为此,我尝试了一个运行良好的有趣命令:我在命令中输入 Wyse(瘦客户端)的名称并发送,但不幸的是,我得到的结果是这样的:

Name
----
\***\WnosIniManager\inc7BEBEF****.ini

或者像这样带有“[string]”:

@{Name=\***\WnosIniManager\inc7BEBEF****.ini}
$fromDir = "\***\WnosIniManager\inc\"
$mac = Get-ChildItem -Path $fromDir\*.ini |
       Select-String -Pattern "TWYD512" |
       group Path |
       select -Unique Name

我只需要文件名,不需要扩展名,我必须删除路径和扩展名以仅保留 MAC 地址,如下所示:847BEBEFABAB。

运行 Select-StringWhere-Object 过滤器中,然后展开文件的 BaseName

Get-ChildItem -Path $fromDir -Filter '*.ini' | Where-Object {
    Select-String -Path $_.FullName -Pattern 'TWYD512' -SimpleMatch
} | Select-Object -Expand BaseName -Unique