2014-09-20 73 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'我增加了單蜱和另一個反斜槓到可變

相關問題