$附件 = Get-ChildItem '/tmp/aaaa.tar.gz'
$HTML 邮件内容 =
@'
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>
<span style="font-family:Microsoft YaHei;font-size:18px;">html 信件内容</span>
</p>
</body>
</html>
'@
Send-MailMessage -Subject "主题" `
-From "你的 hotmail 账户 @
hotmail.com" -To "你的 qq 邮箱 @
qq.com" `
-SmtpServer "
smtp.live.com" -Port 587 -UseSsl -Credential "你的 hotmail 账户 @
hotmail.com" `
-Attachments $附件 -BodyAsHTML -body $HTML 邮件内容
上面的代码,保存成带有 bom 头的 a.ps1 文件,utf8 编码。
win 中用:
powershell.exe -file d:\你的目录\a.ps1
linux 中用:
/usr/bin/pwsh -file /你的目录 /a.ps1
------------------------------------------------------
centos7,centos8,安装 powershell:
curl -o /etc/yum.repos.d/microsoft.repo
https://packages.microsoft.com/config/rhel/7/prod.repo sudo yum remove -y powershell #删除旧版
sudo yum install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
ubuntu1604:
sudo curl
https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -o /etc/apt/sources.list.d/microsoft.list
https://packages.microsoft.com/config/ubuntu/16.04/prod.listsudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
ubuntu1804:
sudo curl
https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -o /etc/apt/sources.list.d/microsoft.list
https://packages.microsoft.com/config/ubuntu/18.04/prod.listsudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
debian9:Deepin 深度操作系统,当前版本,基于 debian9。
sudo apt-get update
sudo apt-get install curl gnupg apt-transport-https
curl
https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64]
https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
sudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '