Parameters

Welcome Forums General PowerShell Q&A Parameters

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #177781

    Participant
    Topics: 4
    Replies: 5
    Points: 57
    Rank: Member

    Hi everyone, good day,

    I am a beginner in PS, and I would like to ask you: I know how to copy some files from one folder to another, and I would like to know how to use a parameter, that when i run the script, it will ask for the bunch of files that I want to copy to the specific folder, how is possible to do that?

    Many thanks in advance.

     

  • #177819

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,651
    Helping Hand
    Rank: Community Hero

    If I under your question properly, you just need to avoid -Path parameter of Copy-item cmdlet. Its a mandatory parameter and will prompt for input.

  • #177831

    Participant
    Topics: 0
    Replies: 4
    Points: 52
    Rank: Member

    Hi everyone, good day,

    I am a beginner in PS, and I would like to ask you: I know how to copy some files from one folder to another, and I would like to know how to use a parameter, that when i run the script, it will ask for the bunch of files that I want to copy to the specific folder, how is possible to do that?

    Many thanks in advance.

    Hi @alejandro01gtcz,

    Hope the below snippet gives you an idea:

    
    $destinationFolder = Read-Host -Prompt "Specify Destination folder"
    $acceptInput = 'Y'
    $files= New-Object System.Collections.Generic.List[string]
    do
    {
    $files.Add($(Read-Host -Prompt "Specify Files to be copied"))
    $acceptInput = Read-Host -Prompt "Do you want to add more files (Y/N)"
    }while ($acceptInput -ne 'N' -or $acceptInput -ne 'n')
    
    

    Please share the script which you have so that we can discuss on it more.

    Thanks.

  • #178020

    Participant
    Topics: 4
    Replies: 5
    Points: 57
    Rank: Member

    Hi @James_Yumnam89

    Many thanks for your reply.

    My script is the following:

    At the moment I have this instruction: Copy-Item -Path $feg -Destination $Incoming -Filter *.zip

    The variable $feg = "D:\feg01\*.zip"

    I would like, in place to copy the files from $feg = "D:\feg01\*.zip" to ask me to set the path from the beginning as parameter.

    How it is possible to do that?

    Many thanks in advance,

    Alejandro

    Clear-Host

    $Failed = "D:\LPStorage\Fail\*"
    $Archive = "D:\LPStorage\Archive\*"
    $Incoming = "D:\LPStorage\incoming\"
    $Processed = "D:\LPStorage\processed\*"
    $Checkstate = "D:\LPStorage\Checkstates\12345\*"
    $feg = "D:\feg01\*.zip"
    $feg01 = "feg01"

    #Copy DSUBS into the LPAdmin\Incoming folder.

    Copy-Item -Path $feg -Destination $Incoming -Filter *.zip
    Write-Host "DSUB has been copied to $($Incoming) folder" -BackgroundColor Red

    #Wait-Process -Timeout 30
    Start-Sleep -S 180

    #Verify if the DSUB's were successfully moved to the Processed, Archive, Checkstate or Fail folder.

    (Get-ChildItem -include *.zip -Path $Processed -Filter *.zip).Count
    (Get-ChildItem -include *.7z -Path $Archive -Filter *.7z).Count
    (Get-ChildItem -include *.xml -Path $Checkstate -Filter *.xml).Count
    (Get-ChildItem -include *.zip -Path $Incoming -Filter *.zip).Count
    (Get-ChildItem -include *.zip -Path $Failed -Filter *.zip).Count

  • #178077

    Participant
    Topics: 4
    Replies: 5
    Points: 57
    Rank: Member
    
    Clear-Host
    
    $Failed = "D:\LPStorage\Fail\*"
    $Archive = "D:\LPStorage\Archive\*"
    $Incoming = "D:\LPStorage\incoming\"
    $Processed = "D:\LPStorage\processed\*"
    $Checkstate = "D:\LPStorage\Checkstates\12345\*"
    $feg = "D:\feg01\*.zip"
    $feg01 = "feg01"
    
    #Copy DSUBS into the LPAdmin\Incoming folder.
    
    Copy-Item -Path $feg -Destination $Incoming -Filter *.zip
    Write-Host "DSUB has been copied to $($Incoming) folder" -BackgroundColor Red
    
    #Wait-Process -Timeout 30
    Start-Sleep -S 180
    
    #Verify if the DSUB's were successfully moved to the Processed, Archive, Checkstate or Fail folder.
    
    (Get-ChildItem -include *.zip -Path $Processed -Filter *.zip).Count
    (Get-ChildItem -include *.7z -Path $Archive -Filter *.7z).Count
    (Get-ChildItem -include *.xml -Path $Checkstate -Filter *.xml).Count
    (Get-ChildItem -include *.zip -Path $Incoming -Filter *.zip).Count
    (Get-ChildItem -include *.zip -Path $Failed -Filter *.zip).Count
    
    
  • #178080

    Participant
    Topics: 4
    Replies: 5
    Points: 57
    Rank: Member

    Hi @James_Yumnam89

    
    Clear-Host
    
    $Failed = "D:\LPStorage\Fail\*"
    $Archive = "D:\LPStorage\Archive\*"
    $Incoming = "D:\LPStorage\incoming\"
    $Processed = "D:\LPStorage\processed\*"
    $Checkstate = "D:\LPStorage\Checkstates\12345\*"
    $feg = "D:\feg01\*.zip"
    $feg01 = "feg01"
    
    #Copy DSUBS into the LPAdmin\Incoming folder.
    
    Copy-Item -Path $feg -Destination $Incoming -Filter *.zip
    Write-Host "DSUB has been copied to $($Incoming) folder" -BackgroundColor Red
    
    #Wait-Process -Timeout 30
    Start-Sleep -S 180
    
    #Verify if the DSUB's were successfully moved to the Processed, Archive, Checkstate or Fail folder.
    
    (Get-ChildItem -include *.zip -Path $Processed -Filter *.zip).Count
    (Get-ChildItem -include *.7z -Path $Archive -Filter *.7z).Count
    (Get-ChildItem -include *.xml -Path $Checkstate -Filter *.xml).Count
    (Get-ChildItem -include *.zip -Path $Incoming -Filter *.zip).Count
    (Get-ChildItem -include *.zip -Path $Failed -Filter *.zip).Count
    
    

You must be logged in to reply to this topic.