Solved

PowerShell Error with Regex Object

Posted on 2015-02-11
4
85 Views
Last Modified: 2015-02-11
I have code that I've been testing in one environment, with no problems. I've recently moved it into the production environment, and am teasting it in 'phases'. One block of code that was working fine is now giving me an error. The actual code is:
	if ([regex]::match($file,'_[0-9]{8}_[0-9]{6,}$').Success = $true)
	{
		...
	}

Open in new window

and the error message I am receiving is:
"Success" is a ReadOnly property.
At D:\CABDataImport\common\AutoClientLoad\MoveFilesToStaging.ps1:35 char:51
+     if ([regex]::match($file,'_[0-9]{8}_[0-9]{6,}$'). <<<< Success = $true)
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Open in new window

0
Comment
Question by:dbbishop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 350 total points
ID: 40603632
You probably meant "... -eq $True", not "... = $True".
0
 
LVL 40

Expert Comment

by:footech
ID: 40603634
It should be
if ([regex]::match($file,'_[0-9]{8}_[0-9]{6,}$').Success -eq $true)

Open in new window


"-eq" instead of "="
I've made that mistake before too.
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 150 total points
ID: 40603685
And best way is to leave that out completely. A boolean is a boolean!
if ([regex]::match($file,'_[0-9]{8}_[0-9]{6,}$').Success)

Open in new window

0
 
LVL 15

Author Closing Comment

by:dbbishop
ID: 40603726
oBdA got it first (by seconds). I should have thought of Qlemo's answer. He is correct, a boolean is a boolean.
Live and learn :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question