1

Can you guys work it out. I'm pretty sure it's just minor syntax error cause i'm noob at this... I'm always getting "Wrong file" no matter what input($name) is.

$name = "DE123456.zip"
if ($name -contains "DE") 
{
  Get-ChildItem C:\test\$name | 
   % {
     $to  = $_.basename.length - 2
     $path = $_.basename.substring( 0, $to)
     & "C:\test\7z.exe" "x" "-y" $_.fullname "-oC:\test\$path"
     }
  }
ELSE
{
"Wrong file"
}

2 Answers 2

2

A syntax error would be emitted before your script ran.

Your problem is that -contains as an operator only checks for existence of values in an array. You want the .Contains method on the string instead:

if ($name.Contains('DE')) ...
Sign up to request clarification or add additional context in comments.

Comments

0

Change

if ($name -contains "DE") 

with

if ($name -match "DE") 

and:

get-help about_comparison_operators

to know the difference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.