PowerShell:如何在名称为"*"(星号/星号)的文件/文件夹中创建选择器? [英] PowerShell: How do I create selector on file/folder, whose name is '*' (asterisk/star)?

查看:136
本文介绍了PowerShell:如何在名称为"*"(星号/星号)的文件/文件夹中创建选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从PS修改注册表.该注册表项与特定文件(所有扩展名的文件夹)的上下文菜单有关.

I have a need to modify registry from PS. This registry item is related to context menu for particular files (folder for all extensions).

\\HKEY_CURRENT_USER\Software\Classes\*

当前,我想在此路径中添加项目:

Currently I'd like to add items to this path:

HKCU:\Software\classes\*
|- shell
|- shellex

但是,当我在此路径上执行dir时,classes文件夹中会显示所有项目:

However when I do dir on this path, there is output of all items in classes folder:

PS D:\> dir "HKCU:\Software\classes\*"   

    Hive: HKEY_CURRENT_USER\Software\classes    

Name                           Property
----                           --------
*
.3g2                           VLC.backup : WMP11.AssocFile.3G2
                               (default)  : VLC.3g2
.3gp                           VLC.backup : WMP11.AssocFile.3GP
                               (default)  : VLC.3gp
.3gp2                          VLC.backup : WMP11.AssocFile.3G2
                               (default)  : VLC.3gp2
.3gpp                          VLC.backup : WMP11.AssocFile.3GP
                               (default)  : VLC.3gpp
.3mf

如果我正确理解它,我的查询将被星号通配.该注册表项(文件夹)被命名为*. 如何仅为该文件夹创建选择器,而不使其用作通配符?也应对所有其他命令有效,而不仅限于dir(Get-ChildItem).

If I understand it correctly, my query is being wildcarded by asterisk. The registry item (folder) is named *. How do I create selector just for this folder and not make it work as a wild-card? Also should work for all other commands, not just the dir (Get-ChildItem).

已经尝试了这些但没有成功:

Already tried these with no success:

PS D:\> dir "HKCU:\Software\classes\**"
PS D:\> dir "HKCU:\Software\classes\\*"
PS D:\> dir "HKCU:\Software\classes\'*'"
PS D:\> dir "HKCU:\Software\classes\`*"

Get-ChildItem的解决方法:

# argument -LiteralPath, unfortunatelly only for "dir" command
PS D:\> dir -LiteralPath "HKCU:\Software\classes\*"


当我收到与Get-ChildItem有关的具体答案时,请假定对于New-Item(不支持-LiteralPath)应该使用相同的路径.


As I have received answers related particulary to Get-ChildItem, please assume that same path should work for New-Item (which doesn't support -LiteralPath).

推荐答案

Get-ChildItem -LiteralPath "HKCU:\Software\classes\*"

或者:

Get-ChildItem "HKCU:\Software\classes\" | Where-Object PSChildName -eq '*' | Get-ChildItem

如果您想要对象本身的一般解决方案:

If you want a general solution for the object itself:

Get-ChildItem "HKCU:\Software\classes\" | Where-Object PSChildName -eq '*'

这篇关于PowerShell:如何在名称为"*"(星号/星号)的文件/文件夹中创建选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆