Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:41:38+00:00 2026-06-18T00:41:38+00:00

I’ve been working on this one issue for abut a week, and think I’m

  • 0

I’ve been working on this one issue for abut a week, and think I’m missing something obvious…I need a couple sets of eyes.

Starting with this question I researched all the links provided in the answer, and I’m running the following script, gleaned from MS Connect:

$txtPath = "c:\users\xxxxxx\desktop\cgc\tx"
$txtPath2 = "c:\users\xxxxxx\desktop\cgc\tx2"
get-childitem $txtPath | foreach {  
    Move-Item -literalpath $txtPath2.Name $_.Name.Replace ("]" | "[", "_") 
}

Both paths exist. *\tx contains 35 *.txt files, some with square brackets in the name, some without. *\tx2 is currently empty, awaiting output files from the script.

If I’ve written my third statement properly, I’m passing each child from \tx to the function where square brackets are changed to an underscore as the file is moved and re-saved to the new location, \tx2.

Unfortunately, I get this error:

Expressions are only allowed as the first element of a pipeline.
At C:\users\xxxxxx\desktop\cgc\rni.ps1:4 char:71
+     Move-Item -literalpath $txtPath2.Name $_.Name.Replace ("]" | "[", "_" <<<< )
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

If I’m interpreting the error correctly, something’s preventing the close paren to be recognized. Do I need some kind of escape character for the brackets? I tried using a backtick escape and backslash escape inside the quotes, but that led to the same error.

With the escape outside the quotes, I got this error.

The term '\]' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
 of the name, or if a path was included, verify that the path is correct and try again.
At C:\users\xxxxxx\desktop\cgc\rni.ps1:4 char:61
+     Move-Item -literalpath $txtPath2.Name $_.Name.Replace (\"]" <<<<  | \"[", "_")
    + CategoryInfo          : ObjectNotFound: (\]:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:41:39+00:00Added an answer on June 18, 2026 at 12:41 am

    You got the syntax wrong:

    $_.Name.Replace ("]" | "[", "_")
    

    is just nonsense. Usually it would mean “Call the Replace method on $_.Name with the return value of the following as argument: Pipe the string ']' as input into the command '[', '_'”. But here lies the first problem: That’s no command, it’s an expression and that cannot work. Then the problem is that this is the argument to a cmdlet. Special rules apply here and they usually say “convert to string everything that isn’t in parentheses”. So there isn’t even a method call, you’d get the method declaration as the new file name and pass another argument that suffers from the problems described above.

    If I’d have to guess I’d think you want to replace square brackets by underscores. If so, then use the following:

    Move-Item -literalpath $txtPath2.Name ($_.Name -replace '\[|]', '_') 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.