powershell - 传递加密凭据以在 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 中。
解决方案
推荐阅读
- java - 如何在 Java 中隐藏来自控制台的不必要的 Selenium 调试消息
- python - 错误列表索引超出范围。问题是关于删除列表中的相同元素,以便列表中仅保留唯一元素
- c++ - 如何以体面的方式实现交互式旋转操作
- javascript - 获取动态年份范围并在选择列表中附加选项
- java - Spring Boot 2.3 中不打印自定义异常的 Stacktrace
- python - 如何遍历图形并返回最小路径?
- oracle - Oracle Apex - 隐藏静态内容区域
- sql - 从具有多个数字的消息中识别特定数字
- sql - SSRS 查询参数无法正常工作
- pthreads - pthread_attr_t 默认属性 - 官方文档