Sqler 工具 CMd 更新
新加入 CMD 功能
1 多线程远程创建文件夹
2 多线程远程操作服务
3 多线程远程 操作windows账户
4 多线程远程机器 加域、删域
5 多线程远程添加 防火墙端口
加域模块
1 #region JoinDomain 2 WorkFlow WFSqlerCmdJoinDomain 3 { 4 param([array] $servers,[string] $Domain 5 ,[string] $WmiAccount,[string] $WmiPassWord 6 ,[array] $dns 7 ,[string]$Logfile ='E:\Monitor\SqlerCmdLog') 8 foreach -parallel($server in $servers) 9 { 10 inlinescript 11 { 12 try 13 { 14 $date=get-date 15 $PWD= ConvertTo-SecureString $using:WmiPassWord -AsPlainText -Force 16 $psc = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $using:WmiAccount,$PWD -ErrorAction Stop 17 $dpsc = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$Using:Domain\$using:WmiAccount",$PWD -ErrorAction Stop; 18 ##Set DNS 19 $IP=Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $using:server -Credential $psc -ErrorAction Stop ` 20 | Where{$_.IPEnabled -eq "TRUE" -and $_.ipaddress -eq $using:server} 21 $Return=$IP.SetDNSServerSearchOrder( $Using:Dns); 22 Add-Computer -ComputerName $using:server -Credential $dpsc -DomainName $using:domain -LocalCredential $psc -Restart -Force -ErrorAction stop 23 "Succeed $using:server Begin:$date Server:$using:Server is join $using:Domain----"|out-file -FilePath "$using:Logfile\SqlerCmdJoinDomainSucceed_$using:server.log" -Append 24 } 25 catch 26 { 27 $date=get-date 28 "Failed '$using:server' error info : "+$_.Exception.Message|out-file -FilePath "$using:Logfile\SqlerCmdJoinDomainFailed_$using:server.log" -Append 29 } 30 } 31 } 32 inlinescript 33 { 34 if((Test-Path -Path "$Using:Logfile\SqlerCmdJoinDomainFailed.log" )){Remove-Item -Path "$Using:Logfile\SqlerCmdJoinDomainFailed.log" } 35 if((Test-Path -Path "$Using:Logfile\SqlerCmdJoinDomainSucceed.log" )){Remove-Item -Path "$Using:Logfile\SqlerCmdJoinDomainSucceed.log" } 36 Get-ChildItem -path $using:Logfile -recurse -include "*.log"| where {$_.Name -match 'SqlerCmdJoinDomain' -and $_.Name -match '_' } ` 37 |ForEach-Object{ if($_ -match 'Failed'){Get-Content $_ |out-file -FilePath "$Using:Logfile\SqlerCmdJoinDomainFailed.log" -Append;Remove-Item -path $_ } Else{Get-Content $_ |out-file -FilePath "$Using:Logfile\SqlerCmdJoinDomainSucceed.log" -Append;Remove-Item -path $_ }} 38 } 39 } 40 41 #endregion
42 WFSqlerCmdJoinDomain $servers $domain $WmiAccount $WmiPassWord $dns
因牵涉到信息安全,部分信息作了处理
PS C:\Users\Administrator> cat E:\Monitor\SqlerCmdLog\SqlerCmdJoinDomainSucceed.log
Succeed 192.168.xx.xxx Begin:04/02/2013 11:50:22 Server:192.168.xx.xxx is join xxdb----
Succeed 192.168.xx.xxx Begin:04/02/2013 11:50:22 Server:192.168.xx.xx is join xxdb----
PS C:\Users\Administrator>
练一技,修百艺,而成于自然.
分类: Tool:Sqler