Solved

PowerShell Error with Regex Object

Posted on 2015-02-11
4
75 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
4 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 350 total points
Comment Utility
You probably meant "... -eq $True", not "... = $True".
0
 
LVL 39

Expert Comment

by:footech
Comment Utility
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 68

Assisted Solution

by:Qlemo
Qlemo earned 150 total points
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now