Parameters

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.

 

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.

[quote quote=177781]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.

[/quote]
Hi @alejandro01gtcz,

Hope the below snippet gives you an idea:

[pre]

$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’)

[/pre]

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

Thanks.

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

[pre]

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

[/pre]

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