﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-nick's IT blog-随笔分类-Script</title><link>http://www.cnitblog.com/nicktang/category/8234.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 29 Sep 2011 03:44:57 GMT</lastBuildDate><pubDate>Thu, 29 Sep 2011 03:44:57 GMT</pubDate><ttl>60</ttl><item><title>updatehf.vbs:自动打补丁</title><link>http://www.cnitblog.com/nicktang/archive/2009/04/10/56199.html</link><dc:creator>nicktang</dc:creator><author>nicktang</author><pubDate>Fri, 10 Apr 2009 02:05:00 GMT</pubDate><guid>http://www.cnitblog.com/nicktang/archive/2009/04/10/56199.html</guid><wfw:comment>http://www.cnitblog.com/nicktang/comments/56199.html</wfw:comment><comments>http://www.cnitblog.com/nicktang/archive/2009/04/10/56199.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/nicktang/comments/commentRss/56199.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/nicktang/services/trackbacks/56199.html</trackback:ping><description><![CDATA[<div><a href="http://www.wsus.info/forums/index.php?showtopic=7298">[url]http://www.wsus.info/forums/index.php?showtopic=7298[/url]</a> <br>rob dunn写的一个，很早以前就使用了，可以进行补丁的检测，下载，安装等等，并且可以选择在安装完补丁后重启。 <br>本人使用上面的一些心得： <br>如果需要远程对多台计算机进行补丁安装，可以选择在远程建立计划任务的方法（at.exe或者使用wmi在远程建立计划任务）；如果仅是检测的话，则可以使用psexec.exe或者wmi远程建立进程，不支持补丁的安装。 <br>目前 Windows Update Agent (7.1.6001.65) + wsus3.0sp1下没有问题。</div>
<img src ="http://www.cnitblog.com/nicktang/aggbug/56199.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/nicktang/" target="_blank">nicktang</a> 2009-04-10 10:05 <a href="http://www.cnitblog.com/nicktang/archive/2009/04/10/56199.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sendmail Function</title><link>http://www.cnitblog.com/nicktang/archive/2009/04/09/56193.html</link><dc:creator>nicktang</dc:creator><author>nicktang</author><pubDate>Thu, 09 Apr 2009 13:24:00 GMT</pubDate><guid>http://www.cnitblog.com/nicktang/archive/2009/04/09/56193.html</guid><wfw:comment>http://www.cnitblog.com/nicktang/comments/56193.html</wfw:comment><comments>http://www.cnitblog.com/nicktang/archive/2009/04/09/56193.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/nicktang/comments/commentRss/56193.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/nicktang/services/trackbacks/56193.html</trackback:ping><description><![CDATA[<p><strong>Powershell:System.Net.Mail.MailMessage</strong></p>
<p>#mail server configuration <br>$smtpServer = "smtpServer" <br>$smtpUser = "smtpUser" <br>$smtpPassword = "smtpPassword " <br></p>
<p>#create the mail message <br>$mail = New-Object System.Net.Mail.MailMessage <br></p>
<p>#set the addresses <br>$MailAddress="MailAddress" <br>$MailtoAddress="MailtoAddress" <br>$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress) <br>$mail.To.Add($MailtoAddress) <br></p>
<p>#set the content <br>$mail.Subject = "Hello PowerShell"; <br>$mail.Priority&nbsp; = "High" <br>$mail.Body = "Sending mail is easy!" <br>$filename="file" <br>$attachment = new-Object System.Net.Mail.Attachment($filename) <br>$mail.Attachments.Add($attachment) <br></p>
<p>#send the message <br>$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer <br>$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword <br>$smtp.Send($mail)</p>
<p>为了防止密码以明文形式出现在脚本中，可以使用Get-Credential cmdlet</p>
<p>$cred = (Get-Credential domain\user).GetNetworkCredential()</p>
<p>$smtp.Credentials = $cred</p>
<p>支持SSL</p>
<p>$smtp.EnableSsl = $True</p>
<p>&nbsp;</p>
<p><strong>Powershell:CDO.Message</strong></p>
<p>$objMessage = new-object -com CDO.Message <br>$objMessage.From = "`"Krzysztof Pietrzak`" &lt;pkrzysz@nospam.pjwstk.edu.pl&gt;" <br>$objMessage.To = "pkrzysz@nospam.pjwstk.edu.pl" <br>$objMessage.Subject = " Message Subject" <br>$objMessage.TextBody = "Body of message" <br></p>
<p># Send using SMTP <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 <br>#SMTP Server <br>$objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.server.org" <br>#SMTP Server Port <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 <br>#Authenticaztion 1-Baasic, 2-NTLM <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2 <br>#Use ssl <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 0 <br>#Timeout <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 <br>$objMessage.Configuration.Fields.Update() <br>$objMessage.Send()</p>
<p><strong></strong>&nbsp;</p>
<p><strong>Powershell:CDO.Message带有身份验证和SSL/TLS</strong></p>
<p>$objMessage = new-object -com CDO.Message <br>$objMessage.From = "`"Krzysztof Pietrzak`" &lt;pkrzysz@nospam.pjwstk.edu.pl&gt;" <br>$objMessage.To = "pkrzysz@nospam.pjwstk.edu.pl" <br>$objMessage.Subject = " Message Subject" <br>$objMessage.TextBody = "Body of message" <br></p>
<p># Send using SMTP <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 <br>#SMTP Server <br>$objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "dfs2" <br>#SMTP Server Port <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 <br>#Authenticaztion 1-Baasic, 2-NTLM <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 <br>#UserID <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "yourUser" <br>#Password <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword" <br>#Use ssl <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 <br>#Timeout <br>$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 <br>$objMessage.Configuration.Fields.Update() <br>$objMessage.Send()</p>
<p><strong></strong>&nbsp; </p>
<p><strong>VBScript:CDO.Message</strong> </p>
<p>Set objMessage = CreateObject("CDO.Message") <br>objMessage.Subject = "Example CDO Message" <br>objMessage.From = "me@my.com" <br>objMessage.To = "test@paulsadowski.com" <br>objMessage.TextBody = "This is some sample message text." <br>objMessage.Send </p>
<p><strong></strong>&nbsp; </p>
<p><strong>VBScript:CDO.Message带有附件和邮件的HTML</strong> </p>
<p>'The line below shows how to send using HTML included directly in your script <br>objMessage.HTMLBody = "&lt;h1&gt;This is some sample message html.&lt;/h1&gt;" <br>'The line below shows how to send a webpage from a remote site <br>objMessage.CreateMHTMLBody "http://www.paulsadowski.com/wsh/" <br>'The line below shows how to send a webpage from a file on your machine <br>objMessage.CreateMHTMLBody "file://c|/temp/test.htm" <br>objMessage.Bcc = "you@your.com" <br>objMessage.Cc = &#8220;you2@your.com&#8221; </p>
<p><strong></strong>&nbsp; </p>
<p><strong>VBScript:CDO.MessageNTLM</strong> </p>
<p>Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. <br>Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). <br>Const cdoAnonymous = 0 'Do not authenticate <br>Const cdoBasic = 1 'basic (clear-text) authentication <br>Const cdoNTLM = 2 'NTLM <br></p>
<p>Set objMessage = CreateObject("CDO.Message") <br>objMessage.Subject = "Temat" <br>objMessage.From = """nadawca"" nadawca@domena.com" <br>objMessage.To = "odbiorca1@domena1.com" <br>objMessage.TextBody = "Serwer " <br></p>
<p>'==This section provides the configuration information for the remote SMTP server. <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 <br>'Name or IP of Remote SMTP Server <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpServer" <br>'Type of authentication, NONE, Basic (Base64 encoded), NTLM <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM <br>'Server port (typically 25) <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 <br>'Use SSL for the connection (False or True) <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False <br>'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 <br>objMessage.Configuration.Fields.Update</p>
<p>&nbsp; </p>
<p>'==End remote SMTP server configuration section== <br>objMessage.Send </p>
<p><strong></strong>&nbsp; </p>
<p><strong>VBScript:CDO.Message基本身份验证和SSL</strong> </p>
<p>Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. <br>Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). <br>Const cdoAnonymous = 0 'Do not authenticate <br>Const cdoBasic = 1 'basic (clear-text) authentication <br>Const cdoNTLM = 2 'NTLM</p>
<p><br>Set objMessage = CreateObject("CDO.Message") <br>objMessage.Subject = "Example CDO Message" <br>objMessage.From = """Me"" &lt;me@my.com&gt;" <br>objMessage.To = "test@paulsadowski.com" <br>objMessage.TextBody = "This is some sample message text.." &amp; vbCRLF &amp; "It was sent using SMTP authentication." <br></p>
<p>'==This section provides the configuration information for the remote SMTP server. <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 <br>'Name or IP of Remote SMTP Server <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com" <br>'Type of authentication, NONE, Basic (Base64 encoded), NTLM <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic <br>'Your UserID on the SMTP server <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid" <br>'Your password on the SMTP server <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword" <br>'Server port (typically 25) <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 <br>'Use SSL for the connection (False or True) <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = TRUE <br>'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) <br>objMessage.Configuration.Fields.Item _ <br>("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 <br>objMessage.Configuration.Fields.Update <br>'==End remote SMTP server configuration section== <br></p>
<p>objMessage.Send</p>
<p>&nbsp;</p>
<p><strong>VBScript:CDONTS，在2000下使用，XP和2003需注册相应dll，并安装SMTP服务，<font color=#ff0000>在Windows Server 2008上同样被支持，但是找不出不升级程序的理由，谁都不希望再去多装服务，麻烦不说，无形中还增加了一点安全风险，而且这种方法也不会被微软支持！</font><a title=http://www.jppinto.com/index.php/2009/03/install-cdonts-mail-component-and-smtp-on-windows-server-2008/ href="http://www.jppinto.com/index.php/2009/03/install-cdonts-mail-component-and-smtp-on-windows-server-2008/"><font color=#ff0000>http://www.jppinto.com/index.php/2009/03/install-cdonts-mail-component-and-smtp-on-windows-server-2008/</font></a></strong></p>
<p><a title=http://weblogs.asp.net/steveschofield/archive/2008/08/18/getting-cdonts-to-work-on-windows-server-2008-x64.aspx href="http://weblogs.asp.net/steveschofield/archive/2008/08/18/getting-cdonts-to-work-on-windows-server-2008-x64.aspx"><font color=#ff0000>http://weblogs.asp.net/steveschofield/archive/2008/08/18/getting-cdonts-to-work-on-windows-server-2008-x64.aspx</font></a></p>
<p>Dim strComputer, objNetwork <br>Set objNetwork = WScript.CreateObject("WScript.Network") <br>Set objMessage = CreateObject("CDONTS.NewMail") <br>set fs = CreateObject("Scripting.FileSystemObject") <br>set drive = fs.GetDrive("C:\") <br>strComputer = objNetwork.ComputerName <br>objMessage.Subject = "Daily report of C drive available space on&nbsp; " &amp; strComputer <br>objMessage.From = "icil_sup@icil.net" <br>objMessage.To = "allenzhang@icil.net,havingchan@icil.net" <br>strSpace = "Available Space on C:\:" &amp; FormatNumber(drive.AvailableSpace/1024^2) &amp; "MB" <br>objMessage.Body = Now &amp; vbtab &amp;&nbsp; strComputer &amp; vbtab &amp; strSpace <br>objMessage.Send</p>
<p>&nbsp;</p>
<p><strong>补充：Powershell:System.Web.Mail.MailMessage </strong><span style="COLOR: red">（利用CDOSYS消息组件发送电子邮件，.net 1.0和.net 1.1）</span></p>
<p>[System.Reflection.Assembly]::LoadWithPartialName("System.Web")
<p>$WebMailMessage = New-Object System.Web.Mail.MailMessage
<p>$WebMailMessage.From = 'powershell@powershell.com'
<p>$WebMailMessage.Subject = 'TEST'
<p>$WebMailMessage.To = 'someone@email.com'
<p>$WebMailMessage.Body = 'This is a test of System.Web.Mail.SMTPMail'
<p>$file="C:\test.txt"
<p>$attach=new-object system.web.mail.mailattachment($file)
<p>$webmailmessage.attachments.add($attach)
<p>[System.Web.Mail.SmtpMail]::smtpServer = 'smtp.server.com'
<p>[System.Web.Mail.SmtpMail]::send($WebMailMessage) </p>
<img src ="http://www.cnitblog.com/nicktang/aggbug/56193.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/nicktang/" target="_blank">nicktang</a> 2009-04-09 21:24 <a href="http://www.cnitblog.com/nicktang/archive/2009/04/09/56193.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>