首页 > 解决方案 > 传递加密凭据以在 PowerShell 中运行批处理命令

问题描述

下面是获取 Networker 每日状态报告的 PowerShell 脚本。

这里密码以纯文本形式给出,并在批处理命令中传递相同的密码。

######## Define variables
$ver="0.1"
$date = Get-Date -Format D  

####### customer info
$cust="FOO"
$site="Chicago"
$nwsvr="CHNetworker1"

#####nmc crdentials
$user="administrator"
$pwd="foobar11"

######## where to store report files
$reportstore="\\10.10.216.9\chdd4200_bkup_infra\NW_Bkup_Reports\"

####### note: JAVA_HOME must be set in gstclreport.bat script

$gstclrpt="D:\EMC NetWorker\Management\GST\bin\gstclreport.bat"
$rptformat="csv"
$now =  get-date -uformat "%Y-%m-%d_%H-%M-%S"
$rpt="/Reports/NetWorker Backup Status/Group Summary by Client and Server"
$rpttmp="rpttmp"

开始报告脚本

######## Run batch file to generate csv report
try
{
& $gstclrpt -u $user -P $pwd -r `"$rpt`" -x $rptformat -o landscape -f `"$reportstore$rpttmp`" -C `"Group Start Time`" `"1 day ago`" -C `"Server Name`" $nwsvr
}

catch [system.exception]
{
"caught a system exception"
}

如何将用户名和密码作为输入提示传递,并且应该采用加密形式。此外,如何在批处理参数中传递凭据(下面突出显示),以便出于安全目的不会将其存储在 shell 中。

标签: powershellbatch-filecredentialspassword-encryption

解决方案


推荐阅读