小编mca*_*ing的帖子

Get-ChildItem -force在"我的文档"文件夹和其他联结点上报告"拒绝访问"

我有一个我写的脚本替换文件.我将params传递给它以获取文件的名称和要搜索的基本位置.工人线是:

$SubLocations = Get-ChildItem -Path $Startlocation -Recurse -include $Filename -Force  | 
                Where { $_.FullName.ToUpper().contains($Filter.ToUpper())}
Run Code Online (Sandbox Code Playgroud)

我将$ Startlocation设置为"C:\ Users",但是,当我试图通过其他用户文件夹进行递归时,我被拒绝访问.我是机器上的完全管理员,我已经尝试过运行PowerShell作为管理员.我可以通过Windows资源管理器访问所有文件,没有任何问题.任何的想法?

Get-ChildItem : Access to the path 'C:\Users\jepa227\Documents\My Music' is denied.
At C:\Users\krla226\Google Drive\Documents\PowerShell\Replace-File.ps1:35 char:46
+ $SubLocations = Get-ChildItem <<<<  -Path $Startlocation -Recurse -    include $Filename -Force | 
    + CategoryInfo          : PermissionDenied: (C:\Users\jepa227\Documents\My     Music:String) [Get-ChildItem], Una 
   uthorizedAccessException
+ FullyQualifiedErrorId :  DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Run Code Online (Sandbox Code Playgroud)

UPDATE

虽然我无法通过GCI工作,但我能够使用WMI来解决我的问题.对于有兴趣的人:

$SubLocations = Get-WmiObject -Class cim_datafile -Filter "fileName = '$filename' AND Extension = '$extension'" | 
                            Where { $_.Name.ToUpper().contains($Filter.ToUpper()) }
Run Code Online (Sandbox Code Playgroud)

powershell acl access-denied

11
推荐指数
2
解决办法
2万
查看次数

ElasticSearch NEST:通过指定json,通过ElasticClient创建索引

我们允许客户在创建索引时定义自定义分析器.我们希望在json中指定它,以通过底层的ElasticSearch文档提供最大的灵活性和可理解性.

我想使用json字符串中定义的分析器,映射器等的任意描述来创建索引.使用sense,我的命令是

PUT /my_index
{
    "settings": 
    {
        "analysis": 
        {
            "char_filter" : 
            {
                "my_mapping" : 
                {
                    "type" : "mapping",
                    "mappings" : [".=>,", "'=>,"]
                }
            },
            "analyzer": 
            {
                "my_analyzer": 
                {
                    "type":         "custom",
                    "tokenizer":    "standard",
                    "filter":       ["lowercase" ],
                    "char_filter" : ["my_mapping"]
                }
            }
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我的代码看起来像

string json = RetrieveJson();
ElasticSearchClient client = InitializeClient();
client.CreateIndexUsingJson( json ); // this is the syntax I can't figure out
Run Code Online (Sandbox Code Playgroud)

这里的帖子试图通过实例化一个IndexSettings然后调用Add("analysis",json)来做到这一点,但Add不是我正在使用的ElasticSearch库版本的函数.

我能想象的选项包括:

  1. 不知何故使用ElasticClient.Raw.IndicesCreatePost或类似的东西
  2. 通过IndexSettingsConverter.ReadJson()将json字符串反序列化为IndexSettings对象,然后通过ElasticClient.CreateIndex(ICreateIndexRequest)应用它

这两种机制都有很少的文档.

我绝对试图避免使用CreateIndex的lambda函数版本,因为将用户的json转换为lamdba表达式会很麻烦,只能立即将它们转换回NEST中的json深度.

非常感谢上面#1或#2的其他选项或具体示例,以及解决此问题的推荐方法.

c# elasticsearch nest

5
推荐指数
1
解决办法
4316
查看次数

可以将Write-debug消息传输到Log文件吗?

Write-verbose消息不会重定向到Out-File.

我的高级功能失败,没有任何痕迹,所以我想放置调试消息.当脚本执行时,它将无法在控制台中运行,因此我看不到该消息.

如果消息可以传输到日志文件,那么我可以看到它.Write-debug是否可以将值传递给日志文件?

powershell powershell-2.0

1
推荐指数
1
解决办法
3665
查看次数