Powershell: Move Items Based on Destination from Hashtable -


I am trying to write a PowerShell script to transfer files from one directory to another based on certain conditions. For example:

  1. An example of a file name: testcenter123456-testtype-222-412014.pdf.

  2. The script should first search for "test center 123456" before the first dash ("-") and then see a hash table for the matching key. All files follow the format shown above.

  3. Once it finds its key, then that key should use the same value (Example: "c: \ temp \ destination \ customer7890") Destination file path And copy that file as.

    I looked around the stack overflow and got some questions & amp; As it was to answer some parts of similar questions but the fact is that

    Even so far what I have:

      $ hashTable = ConvertFrom-StringData (this is a very new one) [IO.File] :: ReadAllText ("c: \ temp \ filepaths.txt")) $ directory = "c: \ temp \ source" Go-ChildItem $ directory | where {! ($ _ PsIsContainer)} | Foreach-Object {Foreach ($ $ $ in hashtable.net.net Entertainment (key of $) {if ($ _. Name Shuttleing (0, $ _. Name Indexoff ("-") - EC $ key. {Copy-item-path $ _Fullname -Destination $ key.Value}}}   

    If anyone can get help with me and I hope that in this process about PowerShell You have to learn a little bit, appreciate D.

    Honestly, I do not see that it Why it should not work. It would be useful if you Has told us which line is generating an error.

      Forte ($ $ key in $ HashTab.Net Entertainment ($)) {if ($ _. 0, $ _Name.IndexOf ("-") - EC $ key. {} Copy-item-path $ _ fullname -nn $ key.value}}   

    He said, By using a hashtable to loop through your entries, you're missing the point of matching on the key manually. With a hashtable, you do not need a loop eg

      $ Hshtable = Knhwartfrom-Stringdata ([Iokfail] :: Readalltest ( "c: \ temp \ Filepatsktst")) gate-Cilditm C: \ temp \ Source | where {! ($ _ PsIsContainer)} | The object-object {$ key = $ _} name. Substrings (0, $ _., The name ("-") $ $ val = $ ishtable $ Key if ($ val) {$ _ | Copy-item - $ $ val -WhatIf} and {write-alert "no entry for $ key"}}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -