ドメインに参加しているすべてのコンピュータにライセンスファイルをコピーしようとしています。 、PowerShellのみを使用できます。 GPOまたはスケジュールされた(GPO)スケジュールされたタスクは、Server 2003環境内ではまだ可能ではないように見えるため、スケジュールされていません。 これに関するアプリケーションは既にインストールされており、ライセンスファイルのみを上書きする必要があります。複数のチェックを含むドメインコンピュータへのPowerShell一括コピー
私は達成するために期待しています: - 他 をスキップし、存在する場合、32bのフォルダの場所のためのコピーをチェック - - をスキップ他、オンラインかどうかを確認、64bのフォルダの場所を確認するコピーを存在する場合、他の をスキップ - 書きますすべてのコンピュータの結果がログファイルに出力されるので、成功することができます。
1回目の試み。私が現在持っている
コード:
$computers = gc "c:\temp\computers.txt" $source = "c:\temp\almmodule.lic" $dest32b = 'c$\program files (x86)\ALM - Automatic Login Module' $dest64b = 'c$\program files\ALM - Automatic Login Module' $TestPath32 = Test-Path -path "\\$computer\$dest32b\*" $TestPath64 = Test-Path -path "\\$computer\$dest64b\*" foreach ($computer in $computers) { if (test-Connection -Cn $computer -quiet) { IF (!$TestPath32) { Copy-Item $source -Destination "\\$computer\$dest32b" -recurse -force -verbose} ELSE { "$computer' 32b folder not found. Skipping"} IF (!$TestPath64) { Copy-Item $source -Destination "\\$computer\$dest64b" -recurse -force -verbose} ELSE {"$computer 64b folder not found. Skipping"} ELSE { "$computer is not online" } } }
私はいくつかのマイナーなバリエーションを試してみたが、私はどこに行くように見えることはできません。 ロギングも作成する必要があります。
自分自身をテストターゲットとして使用し、上記の変数を実行し、単一のコマンドを使用します。 "\ $コンピュータの\ $のdest32bは*"
戻り-path
$ TestPath32 =テストパス:真
コピー項目$源-Destination "\ $コンピュータ\ $ dest32b" -recurse - 力は-verbose
は成功し、コピー現時点でPowerShellを実行して、ファイル
は、最後のELSE文の文句を言います。
しかし、ほとんどの場合、私は64bフォルダを持っていないことに気づきませんでした。そして、それはエラーを出したり、ディレクトリをファイル名として置いたりします。
私は喪失しています。私は今、私が持っている小さなものを制動するのを恐れています。
第二の試み。
私はこのコードを編集し、いくつかの部分をコメントアウトしました。そこから進歩するための作業用モデルを得るためです。
foreach ($computer in $computers) { $TestPath32 = Test-Path "\\$computer\$dest32b\*" $TestPath64 = Test-Path "\\$computer\$dest64b\*" # if (test-Connection -Cn $computer -quiet) { IF (!$TestPath32) { Copy-Item $source -Destination "\\$computer\$dest32b\" -recurse -force -verbose} ELSE {"$computer' 32b folder not found. Skipping"} IF (!$TestPath64) { Copy-Item $source -Destination "\\$computer\$dest64b\" -recurse -force -verbose} ELSE {"$computer 64b folder not found. Skipping"} # ELSE { # "$computer is not online" # } #} }
今すぐ返します。
PS C:\windows\system32> C:\Temp\ALM 2016 LIC copy.ps1 L2016010' 32b folder not found. Skipping VERBOSE: Performing operation "Copy File" on Target "Item: C:\temp\almmodule.lic Destination: \\L2016010\c$\program files\ALM - Automatic Login Module\". Copy-Item : De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist. At C:\Temp\ALM 2016 LIC copy.ps1:14 char:12 + Copy-Item <<<< $source -Destination "\\$computer\$dest64b\" -force -verbose} + CategoryInfo : NotSpecified: (:) [Copy-Item], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
私は32Bパスを持っていますかを保証することができます。コピーアイテムはファイルを配置しません。 私は明らかに64bパスを持っていません、そして、私はそれがちょうどきちんと$ falseを返すのではなく、これを破ると感じます。
彼のパス(私はそれが失敗の原因だと思ったので)で、私は混乱arroundの、それは時々名前のプログラムファイルでファイル置く - ライセンスファイルのサイズである「ALM自動ログインモジュール」 。
また、
Copy-Item $source -Destination "\\$computer\$dest32b\"
をスタンドアロンとして実行すると、ファイルをコピーします。今働いて
第三の試み;
$computers = gc "c:\temp\computers.txt"
$source = "c:\temp\almmodule.lic"
$dest32b = 'c$\program files (x86)\ALM - Automatic Login Module'
$dest64b = 'c$\program files\ALM - Automatic Login Module'
foreach ($computer in $computers) {
$TestUp = test-Connection -Cn $computer -quiet
$TestPath32 = Test-Path -pathType container "\\$computer\$dest32b"
$TestPath64 = Test-Path -pathType container "\\$computer\$dest64b"
IF (!$TestUp) {
write-host "$computer is not online"
} ELSE {
IF (!$TestPath32){
write-host "$computer' 32b folder not found. Skipping"
} ELSE {
Copy-Item $source -Destination "\\$computer\$dest32b\" -force -verbose
}
IF (!$TestPath64){
write-host "$computer 64b folder not found. Skipping"
} ELSE {
Copy-Item $source -Destination "\\$computer\$dest64b\" -force -verbose
}
}
}
の使用$は完全に私の頭の上に行って、私がした時点から動作するようになっていた!
は今、スクリプトが存在しないフォルダをスキップしない場合は、THEN、ELSE
、ダウンコンピュータをまだテストすることはできませんでしたが、私は今これも動作すると仮定します。
今私が把握する必要があるすべては、1つのログファイルに出力をログに記録する方法です、コメントで述べたように、私は、同様GPOに投票読める形式
をGPO許可されていない理由として、実際のソリューション?これは、新しいコンピュータがオンラインになるたびにライセンスファイルを手動でインストールする必要がないため(または古いものを再構築するなど)、最も適切なソリューションと思われます。 –
[File Item](https://technet.microsoft.com/en-us/library/cc772536(v = ws.11).aspx)オプションは、これを行うためのより良い方法です。あなたは望み、x86/x64を扱うためにフィルタリングすることができます。 –
GPOは実際には不可能です。 Windows 2003は、私が見ている限り、そのような種類のGPOをまだサポートしていません。 –