2014-09-20 71 views
0

目前,我正在编写一个GUI Powershell脚本来运行PSR.exe,以便帮助台可以捕获用户问题,然后以最少的输入将输出发送到帮助台。使用PowerShell将文件附加到Outlook

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

#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 = "[email protected]" 
    $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'我增加了单蜱和另一个反斜杠到可变

+0

我必须失去一些东西。你为什么不设置$ file = $ DIR \ $ PCName- $ User.zip – 2014-09-20 16:05:54

+0

我试过了,并得到这个错误错误:在表达式或语句中意外的标记'\ $ PCName- $ User.zip'。 – JeremyA1 2014-09-20 18:22:00

+1

我解决了我的问题我没有正确地转义反斜杠 – JeremyA1 2014-09-20 19:15:34

回答

0

我改变$File = "D:\Reports\LabComputer-Tester01.zip"$File '\$DIR\\$PCName-$User.zip'我增加了单蜱和另一个反斜杠到可变

相关问题