获取日期
$now=get-date
$week=($now).DayOfWeek
$date=$now.ToString('yyyy-MM-dd HH:mm:ss.ff')
Write-Output "$date $week $env:userName $env:COMPUTERNAME"
# 结果:2022-02-21 15:09:46.23 Monday guoruilong IM20211010
更改控制台标题
$host.ui.RawUI.WindowTitle="重置AD账户密码"
生成气泡弹框
# 托盘位于System.Windows.Forms的程序集下,所以首先要首先加载dll
[system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
# 加载 Winform 程序集,会输出一些额外的信息,可以使用Out-Null抑制输出
[system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
#创建 NotifyIcon 对象
$balloon = New-Object System.Windows.Forms.NotifyIcon
$path = Get-Process -id $pid | Select-Object -ExpandProperty Path
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.Icon = $icon
$balloon.BalloonTipIcon = 'Info'
$balloon.BalloonTipText = 'IM30_VPN已创建完毕,请连接吧!'
$balloon.BalloonTipTitle = '温馨提示'
$balloon.Visible = $true
#显示气球提示框
$balloon.ShowBalloonTip(10000)
更改图标
# 默认显示的图标的是powershell的图标,可以选择更换图标
# 从进程列表中获取程序的某个图标
$path = Get-Process | where MainModule -ne $null | select -First 1 Path
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path.Path)
$balloon.Icon = $icon
$balloon.BalloonTipIcon = 'Info'
$balloon.BalloonTipText = '脚本执行完毕'
$balloon.BalloonTipTitle = 'PowerShell tips'
$balloon.Visible = $true
$balloon.ShowBalloonTip(10000)
# 自定义一个ico图标,指定路径即可
$path = "E:\DownLoad\browser\icon.ico"
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.Icon = $icon
$balloon.BalloonTipIcon = 'Info'
$balloon.BalloonTipText = '脚本执行完毕'
$balloon.BalloonTipTitle = 'PowerShell tips'
$balloon.Visible = $true
$balloon.ShowBalloonTip(10000)