Powershell变量中的特殊字符文本格式 [英] Powershell special character text formatting in variable

查看:122
本文介绍了Powershell变量中的特殊字符文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我确定这已经在某个地方以某种方式解决了,但我很长时间内找不到答案。


我正在编写脚本,其中对象的名称(我必须使用名称)包含字符'['和']'。


操作我正在做的是-match


因此我有:



$ OutputList = " lt-LT_LP



示例[g-CN_LIP]


示例[chr-Cher-US_LIP]"




我正在尝试将此列表与许多不同的输出进行比较,例如


$ Comparision = "示例[g-CN_LIP]"



变量只是一个例子,我将它们作为输出。我需要实际设置正确地跟随线。


$ OutputList -match $ Comparision


我得到的错误:



解析"示例[g-CN_LIP]" - [xy]范围的顺序相反。


< span style ="color:#ff0000; font-size:x-small">

行:10 char:1


+ $ OutputList -match $ Comparision


+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


     ; + CategoryInfo          ;: OperationStopped :( :) [],ArgumentException


    + FullyQualifiedErrorId: System.ArgumentException







问题是$ Comparision包含那些"["和"]字符,我无法管理解释powershell


这只是一个文本!!!


请帮助我出去。我试图更换,但没有成功。我尝试了正则表达式,它为每个空格添加了字符"\",[并且]因此我无法比较它,因为文本不同。


我需要能够使用

解决方案

'示例[1] 2"'-match'\ [1 \\ \\]'

Hi All,

I'm sure this was already sorted out somehow somewhere but I couldn't find the answer within a veery long time.

I'm currently working on script where the name of the object (and I must work with name) contains character '[' and ']' .

The operation I'm doing with it is -match

therefore I have:

$OutputList="lt-LT_LP

Example[g-CN_LIP]

Example[chr-Cher-US_LIP]"

and I'm trying to compare this list with many different outputs such as

$Comparision="Example[g-CN_LIP]"

The variables are just an example, i'm getting them as an output. What I need actually to set properly is following line.

$OutputList -match $Comparision

The error I'm getting:

parsing "Example[g-CN_LIP]" - [x-y] range in reverse order.

At line:10 char:1

+ $OutputList -match $Comparision

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], ArgumentException

    + FullyQualifiedErrorId : System.ArgumentException

The problem is that the $Comparision contains those "[" and "]" characters and I can't manage to explain powershell

THAT IT'S JUST A TEXT!!!

Please help me out. I tried to replace, no success. I tried regex, it added character "\" to every space, [ and ] therefore I can't compare it anymore because the text is different.

I need to be able to use

解决方案

'Example[1]2"' -match '\[1\]'


这篇关于Powershell变量中的特殊字符文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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