Last active
December 16, 2015 07:08
-
-
Save hidari/5396195 to your computer and use it in GitHub Desktop.
JenkinsでPowerShellを使ってリモートの(Windows, AD)サーバへファイルをコピーするには.スクリプト内で資格情報オブジェクトを作ってそれを使ってサーバにアクセスする.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ユーザ名 | |
$user = "domain\username" | |
# パスワード | |
$spass = ConvertTo-SecureString "password" -AsPlainText -Force | |
# PSCredential(資格情報)オブジェクトを作成 | |
$cred = New-Object System.Management.Automation.PSCredential($user, $spass) | |
# PSCredentialオブジェクトを使ってこのスクリプトからアクセス可能なPSDriveを作成 | |
New-PSDrive -Name Hoge -PSProvider FileSystem -Root \\Foo\Bar -Credential $cred | |
# コピーを実行 | |
$outputs = Copy-Item -Path "C:\test\src\Fuga.txt" -Destination "Hoge:\Foo\Bar\DestDit\Fuga.txt" -Force -PassThru | |
# コピーしたファイルと件数を表示 | |
$outputs | |
$outputs.Count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment