Export function

不羁的心 提交于 2019-12-02 09:26:01

The -match operator checks against a regular expression, so this:

$script:newLog -match ".*"

is testing if the filename contains any charachter except newline (.) 0 or more times (*). This condition will always be true, thus creating an infinite loop.

If you want to test for a literal dot, you must escape it:

$script:newLog -match '\.'

As for your other question, you're misunderstanding how logical and comparison operators work. $exportInvoke -eq "Y" -or "N" does not mean $exportInvoke -eq ("Y" -or "N"), i.e. variable equals either "Y" or "N". It means ($exportInvoke -eq "Y") -or ("N"). Since the expression "N" does not evaluate to zero, PowerShell interprets it as $true, so your condition becomes ($exportInvoke -eq "Y") -or $true, which is always true. You need to change the condition to this:

$exportInvoke -eq "Y" -or $exportInvoke -eq "N"

Use this to test your input:

!($script:newLog.contains('.')) -and !([String]::IsNullOrEmpty($script:newLog)) -and !([String]::IsNullOrWhiteSpace($script:newLog))

Your regular expression (-match ".*" is essentially matching on everything.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!