我有動態信息(Report_ PC名稱-Date_User)生成的ZIP文件。但是,當我去附加文件時,我無法使用通配符。此目錄中只有一個ZIP文件,因此使用通配符將不會附加任何其他ZIP文件。Attachments.Add通配符使用PowerShell
#Directory storage
$DIR = "$ENV:TEMP"
#Max number of recent screen captures
$MAX = "100"
#Captures Screen Shots from the recording
$SC = "1"
#Turn GUI mode on or off
$GUI = "0"
#Caputres the current computer name
$PCName = "$ENV:COMPUTERNAME"
#Use either the local name or domain name
#$User = "$ENV:UserDomainName"
$User = "$ENV:UserName"
#Timestamp
$Date = Get-Date -UFormat %Y-%b-%d_%H%M
#Computer Information
$MAC = ipconfig /all | Select-String Physical
$IP = ipconfig /all | Select-String IPv4
$DNS = ipconfig /all | Select-String "DNS Servers"
#Needed to add space after user input information
$EMPT = "`n"
#Quick capture of the computer information
$Info = @"
$EMPT
*** COMPUTER INFORMATION ***
$PCName
$IP
$MAC
$DNS
"@
# Used to attach to the outlook program
$File = Get-ChildItem -Path $Dir -Filter "*.zip" | Select -Last 1 -ExpandProperty Fullname
$Start_Click = {
psr.exe /start /output $DIR\$Date-$PCName-$User.zip /maxsc $MAX /sc $SC /gui $GUI
}
$Stop_Click={
psr.exe /stop
}
$Email_Click = {
$Outlook = New-Object -Com Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.Subject = "Capture Report from " + $PCName + " " + $User + " " + $Date
$Mail.Body = $Problem.text + $Info
$Mail.Attachments.Add($File)
$Mail.Send()
}
我不再收到錯誤,但該文件不會第一次附加。第二次它會附加,但它不是最新的.zip。我將我的整個代碼
不知道您需要檢查文件是否存在並且可讀。也許需要時間來確定壓縮文件?在嘗試附加之前,使用'Test-Path'來查看zip是否存在。另外如果這仍然是一個問題,請考慮提出另一個問題,因爲我們已經解決了您當前的問題。誰會說你在解決這個問題之後不會有其他問題。 – Matt 2014-09-21 17:28:43