Windows でスクリプトをリモートで実行するにはどうすればよいですか?
-
21-08-2019 - |
質問
Windows 2003 サーバーでスクリプトを起動し、別の Windows Server 2008 コンピュータで別のスクリプトを起動したいと考えています。
Powershell でそれができると言われました。それは問題ありませんが、より具体的な詳細が必要です。
誰かこれに関するヒントを持っていますか?
ありがとう!
解決
PSEXEC のSysinternalsの
他のヒント
ATコマンドの構文を調べてください。あなたは、リモートマシン上で実行するためのプロセスをスケジュールするために使用することができます。
ATコマンドのスケジュールのコマンドやプログラムがコンピュータ上で実行します 指定された時刻と日付。スケジュールサービスが使用することを実行している必要があります ATコマンドます。
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
最も簡単な方法は、2つのステップ
になりますA。リモートPCにCygwinをインストールする
B。 MCS '/cygdrive/c/path_to_script.bat'
@ sshのハドソンを実行しますについて話すと PsExec
, 、 私は...するだろう 強く 代わりに Cygwin/OpenSSH を使用することをお勧めします。
SSH には、(次のようなツールに比べて)複数の利点があります。 PsExec
またはカスタムメイドのサービスも可能です)。
たとえば、次のように使用してみてください PsExec
これらを実装してください bash
/ ssh
コマンドラインは次のことを行います:
ssh user@remotehost "find . -name something" 2> all.errors.txt
ssh user@remotehost "grep -r something ."
if [ "$?" == "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
fi
幸運を!
SSH はリモート stdout / stderr / 終了ステータスを (!) に転送します。 地元 検査用シェル
(キラー機能と、リモート実行をローカル スクリプトのロジックに統合するための共通要件)Cygwin/OpenSSH が提供する 標準 POSIXシェル環境
(効率的な時間投資、基本的なツール、クロスプラットフォーム対応、互換性のある習慣など)まだ/常に実行できます 全員ネイティブ Windowsアプリケーション
(自動実行を含む)*.bat
ファイルの作成者cmd
プロセッサ)公開キーを使用してパスワードなしの認証を構成できます
(無人の自動化されたタスクについて考えてください)
ヒント
最初に問題があった要件が 1 つありました。
背景 sshd
サービスはユーザーのグラフィカルセッションでアプリを実行する必要がありました
(アプリケーションウィンドウをデスクトップ環境に表示させるため)。
の 許容可能な解決策 私にとっては走っていました sshd
サービス 直接 ユーザーのGUIセッション内
(ユーザーがログインすると自動的に開始され、リンクをクリックして構成ファイルの変更を確認します):
/usr/sbin/sshd -f /home/user/sshd_config
http://www.experts-exchange.comから受け入れた溶液/OS/Microsoft_Operating_Systems/Q_22959948.html ではあります:
私は何を提供することは取るスクリプトました パラメータが...この場合は4になります。 1)サーバー:あなたは-server渡すと、それがします その1台のサーバー2)リストを行うのみ: サーバのリストファイルを提供することができます。 3)サービス:サービスあなたの名前 4)冗長を変更したい:ではありません ここで使用されます。
私はいくつかミスをしていませんでした 次のコードに変更しました。使用するには カット/というファイルにコードを貼り付け セットRemoteService.ps1を。に確認してください 実行するために、あなたのexecutionpolicyを設定 スクリプト...それは、デフォルトではないでしょう。君は 使用してそれを行います Set-ExecutionPolicyコマンドレットを。 PS> セットExecutionpolicyを「RemoteSigned」に あなたがPSを行うスクリプトを実行します> C:\ PathToScript \セットRemoteService.ps1 -list C:\ ServerList.txt -service "DHCP"
#########################のParam($サーバー、$リスト、$サービス、[スイッチ]冗長$)IF($冗長){$ VerbosePreference = {}もし($リスト) "続行" foreachの((取得コンテンツ$リストの$ SRV)) { $クエリは= "Win32_Serviceの名前= '$サービス' SELECT * FROM" $ myServiceという= GET-WmiObjectコマンド-query $クエリ-computer $ SRV $ myService.ChangeStartMode( "自動") $ myService.Start() }} {($サーバ)であれば $クエリは= "Win32_Serviceの名前= '$サービス' SELECT * FROM" $ myServiceという= GET-WmiObjectコマンド-query $クエリ-computerの$サーバー $ myService.ChangeStartMode( "自動") $ myService.Start()}