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
  • 相关阅读:
    spark 程序 TopN FileSort SecondarySort 的出错解决办法
    预报温度和体感温度不是一回事
    搜索引擎 搜索技巧
    scrapy 爬虫框架
    scala-sbt
    英语削笔机
    php 一句话木马
    [CS充实之路] CS50 WEEK 1
    UBUNTU 16.04 编译 OPENJDK8
    使用logrotate分割Tomcat的catalina日志
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/13960092.html
Copyright © 2011-2022 走看看