在powershell中,我想学习将变量调用到起始作业的最佳方法,因此我不必编辑每个服务器的脚本,因为它将基于我放置脚本的客户端而具体.
$Servername = 'Server1'
$pingblock = {
pathping $servername | Out-File C:\client\PS\ServerPing.TXT
}
start-job $pingblock
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我只是得到一个帮助文件,好像我忘了指定$ servername.
我将一些字符串短时间值转换为24小时时间格式时遇到问题.
在脚本中,我有以下foreach循环来解析来自a的每一行数据csv:
Foreach ($Line in $Data) {
$command.CommandText=$SQLCommandPre+ `
"'"+$line."Reference" `
+"','"+$line."Date" `
+"','"$line."Business Hour".SubString(0,8) `
+"','"+"{0:f2}" -f ($line."Total"/2) `
+"','"+"{0:f0}" -f ($line."Number"/2) `
+"')"
[void] $command.ExecuteNonQuery()
}
Run Code Online (Sandbox Code Playgroud)
例如,我的源数据是:
0101,8/19/2012,12:00 AM - 12:59 AM,241.83,21
Run Code Online (Sandbox Code Playgroud)
目前在脚本中它只是抓住12点,但我需要转换为00:00.我尝试使用以下内容,但它对查询powershell创建没有任何影响:
"{0:HH:mm}" -f ($line."Business Hour".SubString(0,8))
Run Code Online (Sandbox Code Playgroud)
我一直无法找到另一种方法来达到我的目标.