How to copy the zip folder using user input values instead of hardcoded and also after placing the zip in visual studio distination folder need to clean and build the.csproj
$source = "C:\Users\name\Downloads"
$archive = "C:\Users\name\Downloads"
$Name = "xyz.zip"
$destination = "D:\repo"
$ArchiveFile = Join-Path -Path $archive -ChildPath $Name
Copy-Item -Path $ArchiveFile -Destination $destination -Force
function
definition,function Copy-BuildArchive
{
param()
$archive = "C:\Users\name\Downloads"
$Name = "xyz.zip"
$destination = "D:\repo"
$ArchiveFile = Join-Path -Path $archive -ChildPath $Name
Copy-Item -Path $ArchiveFile -Destination $destination -Force
}
param
block:function Copy-BuildArchive
{
param(
[string]$Name,
[string]$Archive,
[string]$Destination
)
$ArchiveFile = Join-Path -Path $Archive -ChildPath $Name
Copy-Item -Path $ArchiveFile -Destination $Destination -Force
}
function Copy-BuildArchive
{
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Archive = $(Join-Path $HOME "Downloads"),
[string]$Destination = $(Join-Path $HOME "Documents")
)
$ArchiveFile = Join-Path -Path $Archive -ChildPath $Name
Copy-Item -Path $ArchiveFile -Destination $Destination -Force
}
Congratulations - you just turned your script into a parameterized function!
Now, after executing the function
definition, you can do:
Copy-BuildArchive -Name project.zip -Archive C:\build\path -Destination C:\output\path
or
Copy-BuildArchive -Name somethingElse.zip # using default values for Archive and Destination
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.