Powershell SendWait和变量

Powershell SendWait和变量,powershell,Powershell,我在IE自动化过程中发送密钥。首先按Ctrl+S(保存),然后我想将网页保存为名为variable$currentDate的MHT文件 [System.Windows.Forms.SendKeys]::SendWait('^{s}') Start-Sleep -m 500 [System.Windows.Forms.SendKeys]::SendWait('{$currentDate}') SendWait({}')中用法变量的正确格式是什么 我已经尝试了('{''$currentDate'}

我在IE自动化过程中发送密钥。首先按Ctrl+S(保存),然后我想将网页保存为名为variable
$currentDate
的MHT文件

[System.Windows.Forms.SendKeys]::SendWait('^{s}')
Start-Sleep -m 500
[System.Windows.Forms.SendKeys]::SendWait('{$currentDate}')
SendWait({}')
中用法变量的正确格式是什么

我已经尝试了
('{''$currentDate'}')
('{'$currentDate'}')

阅读并跟随文章:

将字符串括在双引号中时(a 双引号字符串),前面带有美元的变量名 符号(
$
)在输入字符串之前替换为变量的值 传递给命令进行处理

将字符串括在单引号中时(a 单引号字符串),字符串将完全按照 你打吧不执行替换

示例

$currentdate = (get-date).ToString('yyyyMMdd-HHmm')
$currentdate
"$currentdate"
'$currentdate'
[System.Windows.Forms.SendKeys]::SendWait("SendWait=$currentdate")
在打开的
Powershell
提示符中输出

PS D:\PShell>D:\PShell\SO\47649742.ps1
20171205-1454
20171205-1454
$currentdate
PS D:\PShell>SendWait=20171205-1454

为什么要使用发送键?使用Internet Explorer.Application对象中的另存为命令