Powershell 在文件路径中使用通配符

Powershell 在文件路径中使用通配符,powershell,Powershell,我需要在服务器上搜索一些文件。。。但是所讨论的文件被隐藏在用户ID下的文件夹中。因此,我尝试使用通配符%username%来访问要搜索的文件夹 厌倦了使用%username%和*对上面的文件夹进行通配符以访问子文件夹 $Path="\\server\profiles\%username%\Data\" $filename='notes.ini' Get-ChildItem -Path $Path -Recurse -Filter $filename -ErrorAction SilentlyC

我需要在服务器上搜索一些文件。。。但是所讨论的文件被隐藏在用户ID下的文件夹中。因此,我尝试使用通配符%username%来访问要搜索的文件夹

厌倦了使用%username%和*对上面的文件夹进行通配符以访问子文件夹

$Path="\\server\profiles\%username%\Data\"
$filename='notes.ini'

Get-ChildItem -Path $Path -Recurse -Filter $filename -ErrorAction SilentlyContinue

我希望只在数据文件夹中搜索notes.ini文件,而不必搜索其间的所有文件夹。

如果您不知道用户的姓名,可以在路径中使用通配符asteriks
*

$Path     = "\\server\profiles\*\Data\"  #"# use wildcard to search all user folders 
$filename = 'notes.ini'

# this returns the full file and path names of the file you are looking for:
Get-ChildItem -Path $Path -Recurse -Filter $filename -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName

如果这不是您想要的,请在您的问题中添加更多解释。

%username%在powershell中是$env:username%


%用户名%不是通配符,它是cmd中的一个环境变量。您要搜索每个用户的文件夹还是特定用户?