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:
-
An example of a file name: testcenter123456-testtype-222-412014.pdf.
-
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.
-
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
Post a Comment