locked
Powershell Script Not putting any data in output RRS feed

  • Question

  • I have a powershell script that matchs a text file with file names to a directory consisting of data files On the first match between these 2 it should copy the matched file in the directory to another directory.'

    The text file consists of file names only    The directory consists of the text data for these file name

    test1.txt                                                   test4

    test2.txt                                                   test3

    test3.txt                                                   test5

    Inside test2 test3 and test3 are DB deployments scripts.

    Since test3 is the first match the data file test3 should move to an output directory but its not 

    Here is my script

    $objFolder = "C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\"  #(directory)
    $objFile = "C:\Serena\ReleaseAutomationAgent\core\var\work\tmp\compare2.txt" #(File)
    $outFile ="C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\deploy\"  #Output Directory
    Compare-Object -ReferenceObject (gc $objFile) -DifferenceObject (gci $objFolder|select -ExpandProperty Name) -ExcludeDifferent -IncludeEqual|select -first 1 -Expand InputObject | %{Copy-Item "objFolder\$_" -Dest $outFile}

    Any help on this would be appreciated

    Wednesday, July 16, 2014 7:28 PM

Answers

  • That seems horribly convoluted.

    I'd do something like this:

    $objFolder = "C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\"  #(directory)
    $objFile = "C:\Serena\ReleaseAutomationAgent\core\var\work\tmp\compare2.txt" #(File)
    $outFile ="C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\deploy\"  #Output Directory
    $compare = get-content $objFile
    gci $objFolder | where {$compare -contains $_.name} |
     %{Copy-Item "$objFolder\$_" -Dest $outFile}


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


    • Edited by mjolinor Wednesday, July 16, 2014 8:19 PM
    • Proposed as answer by Albiz Thursday, July 17, 2014 7:29 AM
    • Marked as answer by ScriptingWife Tuesday, August 12, 2014 12:07 AM
    Wednesday, July 16, 2014 8:17 PM

All replies

  • $objFolder = "C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\"  #(directory)
    $objFile = "C:\Serena\ReleaseAutomationAgent\core\var\work\tmp\compare2.txt" #(File)
    $outFile ="C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\deploy\"  #Output Directory
    Compare-Object -ReferenceObject (gc $objFile) -DifferenceObject (gci $objFolder|select -ExpandProperty Name) -ExcludeDifferent -IncludeEqual|select -first 1 -Expand InputObject | %{Copy-Item "$objFolder\$_" -Dest $outFile}
    You are missing the $ before objFolder. Nothing will be shown on the console, but the file will be copied.
    Wednesday, July 16, 2014 8:06 PM
  • You can't compare a file with a folder.  That doesn't make any sense.

    You need to rethink and rewrite your question. It makes very little sense:

    You wrote: "Inside test2 test3 and test3 are DB deployments scripts"

    What are you trying to say?

    Please try to be clear and unambiguous.


    ¯\_(ツ)_/¯

    Wednesday, July 16, 2014 8:11 PM
  • That seems horribly convoluted.

    I'd do something like this:

    $objFolder = "C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\"  #(directory)
    $objFile = "C:\Serena\ReleaseAutomationAgent\core\var\work\tmp\compare2.txt" #(File)
    $outFile ="C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\deploy\"  #Output Directory
    $compare = get-content $objFile
    gci $objFolder | where {$compare -contains $_.name} |
     %{Copy-Item "$objFolder\$_" -Dest $outFile}


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


    • Edited by mjolinor Wednesday, July 16, 2014 8:19 PM
    • Proposed as answer by Albiz Thursday, July 17, 2014 7:29 AM
    • Marked as answer by ScriptingWife Tuesday, August 12, 2014 12:07 AM
    Wednesday, July 16, 2014 8:17 PM