首先感谢各位互联网大佬,今天在前期一些任务里头增加了企业微信通知功能和自助修改密码。

 https://developer.work.weixin.qq.com/devtool/query?e=48002#15074

Import-Module ActiveDirectory

function send-weixin {

Param(

       [Parameter(Mandatory = $True, Position = 1)]

       [String]$USERID,

       [Parameter(Mandatory = $True, Position = 2)]

       [String]$Content

     )

$auth_string = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=企微微信后台获取&corpsecret=企微微信后台获取自建应用"

$auth_values = Invoke-RestMethod $auth_string

$token = $auth_values.access_token

$body="{

`"touser`":`"$USERID`",

`"msgtype`":`"text`",

`"agentid`":`"1000018企业微信获取`",

`"text`":

{`"content`":`"$Content`"},

`"safe`":`"0`"

}"

$chinese=[System.Text.Encoding]::UTF8.GetBytes($body)  

Invoke-RestMethod "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token" -ContentType "application/json"  -Method Post  -Body $chinese

}


$alladuser=get-aduser -searchbase "DC=chinacpk你的域名,DC=com" -LDAPFilter '(!userAccountControl:1.2.840.113556.1.4.803:=2)' | %{$_.sAMAccountname}

$userlist = @()

foreach ($user in $alladuser){

$pwdlastset=Get-ADUser $user -Properties * | %{$_.passwordlastset}

$pwdlastday=($pwdlastset).AddDays(90)

$now=get-date

$neverexpire=get-aduser $user -Properties * |%{$_.PasswordNeverExpires}

$expire_days=($pwdlastday - $now).Days

if($expire_days -lt 7 -and $neverexpire -like "false" ){

  if($user -notlike " "){

   $chineseusername= Get-ADUser $user  -Properties * | %{$_.Displayname}

   $Contentbody=

"亲爱的 $chineseusername 同事 :

   您的Windows账户密码即将在 $expire_days 天后过期, 密码过期之后您将无法登陆电脑和文档加密等系统,请您尽快更改。

   Windows用户更改方式:

       按住Ctrl+Alt+Delete,选择更改密码即可!

   重置密码过程请遵循以下原则:

   ○密码长度最少 8 位;

   ○密码可使用最长时间 90天,过期需要更改密码;

   ○密码符合复杂性需求(大写字母、小写字母、数字和符号四种中必须有三种、且密码口令中不得包括全部或部分用户名)

   如有问题,请及时联系IT:0777-99999999

"

$tousers=Get-ADUser $user  -Properties * | %{$_.sAMAccountname}

send-weixin -$tousers -$Contentbody

}

}

}