パスワードの入力を受け入れるバッチファイルがあります。それは何らかの理由で最後の文字を取ることはなく、私はそれを理解できません。バッチファイルに設定されたパスワードが最後の文字を使用しない
powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
echo psexec \\%computerName% -u %domainName%\%userName% -p %password% cmd
私はset /p password="Enter password: "
でそれをテストし、まだ最後の文字をエコーするために失敗したので、それはPowerShellコマンドではありません知っています。 。私の問題は、3つのドメインの2のために、PSEXECが実行されることである
set /P domainName=
set params = %*:"=""?!
if "%domainName%" == "1" (
set "domainName=domain1"
goto nextstep
)
if "%domainName%" == "2" (
set "domainName=domain2"
goto nextstep
)
if "%domainName%" == "3" (
set "domainName=domain3"
goto nextstep
) else (
goto resetfile
)
:nextstep
:私が使用した文の場合は、ここに私のコメントを1として
であり、 domain1の場合、domain1は実行されません。私はコマンドをエコーし、それは完全に印刷されます。コマンドからecho
を削除すると、そのすべてがスキップされ、ファイルが再起動されます。
nextstep
は次のとおりです。私は、スクリプトを再起動する場合、スクリプトにも聞いていません
:nextstep
set /p userName="Enter your Admin username: "
powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
psexec \\%computerName% -u %domainName%\%userName% -p %password% cmd
:resetfile
set resetfile=
set /p resetfile="Do you want to restart this file? Press 'y' for Yes or 'n' for No then Press ENTER: "
if not '%resetfile%'=='' set resetfile=%resetfile:~0,1%
if '%resetfile%'=='y' goto start
。スクリプトの先頭にある:start
にループバックします。
助けてください、ありがとうございます!
でそれを使用することができ、私はパスワードの最後の文字が '&^%'や '!'のような特殊文字であると遅延拡張が有効になっていると仮定します。 "echo psexec.exe" \\%computerName% "-u"%domainName%\%userName% "-p"%password% "cmd'を試してください。 'psexec.exe'を実行する場合は、二重引用符を使用する必要があります。しかし、パスワードに遅延拡張を有効にした '%'や '!'が含まれている場合は、 'echo psexec.exe '\\%computerName%-u"%domainName%\%userName% "-p"!password! "以前はもちろん 'setlocal EnableDelayedExpansion'を使って' cmd'を実行しました。 – Mofi
正直なところ、SecureStringを再び安全でないようにするという激しいダンスをするのではなく、PowerShellからpsexecを実行するだけでいいですか? – Joey
@joey私はできると思います。 –