Powershell Get-ChildItem 从配置文件文件夹中提取用户名
我有存储漫游用户配置文件的驱动器:
U:\Users\john.doe
U:\Users\john.wick
U:\Users\john.smith
我需要检查用户是否有存储在其配置文件中的 *.pdf扩展名的文件,
$a = Get-ChildItem "U:\users\" -Include *.pdf -Recurse | select FullName
foreach ($b in $a){
Write-Output $b
}
我
U:\Users\john.wick\desktop\file.pdf
U:\Users\john.wick\documents\a.pdf
U:\Users\john.doe\desktop\1.pdf
..................................
需要编写列以从路径中提取用户名,而一个带有完整文件路径的列。 怎么做?
john.doe
john.wick
--------
I have drive where roaming user profiles are stored:
U:\Users\john.doe
U:\Users\john.wick
U:\Users\john.smith
I need to check if users have files with *.pdf extensions stored in their profiles
$a = Get-ChildItem "U:\users\" -Include *.pdf -Recurse | select FullName
foreach ($b in $a){
Write-Output $b
}
Output
U:\Users\john.wick\desktop\file.pdf
U:\Users\john.wick\documents\a.pdf
U:\Users\john.doe\desktop\1.pdf
..................................
I need to write column to extract username from path, and one column with full file path.
How to do it ?
john.doe
john.wick
--------
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
Get-ChildItem
不使用-Recurse
来发现配置文件文件夹,然后使用Where-Object
+Get-ChildItem
查找包含 pdf 的文件夹:找到相关文件夹后,您只能获取名称:
Call
Get-ChildItem
without-Recurse
to discover the profile folders, then useWhere-Object
+Get-ChildItem
to find the ones containing pdfs:Once you've discovered the relevant folders, you can grab the name only: