随笔 - 24, 文章 - 0, 评论 - 1, 引用 - 0
数据加载中……

updatehf.vbs:自动打补丁

[url]http://www.wsus.info/forums/index.php?showtopic=7298[/url]
rob dunn写的一个,很早以前就使用了,可以进行补丁的检测,下载,安装等等,并且可以选择在安装完补丁后重启。
本人使用上面的一些心得:
如果需要远程对多台计算机进行补丁安装,可以选择在远程建立计划任务的方法(at.exe或者使用wmi在远程建立计划任务);如果仅是检测的话,则可以使用psexec.exe或者wmi远程建立进程,不支持补丁的安装。
目前 Windows Update Agent (7.1.6001.65) + wsus3.0sp1下没有问题。

posted @ 2009-04-10 10:05 nicktang 阅读(235) | 评论 (0)编辑 收藏

Searching the Active Directory with PowerShell

 

function get-dn ($SAMName) 



$root 
= [ADSI]'

$searcher 
= new-object System.DirectoryServices.DirectorySearcher($root) 

$searcher.filter 
= "(&(objectClass=user)(sAMAccountName= $SAMName))" 

$user 
= $searcher.findall() 

if ($user.count -gt 1



$count 
= 0 

foreach($i 
in $user) 



write-host $count "" $i.path 

$count 
= $count + 1 



$selection 
= Read-Host "Please select item: " 

return $user[$selection].path 



else 



return $user[0].path 





$Name 
= $args[0

$path 
= get-dn $Name 

"'" + $path + "'" 


举例:

PS C:\store\ps scripts> .\get-dn.ps1 administrator 

'LDAP://CN=Administrator,CN=Users,DC=umpadom,DC=com' 

 

摘自:http://blogs.technet.com/benp/archive/2007/03/26/searching-the-active-directory-with-powershell.aspx

posted @ 2009-04-10 09:59 nicktang 阅读(243) | 评论 (0)编辑 收藏

System.Net.Mail with SSL to authenticate against port 465

Sending mail using System.Net.Mail with SSL will fail:

System.Net.NetworkCredential aCred = new System.Net.NetworkCredential("myacct", "mypassword");

SmtpClient smtp = new SmtpClient("smtp.mail.myserver.com", 465);

smtp.EnableSsl = true;

smtp.UseDefaultCredentials = false;

smtp.Credentials = aCred;

System.Net.Mail only supports “Explicit SSL”. 

Explicit SSL

System.Net.Mail only supports “Explicit SSL”.  Explicit SSL starts as unencrypted on port 25, then issues a STARTDLS and switches to an Encrypted connection.  See RFC 2228.

Explicit  SLL would go something like: Connect on 25 -> StartTLS (starts to encrypt) -> authenticate -> send data

If the SMTP server expects SSL/TLS connection right from the start then this will not work.

Implicit SSL

There is no way to use Implicit SSL (SMTPS) with System.Net.Mail.  Implicit SSL would have the entire connection is wrapped in an SSL layer.  A specific port would be used (port 465 is common).  There is no formal RFC covering Implicit SSL.

Implicit  SLL would go something like: Start SSL (start encryption) -> Connect -> Authenticate -> send data

This is not considered a bug, it’s a feature request. There are two types of SSL authentication for SMTP, and we only support one (by design) – Explicit SSL.

 

转自Dan's WebDAV 101

posted @ 2009-04-09 21:34 nicktang 阅读(338) | 评论 (0)编辑 收藏

Sendmail Function

Powershell:System.Net.Mail.MailMessage

#mail server configuration
$smtpServer = "smtpServer"
$smtpUser = "smtpUser"
$smtpPassword = "smtpPassword "

#create the mail message
$mail = New-Object System.Net.Mail.MailMessage

#set the addresses
$MailAddress="MailAddress"
$MailtoAddress="MailtoAddress"
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress)

#set the content
$mail.Subject = "Hello PowerShell";
$mail.Priority  = "High"
$mail.Body = "Sending mail is easy!"
$filename="file"
$attachment = new-Object System.Net.Mail.Attachment($filename)
$mail.Attachments.Add($attachment)

#send the message
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$smtp.Send($mail)

为了防止密码以明文形式出现在脚本中,可以使用Get-Credential cmdlet

$cred = (Get-Credential domain\user).GetNetworkCredential()

$smtp.Credentials = $cred

支持SSL

$smtp.EnableSsl = $True

 

Powershell:CDO.Message

$objMessage = new-object -com CDO.Message
$objMessage.From = "`"Krzysztof Pietrzak`" <pkrzysz@nospam.pjwstk.edu.pl>"
$objMessage.To = "pkrzysz@nospam.pjwstk.edu.pl"
$objMessage.Subject = " Message Subject"
$objMessage.TextBody = "Body of message"

# Send using SMTP
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
#SMTP Server
$objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.server.org"
#SMTP Server Port
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
#Authenticaztion 1-Baasic, 2-NTLM
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2
#Use ssl
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 0
#Timeout
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
$objMessage.Configuration.Fields.Update()
$objMessage.Send()

 

Powershell:CDO.Message带有身份验证和SSL/TLS

$objMessage = new-object -com CDO.Message
$objMessage.From = "`"Krzysztof Pietrzak`" <pkrzysz@nospam.pjwstk.edu.pl>"
$objMessage.To = "pkrzysz@nospam.pjwstk.edu.pl"
$objMessage.Subject = " Message Subject"
$objMessage.TextBody = "Body of message"

# Send using SMTP
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
#SMTP Server
$objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "dfs2"
#SMTP Server Port
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
#Authenticaztion 1-Baasic, 2-NTLM
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
#UserID
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "yourUser"
#Password
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
#Use ssl
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
#Timeout
$objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
$objMessage.Configuration.Fields.Update()
$objMessage.Send()

 

VBScript:CDO.Message

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me@my.com"
objMessage.To = "test@paulsadowski.com"
objMessage.TextBody = "This is some sample message text."
objMessage.Send

 

VBScript:CDO.Message带有附件和邮件的HTML

'The line below shows how to send using HTML included directly in your script
objMessage.HTMLBody = "<h1>This is some sample message html.</h1>"
'The line below shows how to send a webpage from a remote site
objMessage.CreateMHTMLBody "http://www.paulsadowski.com/wsh/"
'The line below shows how to send a webpage from a file on your machine
objMessage.CreateMHTMLBody "file://c|/temp/test.htm"
objMessage.Bcc = "you@your.com"
objMessage.Cc = “you2@your.com”

 

VBScript:CDO.MessageNTLM

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Temat"
objMessage.From = """nadawca"" nadawca@domena.com"
objMessage.To = "odbiorca1@domena1.com"
objMessage.TextBody = "Serwer "

'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpServer"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update

 

'==End remote SMTP server configuration section==
objMessage.Send

 

VBScript:CDO.Message基本身份验证和SSL

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM


Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = """Me"" <me@my.com>"
objMessage.To = "test@paulsadowski.com"
objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."

'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = TRUE
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==

objMessage.Send

 

VBScript:CDONTS,在2000下使用,XP和2003需注册相应dll,并安装SMTP服务,在Windows Server 2008上同样被支持,但是找不出不升级程序的理由,谁都不希望再去多装服务,麻烦不说,无形中还增加了一点安全风险,而且这种方法也不会被微软支持!http://www.jppinto.com/index.php/2009/03/install-cdonts-mail-component-and-smtp-on-windows-server-2008/

http://weblogs.asp.net/steveschofield/archive/2008/08/18/getting-cdonts-to-work-on-windows-server-2008-x64.aspx

Dim strComputer, objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objMessage = CreateObject("CDONTS.NewMail")
set fs = CreateObject("Scripting.FileSystemObject")
set drive = fs.GetDrive("C:\")
strComputer = objNetwork.ComputerName
objMessage.Subject = "Daily report of C drive available space on  " & strComputer
objMessage.From = "icil_sup@icil.net"
objMessage.To = "allenzhang@icil.net,havingchan@icil.net"
strSpace = "Available Space on C:\:" & FormatNumber(drive.AvailableSpace/1024^2) & "MB"
objMessage.Body = Now & vbtab &  strComputer & vbtab & strSpace
objMessage.Send

 

补充:Powershell:System.Web.Mail.MailMessage (利用CDOSYS消息组件发送电子邮件,.net 1.0和.net 1.1)

[System.Reflection.Assembly]::LoadWithPartialName("System.Web")

$WebMailMessage = New-Object System.Web.Mail.MailMessage

$WebMailMessage.From = 'powershell@powershell.com'

$WebMailMessage.Subject = 'TEST'

$WebMailMessage.To = 'someone@email.com'

$WebMailMessage.Body = 'This is a test of System.Web.Mail.SMTPMail'

$file="C:\test.txt"

$attach=new-object system.web.mail.mailattachment($file)

$webmailmessage.attachments.add($attach)

[System.Web.Mail.SmtpMail]::smtpServer = 'smtp.server.com'

[System.Web.Mail.SmtpMail]::send($WebMailMessage)

posted @ 2009-04-09 21:24 nicktang 阅读(633) | 评论 (1)编辑 收藏

仅列出标题
共3页: 1 2 3