troubleshooting Question

File Split and move processed to archive using powershell

Avatar of SQLM_M
SQLM_MFlag for India asked on
6 Comments2 Solutions452 ViewsLast Modified:

I tried to make code dynamic, but couldn't able to move the files. Please help me the solve this..

$pattern = @("Mobile Originated Call", "Mobile Terminated Call", "Network Info")

$SourcePath = "D:\tap3"
$FileType = "*.cdr"
$DestPath = "D:\tap3\Archive\"

Get-ChildItem "$SourcePath\$FileType" |
  % { # $_ is file
    $name = $
    get-content $_ |
    % { # $_ is single line
      foreach ($p in $pattern)
      { if ($_.StartsWith($p))
        { Out-File -Append -FilePath "$SourcePath\$p\$name" -InputObject $_  }
Move-Item "$SourcePath\$p\$name" "$DestPath\$name" -Force
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros