Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PowerShell Error with Regex Object

Posted on 2015-02-11
4
Medium Priority
?
88 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 85

Accepted Solution

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

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 71

Assisted Solution

by:Qlemo
Qlemo earned 600 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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