zoukankan      html  css  js  c++  java
  • PowerShell导入自定义公共函数

    编写公共函数,然后将其保存为D: empSend.psm1,脚本内容如下:

    Function SendMsg($touser,$data){
        $url='http://msg.xx.com/rmsg'
        $key = 'Mj111'   
        $secret = 'b3228'   
        $today = Get-Date -uformat "%YY-%M-%D"
        $snstr = "key=$key&content=$data&touser=$touser$secret"
        $md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
        $utf8 = New-Object -TypeName System.Text.UTF8Encoding
        $sn = [System.BitConverter]::ToString($md5.ComputeHash($utf8.GetBytes($snstr))).replace('-','').ToLower()
        #$textmod="key=$key&batch=1&content=$data&touser=$touser&sn=$sn"
        $textmod = @{key=$key;content=$data;touser=$touser;sn=$sn}
        Invoke-WebRequest -UseBasicParsing $url -Method POST -Body $textmod  |Out-Null
        #Invoke-WebRequest -UseBasicParsing $url -ContentType 'application/x-www-form-urlencoded;charset=UTF-8' -Method POST -Body $textmod  
    }

     注:该psm1脚本中可以包含多个函数,导入后都可以直接调用,可以通过get-module查看到

    在另外脚本中先导入psm1文件,然后即可调用SendMsg函数,如下:

    Import-Module D:	empSend.psm1
    Import-Module #可以看到导入的函数模块
    SendWechatMsg $touser $data
  • 相关阅读:
    CMake学习笔记
    右键添加"在此处打开命令窗口"菜单
    设置默认python模块源
    添加到附加组
    Unity宏处理
    挂载windows共享文件夹
    MacOS长按无效问题
    中文Locale
    笔记本用作无线路由器
    C# Winfrom iTextSharp 导出pdf 带二维码 表格嵌套 简单Dome
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/13960092.html
Copyright © 2011-2022 走看看