2017-01-27 11 views
1

私は自分の考えを作業コードにまとめるのに少し助けが必要です。Zipファイルをダウンロードして解凍するPowerShellスクリプト

これは私が持っているものです。

第一ステップ:私はのparamsとしてFTPユーザー名とパスワードを取得しています。

param(#define parameters 
[Parameter(Position=0,Mandatory=$true)] 
    [string]$FTPUser 
[Parameter(Position=1,Mandatory=$true)] 
    [string]$FTPPassword  
[Parameter(Position=2,Mandatory=$true)] 
    [string]$Version  
) 

私は、これらの変数を設定します。

$FTPServer = "ftp.servername.com" 
$SetType = "bin" 

、私は接続を確立したいです。私はSyntaxのためにGoogleがこれを見つけた。これがFTP接続を確立するかどうかは不明です。

$Versionは私の入力パラメータの一つである:私はこれは私がコーディングする方法がわからない部分です

$webclient = New-Object System.Net.WebClient 
    $webclient.Credentials = New-Object System.Net.NetworkCredential($FTPUser,$FTPPassword) 

、テストするためにまだいます。私は(スクリプトが実行されてから)私のローカルマシンの"C:\myApp\$Version"フォルダにそのClient.zipをダウンロードしたい

ftp.servername.com\builds\my builds\$Version\Client\Client.zip 

:として私は、FTPでのzipファイルを持っています。 したがって、FTPダウンロードでは、実行ごとにC:\myAppにある$versionという名前の新しいサブフォルダが作成されます。

これが完了すると、私はまた、あなたがzipや解凍しようとしている場合に応じて、C:\myApp\$Version\Client\<content of the zip file will be here>

+1

解凍:http://stackoverflow.com/questions/27768303/how-to-unzip-a-file-in-powershellかhttps://msdn.microsoft.com/en-us/powershell/reference/5.0/microsoft.powershell.archive/expand-archive。 PowershellのWinSCPアセンブリを調べることも考えています。https://winscp.net/eng/docs/library_powershell – dbso

答えて

1
Add-Type -assembly "System.IO.Compression.Filesystem"; 
[String]$Source = #pathA ; 
[String]$Destination = #pathB ; 
[IO.Compression.Zipfile]::ExtractToDirectory($Source, $Destination); 

または

[IO.Compression.Zipfile]::CreateFromDirectory($Source,$Destination); 

の下で、このclient.zipファイルを解凍する方法を知っておく必要があります。

2

Expand-Archiveコマンドレットを使用できます。 Powershellバージョン5で利用可能です。以前のバージョンではわかりません。構文は以下を参照してください:

Expand-Archive $zipFile -DestinationPath $targetDir -Force

-Forceパラメータは、それが存在する場合は、ターゲットディレクトリ内のファイルを上書きする強制します。あなたのパラメータを持つ

、それは次のようになります。

Expand-Archive "C:\myApp\$Version\Client.zip" -DestinationPath "C:\myApp\$Version" -Force

関連する問題