使用PowerShell将文件附加到Outlook

时间:2014-09-20 15:03:31

标签: powershell powershell-v2.0

目前我正在编写GUI Powershell脚本来运行PSR.exe,以便帮助台可以捕获用户问题,然后以最少的输入将输出通过电子邮件发送到帮助台。

我遇到的问题是附加使用环境变量生成的文件。如果我使用示例中所示的静态文件名,它可以工作,但是没有计算机名同时具有相同的主机名和用户。如何通过用于创建文件的两个变量附加文件?

#Directory storage
$DIR = "D:\Reports"

#Max number of recent screen captures
$MAX = "100"

#Captures Screen Shots from the recording
$SC = "1"

#Turn GUI mode on or off
$STR = "0"

#Caputres the current computer name
$PCName = "$ENV:COMPUTERNAME"

#Use either the local name or domain name
#$User = "$ENV:UserDomainName"
$User = "$ENV:UserName"

#Work in progress.
$File = "D:\Reports\LabComputer-Tester01.zip"

$buttonStart_Click={
    New-Item -ItemType directory -Path D:\Reports
    psr.exe /start /output $DIR\$PCName-$User.zip /maxsc $MAX /sc $SC /gui $STR
}

$buttonStop_Click={
        psr.exe /stop
}

$buttonEmail_Click={
    #TODO: Place custom script here
    $Outlook = New-Object -ComObject Outlook.Application
    $Mail = $Outlook.CreateItem(0)
    $Mail.To = "deaconf19@gmail.com"
    $Mail.Subject = "Capture Report"
    $Mail.Body = "Something in here"
    $Mail.Attachments.Add($File)
    $Mail.Send()
}

我将$File = "D:\Reports\LabComputer-Tester01.zip"更改为$File '\$DIR\\$PCName-$User.zip'我添加了单个刻度和另一个反斜杠到变量

1 个答案:

答案 0 :(得分:0)

我将$File = "D:\Reports\LabComputer-Tester01.zip"更改为$File '\$DIR\\$PCName-$User.zip'我添加了单个刻度和另一个反斜杠到变量