2012-12-09

Adfind

http://www.joeware.net/freetools/tools/adfind/index.htm


adfind –b <Search Base> -s <Search Scope> -f <Search Filter> attributesDesired

1.所以對域中所有計算機對象的DN 和說明的查詢應為:
adfind –b dc=contoso,dc=com –s subtree –f (objectcla​​ss=computer) dn description

2.對所有用戶對象的查詢如下所示:
adfind –b dc=contoso,dc=com –s subtree –f "(&(objectcategory=person) (objectcla​​ss=user))" dn description

Forfiles


http://technet.microsoft.com/en-us/library/cc753551(WS.10).aspx
Syntax

forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d[{+ | -}] [{MM/DD/YYYY | DD}]]

Parameters

/p Path
指定您要在其上開始搜尋的 Path。預設資料夾為目前的工作目錄,您可以透過輸入句點 (.) 來指定。
/m SearchMask
依據 SearchMask 來搜尋檔案。預設的 SearchMask 為 *.*。
/s
指示 forfiles 在子目錄中搜尋。
/c Command
在每個檔案上執行指定的 Command。您必須將帶有空格的命令字串包含在引號中。預設的 Command 為 "cmd /c echo @file"。
/d[{+ | -}] [{MM/DD/YYYY | DD}]
選取日期大於等於 (+) 或小於等於 (-) 指定日期的檔案,其中 MM/DD/YYYY 是指定的日期,而 DD 是目前日期減去 DD 天。如果您未指定 + 或 -,則會使用 +。DD 的有效範圍為 0 - 32768。
/?
在命令提示字元上顯示說明。
Remarks

Forfiles 最常使用於批次檔案中。

Forfiles /s 與 dir /s 類似。
下列表格列出了您可以在 /cCommand 命令字串中使用的變數。

變數 描述
@file 檔案名稱

@fname 不含副檔名的檔案名稱

@ext 副檔名

@path 檔案的完整路徑

@relpath 檔案的相對路徑

@isdir 如果檔案類型是目錄,則判斷值是 TRUE,否則判斷值是 FALSE。

@fsize 檔案大小 (以位元組為單位)

@fdate 檔案上的上次修改日期戳記

@ftime 檔案上的上次修改時間戳記

使用 forfiles,您可以在多個檔案上執行命令,或將引數傳送到多個檔案。例如,您可以在樹狀目錄中帶有 *.txt 副檔名的所有檔案上執行 TYPE 命令。或者,您可以執行 C: 磁碟機上的每個批次檔案 (*.bat),以檔案名稱 Myinput.txt 作為第一個引數。

使用 forfiles,您可以執行下列任何一項動作:

使用 /d 按絕對或相對日期選取檔案。

使用變數,例如 @fsize (檔案大小) 及 @fdate (檔案日期),來建立檔案的保存樹狀目錄。

使用 @isdir 變數以從目錄中區分檔案。

藉由在命令列中包含特殊字元,及使用十六進位字碼 0xHH 包圍字元,來格式化輸出。

Forfiles 藉由執行工具 (設計用於僅處理單一檔案)上的 recurse subdirectories 旗標來運作。

Examples

若要列出 C: 磁碟機上的所有批次檔案,請輸入:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

若要列出 C: 磁碟機上的所有目錄,請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

若要列出 C: 磁碟機上 100 天之前的所有檔案,請輸入:

forfiles /p c:\ /s /m *.* /dt-100 /c "cmd /c echo @file :date >= 100 days"

若要列出 C: 磁碟機上 1993 年 1 月 1 日之前的所有檔案,再為這些檔案顯示 "file is quite old!",請輸入:

forfiles /p c:\ /s /m *.* /dt-01011993 /c "cmd /c echo @file is quite old!"

若要列出 C: 磁碟機上所有檔案的所有副檔名(按欄位格式),請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c echo extension of @file is 0x09@ext0x09" With:

若要列出 C: 磁碟機上的所有批次檔案,請輸入:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

若要列出 C: 磁碟機上的所有目錄,請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

若要列出 C: 磁碟機上 100 天之前的所有檔案,請輸入:

forfiles /p c:\ /s /m *.* /d t-100 /c "cmd /c echo @file :date >= 100 days"

若要列出 C: 磁碟機上 1993 年 1 月 1 日之前的所有檔案,再為這些檔案顯示 "file is quite old!",請輸入:

forfiles /p c:\ /s /m *.* /d t-01011993 /c "cmd /c echo @file is quite old!"

若要列出 C: 磁碟機上所有檔案的所有副檔名(按欄位格式),請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c echo extension of @file is 0x09@ext0x09"


#刪除超過7天,位於 c:\windows\Temp 路徑中檔名 sess開頭的檔案
forfiles /P c:\Windows\Temp /M sess_* /S /D -7 /C "cmd /c del /F @path"

2012-11-17

2012-10-13

MRBS -- LDAP

mrbs 1.4.8 on OB2D with "apt-get install php5-ldap"

check ldap log
/var/log/apache2/error.log

systemdefaults.inc.php

$auth["type"] = "ldap";
$ldap_host = "server.abc.com";
$ldap_port = 389;
$ldap_v3 = false;
$ldap_tls = false;
$ldap_base_dn = "c=uers,DC=abc,DC=com";
$ldap_user_attrib = "uid";
$ldap_dn_search_attrib = "sAMAccountName";
$ldap_dn_search_dn = "CN=user,cn=users,DC=abc,DC=com";
$ldap_dn_search_password = "xxxxxx";

$ldap_disable_referrals = TRUE;
$ldap_get_user_email = FALSE;
$ldap_email_attrib = "mail";
//$ldap_unbind_between_attempts = TRUE;
$ldap_debug = TRUE;

//$ldap_filter = "memberof=cn=MRBSUsers,ou=MRBS,ou=Groups,dc=ufv,dc=ca";
//$ldap_admin_group_dn = "cn=MRBSAdmins,ou=MRBS,ou=Groups,dc=ufv,dc=ca";
//$ldap_group_member_attrib = "memberof";


auth_ldap.inc



// Turn any non-array config items into arrays in $all_ldap_opts
+  if (!isset($count))
+  {
+    $count = 1;
+  }
foreach ($config_items as $item)
{
if (!isset($$item))

Windows How to Finding non present devices

1. Open Command shell
2. type "set devmgr_show_nonpresent_devices=1"
3. type "start devmgmt.msc"
4. Select "Show hidden devices"

2012-09-30

Ubuntu -- Learning

@How to configure network setting to use static IP address
sudo vi /etc/network/interfaces


 1 auto lo
 2 iface lo inet loopback
 3
 4 auto eth0
 5 iface eth0 inet static
 6 address 192.168.0.1 # 固定 IP 位址
 7 netmask 255.255.255.0   # 網路遮罩
 8 gateway 192.168.0.254 # 預設閘道

 sudo /etc/init.d/networking restart #重啓網路服務

@How to configure DNS server setting
sudo vim /etc/resolv.conf


 1# DNS of Google
 2#nameserver  8.8.4.4
 3#nameserver  8.8.8.8
 4
 5# DNS of HiNet
 6#nameserver  168.95.1.1
 7#nameserver  168.95.192.1

sudo /etc/init.d/networking restart #重啓網路服務

@How to install LAMP
sudo apt-get install tasksel
sudo  tasksel

#select LAMP to install
$sudo vi /var/www/info.php #to vi info.php

<?php
phpinfo();
?>
$sudo /etc/init.d/apache2 restart  #to restart Apache service
Visit http://192.168.0.1/info.php

@How to install phpmyadmin
sudo  apt-get  install  phpmyadmin

http://ip/phpmyadmin #to test


Linux -- 檔案系統樹狀標準


  • 根目錄 (/):為整個檔案系統樹狀結構的根,也就是整個檔案系統的根目錄。
  • /bin: 此目錄中存放著許多的 Binary 執行檔案,為一般及啟動時常常會使用到的檔案,例如 ls、cp、rm ...等指令。
  • /sbin:此目錄中存放著許多的 System Binary 執行檔案,為系統管理時常常會使用到的檔案,例如 shutdown、fsck、quotacheck...等指令。
  • /etc:此為 Linux 系統中相當重要得目錄,大部份的設定檔都存放於此,例如檔案系統掛載設定檔 /etc/fstab、IPTables 防火牆設定檔 /etc/sysconfig/iptables...等。
  • /lib:存放 Linux 系統中各種共用的 Library 函式庫檔案,類似於 Windows 作業系統的 DLL 動態連結函式庫一樣的功能。
  • /dev:Linux 系統是以 Everything is Files 的觀念來進行管理 Device 硬體裝置,因此硬體設備及週邊設備也不例外,此目錄中存放著所偵測到的相關硬體檔案,例如 光碟機為 /dev/cdrom、SCSI 硬碟為 /dev/sda...等,為相容舊版系統而存在。
  • /sys:存放 System-Device 相關資訊 (由 RHEL 4 開始才有此資料夾),如 PnP...等,會將偵測到的 Device 資訊回寫至 /dev 對應的檔案內以相容舊版,所以舉例來說當主機插入 USB 隨身碟時會同時建立 /sys/block/sdb 以及回寫至 /dev/sdb 內。
  • /selinux:存放 Linux 增強安全性機制 SELinux (Security Enhanced Linux) 相關檔案。
  • /var 具備 Variable 也就是變動特性的檔案將存放於此,例如 系統的各式日誌檔案 /var/log、使用者電子信箱 /var/mail、正在執行的執行序 /var/run/*.pid ...等。
  • /srv:存放相關的 Server-data。(由 RHEL 4 開始才有此資料夾)
  • /usr:Linux 系統中大部份的 安裝套件及相關應用程序 都存放於此,例如其它網路服務的執行程序 /usr/sbin、核心原始碼檔案 /usr/src...等,類似於 Windows 作業系統的Program Files 資料夾。
  • /opt:Optional 通常非預設安裝的套件會安裝於此,例如 Oracle 資料庫...等。
  • /lost+found: 在每個獨立的掛載點內都會有此資料夾,當 Linux 系統不正常關機時相關資料便會暫存於此。
  • /mnt: 用於 臨時掛載的目錄,通常會手動執行將外接設備掛載於此。(Kernel 2.4.x 使用)
  • /media: 若 RunLevel 為 5 也就是進入圖形介面時 (由 RHEL 4 開始才有此資料夾),若主機有插入 USB 或其它外接設備時則會自動掛載於此目錄上 (不需手動掛載)。(Kernel 2.6.x 使用)
  • /misc、/net: 用於 autofs 自動掛載時所使用的資料夾,例如 Linux 主機成為 LDAP、NIS Client 時便會將相關資料夾自動掛載於此,類似於 Windwos 作業系統中網路芳鄰的概念。
  • /tmp: 暫存資料夾,存放暫時性的資料夾及檔案,通常 Linux 系統重新啟動或關機以及排程會自動清空此資料夾內容。
  • /proc: Linux 系統中目前所執行的 執行序 Process 即存放於此資料夾,當該執行序停止執行則位於此資料夾中的 Process ID 或檔案將消失 (事實上此資料夾就是 Memory 中的暫存資料),至於有些檔案的大小為何是 0? 例如 meminfo、cpuinfo 則只是為了要達成 Everything is Files 的觀念而以,但仍可查看及檔案內容。
  • /boot: 存放 Linux 系統開機時相關引導檔案,例如 Boot Loader 設定檔 /boot/grub/grub.conf、初始化映像檔 .img...等。
  • /home: 所有 一般使用者帳號的家目錄,例如 使用者帳號 weithenn 的家目錄為 /home/weithenn。
  • /root: Linux 系統超級管理者的家目錄。

CentOS -- Learning

&configure NIC&
#su
#Enter password for root
#service NetworkManager stop
#chkconfig NetworkManager off
#chkconfig NetworkManager --list
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"

NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Ethernet
IPADDR=x.x.x.x
NETMASK=255.255.255.0
GATEWAY=x.x.x.x
DNS1=8.8.8.8
DEFROUTE=yes
#service network restart

&system update&
#yum update --skip-broken

&Disable SELinux&
#getenforce
Enforcing
#vi /etc/selinux/config
SELINUX=disabled
#reboot
#getenforce
Disabled

Connecting to the Console Port with Mac OS X


Connecting to the Console Port with Mac OS X

This procedure describes how to connect a Mac OS X system USB port to the console using the built-in OS X Terminal utility.

Step 1 Use the Finder to go to Applications > Utilities > Terminal.

Step 2 Connect the OS X USB port to the router.

Step 3 Enter the following commands to find the OS X USB port number:

macbook:user$ cd /dev
macbook:user$ ls -ltr /dev/*usb*
crw-rw-rw-  1 root    wheel       9,  66 Apr  1 16:46 tty.usbmodem1a21
DT-macbook:dev user$

Step 4 Connect to the USB port with the following command followed by the router USB port speed:

macbook:user$ screen /dev/tty.usbmodem1a21 9600
To Disconnect the OS X USB Console from the Terminal Window

Enter Ctrl+A followed by Ctrl+\

2012-09-29

MRBS -- the steps of installation

@安裝
tar zxvf mrbs-1.4.6.tar.gz
cd mrbs-1.4.6
cp -r web /var/www/mrbs
配置timezone。找到config.inc.php文件。去掉$timezone = "XXXXXXX"的註釋,並修改成$timezone = "Asia/Taipei"。
配置數據庫。還是config.inc.php文件。修改以下參數,分別對應數據庫類型、主機、數據庫實例、用戶名、密碼、表前綴。例如:
$dbsys = "mysql";
$db_host = "localhost";
$db_database = "mrbs";
$db_login = "root";
$db_password = 'xxxxxxxx';
$db_tbl_prefix = "mrbs_";
配置用戶授權類型。
在config.inc.php文件的尾部添加$auth["type"]="db";

@配置mysql數據庫
mysql -uroot -p111111
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql>CREATE DATABASE `mrbs` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
退出數據庫,返回到mrbs-1.4.6目錄
mysql -uroot -p111111 mrbs < tables.my.sql
mysql -uroot -p111111 mrbs < sample-data.sql
全部部署完畢。

@LDAP的部分,於config.inc.php內增加
$auth["type"] = "ldap";
$ldap_host = "LDAP的IP位址";
$ldap_port = 389;
$ldap_v3 = true;
$ldap_tls = false;
$ldap_base_dn = "DC=abc,DC=com";
$ldap_user_attrib = "sAMAccountName";
$ldap_dn_search_attrib = "sAMAccountName";
$ldap_dn_search_dn = "CN=adminaccount,CN=Users,DC=abc,DC=com";需使用正確的adminaccount帳號的LDAP distinguishedName
$ldap_dn_search_password = "adminpassword";查詢LDAP的adminaccount密碼不能包含$#@等字眼
@訪問http://localhost/mrbs

2012-09-22

VMware vSphere 5.1

http://www.vmware.com/files/pdf/products/vsphere/vmware-what-is-new-vsphere51.pdf

OB2D -- Learning (1) -- Installation

OB2D
http://www.phcno1.net/modules/tad_book3/page.php?tbdsn=292

How to use Virtualbox to build a ob2d server.
http://myip.tw/itsmw/index.php?title=Ob2d_2010

1. Download and install Oracle Virtualbox.
2. Settings for ob2d:
    OS:Linux
    Version:bebian
    RAM: 800MB
    HD:10GB

2012-09-15

Powershell -- 1st experience


#Set-ExecutionPolicy RemoteSigned
# VMware vSphere PowerCLI
if (((Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapinregistered -Name "VMware.VimAutomation.Core") -ne $null))
{
   Write-Host "Adding VMware vSphere PowerCLI" -ForegroundColor Green
   Add-PSSnapin -name VMware.VimAutomation.Core
   ."C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
}
$vmmodule = Get-PSSnapin -Name "VMware.VimAutomation.Core"
if (!$vmmodule) {
    [System.Reflection.Assembly]::LoadwithPartialName("System.windows.Forms")
    [System.windows.Forms.MessageBox]::Show("We dont got the VM powerCLI module.")
    exit
} else {
    echo "Module $vmmodule loaded successfully"
}
# SSH-Sessions Module load
$sshmodule = Get-Module -List 'SSH-Sessions'
if (!$sshmodule) {
    [System.Reflection.Assembly]::LoadwithPartialName("System.windows.Forms")
    [System.windows.Forms.MessageBox]::Show("We dont got the SSh-Sessions module.")
    exit
} else {
    Import-Module SSH-Sessions
    echo "Module $sshmodule loaded successfully"
}
#Connect to Vcenter
$Viserver = Connect-VIServer -Server 'IP' -User 'username' -Password 'password'
If (!$viserver) {
   [System.Reflection.Assembly]::LoadwithPartialName("System.windows.Forms")
   [System.windows.Forms.MessageBox]::Show("We dont connect to FTvcenter01.")
   exit
} else {
    echo "Connect to vcenter success"
}
Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Where-Object {$_.Name -ne "vcenter"} | Shutdown-VMGuest -Confirm:$false
Start-
#Get-VM
#Start-Sleep -s 600
#Get-VMHost | Stop-VMHost -Confirm:$false
#Get-VMHost
#Start-Sleep -s 300
#SSH to NetApp
$naserver = New-SshSession -ComputerName 'IP for 1st','IP for 2nd' -Username 'username' -Password 'password'
If (!$naserver) {
    [System.Reflection.Assembly]::LoadwithPartialName("System.windows.Forms")
    [System.windows.Forms.MessageBox]::Show("We dont connect to NetApp Controller.")
   exit
} else {
echo "Connect to NetApp Controller success"
}
exit 
#Invoke-Sshcommand -InvokeOnAll -Command 'halt -t 0 -f'
#Invoke-Sshcommand -InvokeOnAll -Command 'ifconfig -a'
#Remove-SshSession -RemoveAll

2012-09-06

SQLSchedule

To Backup SQL Express


Features:

  • Supports all versions of SQL Server 2000, 2005, and 2008
  • Supports unlimited SQL Server instances with an unlimited number of jobs.
  • Allows to easily schedule SQL Server maintenance tasks: backups, index rebuilds, integrity checks, etc.
  • Runs as Windows Service
  • Email notifications on job success and failure
  • And more...

http://www.lazycoding.com/products.aspx

LogParser -- (3)

logparser.exe -o:datagrid "SELECT TimeGenerated, Message FROM security WHERE EventID=680 AND Message LIKE 'username'"

PStool GUI

http://www.davitools.com/fepstools/documentation.aspx

2012-08-14

dsquery command

dsquery user -inactive 13 ==>list users have no login for 91 days.
dsquery user -stalepwd 180 ==>list users that the password had been used for 180 days.

2012-08-08

netsh command change IP address

netsh interface ip set address "Local Area Connection" static 192.168.0.1 255.255.255.0 192.168.0.254 1

netsh firewall set icmpsetting 8          => allow others to ping you
netsh firewall set icmpsetting 8 disable=> deny others to ping you

2012-07-23

EventTriggers

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/eventtriggers.mspx?mfr=true


  • /create - is used to create an event trigger,
  • /delete can be used to delete the trigger
  • /eid - is the event id number you wish to track
  • /tr - is the name you would like to give to the event trigger
  • /ru - is the user name to run under userdomain or user@domain.com are both acceptable
  • /rp - is the user password
  • /tk - is the action you would like performed when triggered

  • /query - a list of event triggers

How to set event log security locally or by using Group Policy in Windows Server 2003

http://support.microsoft.com/kb/323076/en-us
http://social.technet.microsoft.com/Forums/zh-TW/winserverzhcht/thread/eda758fa-8841-4d64-9edb-5b798d99600d/

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\Security
對CustomSD點兩下後,在最後面加上下面一行

(A;; 0x1;;;UserSID)

A=Allow

D=Deny

1 = 讀取
2 = 寫入

3 = 讀取+寫入
4 = 清除

7 = 讀取+寫入+清除

2012-07-20

LogParser -- (2)


How do I retrieve the event logs that have been logged in the past 10 minutes?
You need to use the SUB function to subtract 10 minutes from the current UTC timestamp returned by the SYSTEM_TIMESTAMP function, and convert this timestamp to local time using the TO_LOCALTIME function:
SELECT *
FROM System
WHERE TimeGenerated >= TO_LOCALTIME( SUB( SYSTEM_TIMESTAMP(), TIMESTAMP( '10', 'mm' ) ) )

2012-07-18

LogParser -- (1)


logparser "SELECT * FROM Application.evt"
Task aborted.
Cannot open <from-entity>: Error opening event log "\\?\C:\Application.evt": The event log file is corrupted.
Statistics:
-----------
Elements processed: 0
Elements output:    0
Execution time:     0.61 seconds

Solution:
wevtutil epl application.evt application.evtx /lf:true
wevtutil export-log application.evt application.evtx /lf

wevtutil [{el | enum-logs}] [{gl | get-log} <Logname> [/f:<Format>]]
[{sl | set-log} <Logname> [/e:<Enabled>] [/i:<Isolation>] [/lfn:<Logpath>] [/rt:<Retention>] [/ab:<Auto>] [/ms:<Size>] [/l:<Level>] [/k:<Keywords>] [/ca:<Channel>] [/c:<Config>]] 
[{ep | enum-publishers}] 
[{gp | get-publisher} <Publishername> [/ge:<Metadata>] [/gm:<Message>] [/f:<Format>]] [{im | install-manifest} <Manifest>] 
[{um | uninstall-manifest} <Manifest>] [{qe | query-events} <Path> [/lf:<Logfile>] [/sq:<Structquery>] [/q:<Query>] [/bm:<Bookmark>] [/sbm:<Savebm>] [/rd:<Direction>] [/f:<Format>] [/l:<Locale>] [/c:<Count>] [/e:<Element>]] 
[{gli | get-loginfo} <Logname> [/lf:<Logfile>]] 
[{epl | export-log} <Path> <Exportfile> [/lf:<Logfile>] [/sq:<Structquery>] [/q:<Query>] [/ow:<Overwrite>]] 
[{al | archive-log} <Logpath> [/l:<Locale>]] 
[{cl | clear-log} <Logname> [/bu:<Backup>]] [/r:<Remote>] [/u:<Username>] [/p:<Password>] [/a:<Auth>] [/uni:<Unicode>]

Event Collector is managed with a command-line tool, Windows Event Collector Utility (Wecutil.exe).

2012-07-17

How to move user Databases

The procedures in this topic require the Logic name of the database files. To obtain the name, query the name column in the "sys.master_files" catalog view.
>select * from sys.master_files

To move a data or log file as part of a planned relocation, follow these steps:

1. Run the following statement.
>ALTER DATABASE database_name SET OFFLINE;

2. Move the file or files to the new location.

3. For each file moved, run the following statement.
>ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_path\os_file_name' );

4. Run the following statement.
>ALTER DATABASE database_name SET ONLINE;

5. Verify the file change by running the following query.
>SELECT name, physical_name AS CurrentLocation, state_desc FROM sys.master_files
WHERE database_id = DB_ID(N'<database_name>');

2012-07-15

mbralign options of NetApp

mbralign --sparse /vmfs/volume/"Datastore"/"Virtual Machine"/"Virtual Machine"-flat.vmdk


Options:
   --sparse                 The resulting file will be sparse.  This option is designed for NetApp NFS based datastor                            es.
   --force                  The default behavior is to skip properly aligned disks.
                            The --force option can be used to override this. (Useful for migrating and making sparse)                            .
   --bs=n                   Use n as the block size (specified in kB).  n must be one of (8, 16, 32, 64, 128, 1024).                             The default is 8.
   --preview                Show what would be done, then exit.  No changes are madeto the file.
   --quiet                  Only print warnings and errors (no other status isprinted to screen).
   --debug                  Print debug comments.
   --help                   Print usage.
   --thereAreNoVmSnapshots  Suppress the warning message about snapshots and answer YES to the question of whether to                            continue.

Cloning and converting virtual machine disks with vmkfstools

vmkfstools -i <input> <output> -d <format>

Convert HD type to thin-provision
1. SSH to VM host.
2. Shutdown the virtual machine.
3. vmkfstools -i "guest.vmdk" "new_guest.vmdk" -d thin
4. Add new HD and point to the "new_guest.vmdk" under "Edit setting"
5. Power-on the virtual machine.
6. Delete the "guest.vmdk" file.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1028042

2012-07-13

Hotkey for MacOS

Hotkey for Mac OS:
  • Power-off screen:Shitf + Ctrl + Eject
  • Hibernate:Command + Option +Eject
  • Reboot:Ctrl + Command +Eject
  • Shutdown:Ctrl + Option + Command +Eject
  • Logout:Shift + Command + Q

2012-07-11

How to increase HD size for Windows XP guest in ESXi

1. SSH to VM host.
2. Power-off the guest.
3. vmkfstools -X xxG /vmfs/volumes/"Datastore"/"VM guest"/"VM guest".vmdk
4. Power-on the guest.
5. Use GParted to extend the size for the filesystem of virtual machine.

2012-07-07

WSUS offline update

WSUS offline update

微軟更新離線安裝檔下載工具支援Windows 7及2008 R2,只要勾選要下載的更新項目,就會將檔案儲存於「client\wsus」資料夾,還可以勾選下載完畢時自動打包成ISO檔,或者複製到USB或某個資料夾。



Backup software -- Freeware

YadisBackup

Yadis is a free and easy backup application that protects your private information within minutes. It's intuitive design will guide you through a few steps, and before you know it, your personal data is brought in safety.



When you use a backup-tool, it's often a hard job to learn to know all of the features. And when you've finally managed to understand every possibility of that tool, you realize it's not just that what you wanted.

That's why we've created Yadis Backup. Take a look around and discover all of it's advantages...
  • It's FREE
  • It's small
  • It's easy to use
  • You can fully decide what to backup
  • It copies one on one your files to allmost any destination you want
  • You don't need Yadis! Backup to access the backed-up files
  • The marked folders are backed-up real-time (no scheduling needed!). You make a change? Yadis! Backup makes a backup
  • When your backup destination isn't available, Yadis! remembers the changes you have made. Whenever the location becomes available Yadis! starts backing up the changes.

How to list the password of all domian users will be expired in xx days

Requirement:netpwage

1. netpwage.exe /? ==> get more detail syntax
2. netpwage.exe /USERS /DOMAIN:xx /MIN:180 ==>List the users whose password  is at least 180 days old.

Exchange2003 自動郵件通知密碼將到期的使用者

參考來源 http://japlinchen.wordpress.com/


' exch-pwd-expires.vbs
'
' Alan.Zhou
' Jun 26, 2007
'Email: alan.zhou@hi-p.com
'
' This program scans all users in the AD,for users whose passwords have either
' already expired or will expire within DAYS_FOR_EMAIL days.
'
' An email is sent, using CDO, via the SMTP server specified as SMTP_SERVER to the
' user to tell them to change their password. You should change strFrom to match
' the email address of the administrator responsible for password changes.
'
' You will, at a minimum, need to change the SMTP_SERVER,  and the STRFROM constants.
' If you run this on an Exchange server, then SMTP_SERVER can
' be "127.0.0.1" - and it may be either an ip address or a resolvable name.
'


 'Option Explicit


 ' Per environment constants - you should change these!
 Const SMTP_SERVER  = "192.168.0.x"
 Const STRFROM   = "Administrator@YourDomain.com"
 Const DAYS_FOR_EMAIL  = 5


 ' System Constants - do not change
 Const ONE_HUNDRED_NANOSECOND    = .000000100   ' .000000100 is equal to 10^-7
 Const SECONDS_IN_DAY            = 86400
 Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
 Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D


 ' Change to "True" for extensive debugging output
 Const bDebug   = True
 Const ForWriting = 2
 Const ForReading = 1
 Const ForAppending = 8
 Const TristateUseDefault    = -2


    ' 簡單註記 by Japlin on 2010.12.22
 ' ================================================================================
 ' 使用者帳號      : Mid (objUser.Name, 4)
 ' 使用者郵件帳號  : objUser.userPrincipalName
 '                 {  UPN=系統主體用戶,是系統用戶以完整的電子郵件格式書寫的名稱 }
 '                 {  如:name@domain.com, Email.Name@emailAddress.com }
 ' 使用者登入名稱  : objUser.sAMAccountName
 '                 {  sAMAccountName = Domain account login name }
 ' Mailbox         : objUser.Mail
 ' 密碼最後變更日期: dtmValue = objUser.PasswordLastChanged
 ' 密碼保存最長期間: numdays = GetMaximumPasswordAge (strDomainDN)
 '                 {  在 UserIsExpired Function 內,變數名稱=iMaxAge }
 ' 密碼變更在幾天前: intTimeInterval = Int (Now - dtmValue)
 '                 {  今天日期-密碼最後變更日期 }
 ' 密碼是否過期    : if intTimeInterval >= iMaxAge
 ' 密碼在幾天後到期: iRes = Int ((dtmValue + iMaxAge) - Now)
 '                 {  密碼最後變更日期 + 密碼保存最長期間 - 今天日期 }
 ' 發送郵件通知條件: If iRes <=  DAYS_FOR_EMAIL
 '                 {  DAYS_FOR_EMAIL 是在程式內自定義,並非AD上所定義的通知日期 }
 '


 Dim objRoot , objFSO
 Dim numDays, iResult
 Dim strDomainDN , Outputfile
 Dim objContainer, objSub


 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Outputfile = "./exch-pwd-expires-2-log.txt"
 CreateOutputFile OutputFile
 wscript.sleep 1000


 Set objRoot = GetObject ("LDAP://rootDSE")
 strDomainDN = objRoot.Get ("defaultNamingContext")
 Set objRoot = Nothing


 numdays = GetMaximumPasswordAge (strDomainDN)
 dp strDomainDN & " 密碼保存最長期間: " & numDays & vbCRLF


 If numDays > 0 Then
    Set objConnection = CreateObject("ADODB.Connection")
 Set objCommand =   CreateObject("ADODB.Command")
 objConnection.Provider = "ADsDSOObject"
 objConnection.Open "Active Directory Provider"
 Set objCommand.ActiveConnection = objConnection


 objCommand.Properties("Page Size") = 1000
 objCommand.Properties("Searchscope") = 2
 'objCommand.CommandText = _
 '    "SELECT AdsPath, whenCreated FROM 'LDAP://"& strDomainDN &"' WHERE objectCategory='user'"
 objCommand.CommandText = _
         "Select AdsPath, whenCreated from 'LDAP://" & strDomainDN & _
             "' where objectClass ='user' and objectClass <>'computer'"
 Set objRecordSet = objCommand.Execute
 objRecordSet.MoveFirst
 Do Until objRecordSet.EOF
  Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
  If Right (objUser.Name, 1) <> "$" Then
   If IsEmpty (objUser.Mail) or IsNull  (objUser.Mail) Then
    dp Mid (objUser.Name, 4) & " 沒有 Mailbox" & vbCRLF
            Else
                If UserIsExpired (objUser, numdays, DAYS_FOR_EMAIL, iResult) Then
     dp "---已經發送 Email 給 " & objUser.Mail & vbCRLF
     Call SendEmail (objUser, iResult)
    Else
     dp "...不需要發送 Email" & vbCRLF
    End If
   End If
  End If
     objRecordSet.MoveNext
 Loop


 End If


 WScript.Echo "Done"


Function GetMaximumPasswordAge (ByVal strDomainDN)
 Dim objDomain, objMaxPwdAge
 Dim dblMaxPwdNano, dblMaxPwdSecs, dblMaxPwdDays


 Set objDomain = GetObject("LDAP://" & strDomainDN)
 Set objMaxPWdAge = objDomain.maxPwdAge


 If objMaxPwdAge.LowPart = 0 And objMaxPwdAge.Highpart = 0 Then
  ' Maximum password age is set to 0 in the domain
  ' Therefore, passwords do not expire
  GetMaximumPasswordAge = 0
 Else
  dblMaxPwdNano = Abs (objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
  dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND
  dblMaxPwdDays = Int (dblMaxPwdSecs / SECONDS_IN_DAY)
  GetMaximumPasswordAge = dblMaxPwdDays
 End If
End Function


Function UserIsExpired (objUser, iMaxAge, iDaysForEmail, iRes)
 Dim intUserAccountControl, dtmValue, intTimeInterval
 Dim strName


 On Error Resume Next
 Err.Clear


 strName = Mid (objUser.Name, 4)
 intUserAccountControl = objUser.Get ("userAccountControl")


 If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
  dp strName & " 的密碼尚未過期."
  UserIsExpired = False
 Else
  iRes = 0
  dtmValue = objUser.PasswordLastChanged
  If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
   UserIsExpired = True
   dp strName & " 的密碼尚未設定." & vbCRLF
  Else
   intTimeInterval = Int (Now - dtmValue)
   dp strName & " 的密碼最後設定日期:" & _
    DateValue(dtmValue) & " 在 " & TimeValue(dtmValue) & _
    " (" & intTimeInterval & " 天以前) 最大日期:" & iMaxAge


   If intTimeInterval >= iMaxAge Then
    dp strName & " 的密碼已經過期."
    UserIsExpired = True
   Else
    iRes = Int ((dtmValue + iMaxAge) - Now)
    dp strName & " 的密碼將於 " & _
     DateValue(dtmValue + iMaxAge) & " (" & _
     iRes & " 天後到期)."


    If iRes <= iDaysForEmail Then
     'dp strName & " 需要一個 email 帳號作為密碼更改通知"
     UserIsExpired = True
    Else
     'dp strName & " 不需要 email 帳號作為密碼更改通知"
     UserIsExpired = False
    End If
   End If


  End If
 End If
End Function


Sub SendEmail (objUser, iResult)
 Dim objMail


 Set objMail = CreateObject ("CDO.Message")


 objMail.From     = STRFROM
 objMail.To       = objUser.Mail


 objMail.Subject  = "密碼到期通知:" & Mid (objUser.Name, 4)
 objMail.Textbody = "Dear " & objUser.userPrincipalName & ":" & vbCRLF & _
    "您的網域和郵件帳號 (" & objUser.sAMAccountName & ")" & vbCRLF & _
    "密碼將於 " & iResult & " 天後到期了。 " & vbCRLF & _
    "請您儘快更換您的密碼." & vbCRLF & vbCRLF & _
 "請至 <a herf='https://webmail.YourDomain.com/ChangePassword/'>公司網域密碼變更處</a> 變更您的密碼" & vbCRLF & _
    "謝謝!" & vbCRLF & _
    "資訊部 系統管理者 敬上"


 objMail.Send


 Set objMail = Nothing
End Sub


Sub dp (str)
 If bDebug Then
  WriteOutputToFile str
 End If
End Sub


'---------------------------------------------------------------------------------------
'Function: CreateOutputFile
'Last Modified: 10/11/05 .csm
'This function writes the output file for the script.  The name and destination of the
'file is passed in as string variable. Uses Wscript.network to find current user id
'and domain, tries Win32_ComputerSystem and prompts if both of these methods fail.
'---------------------------------------------------------------------------------------
Function CreateOutputFile(OutputFile)
Dim tmpCurrentUser, objNetwork
strComputer = "."
'get local user information and add to the header file
Set objNetwork = CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
 tmpCurrentUser = objItem.UserName
Next


If IsNull(tmpCurrentUser) Then
    ScriptDomain = objNetwork.UserDomain
 ScriptUser = objNetwork.UserName
 If ISNull(ScriptDomain) or IsNull(ScriptUser) Then ' have user manually enter information as a last resort
  ScriptDomain = InputBox("請輸入 Domain:")
  ScriptUser = InputBox("請輸入 User ID:")
 End if
Else
 tmpCurrentUser = Split(tmpCurrentUser,"\")
 ScriptDomain = tmpCurrentUser(0)
 ScriptUser = tmpCurrentUser(1)
End if


Set objFile = objFSO.CreateTextFile(Outputfile) 'Create the File
objFile.Close
'Re-open file, write the headcer & 1st line of output
Set objFile = objFSO.OpenTextFile(Outputfile, ForWriting, true, TristateUseDefault)
objFile.WriteLine "Check domain password log"
objFile.WriteLine "Created: " & Now
objFile.WriteLine "Computer Domain: " & ScriptDomain
objFile.WriteLine "Current User: " & ScriptUser & vbcrlf
objFile.Close
End Function 


'---------------------------------------------------------------------------------------
'Function: WriteOutputToFile
'Last Modified: 9/28/05 .csm
'This function accepts a string and writes it to the output file
'---------------------------------------------------------------------------------------
Function WriteOutputToFile(strOutput)
'Check if file exists & write the data
On Error Resume Next
'Wscript.echo (strOutput)


If objFSO.FileExists(Outputfile) Then
 Set objFile = objFSO.OpenTextFile(Outputfile, ForAppending)
 objFile.Write strOutput
 objFile.WriteBlankLines(1)
 objExplorer.Document.Body.InnerHTML = "Script progress: <br>" & strOutput
Else
 ' file not found
 'Wscript.echo "Error file not found.  Please run the script again."
End If
objFile.Close
End Function


2012-07-02

Hotkey for ESXi

Hotkey for ESXi
Hosts And Clusters                               Ctrl+Shift+H
Virtual Machines And Templates         Ctrl+Shift+V
Networking                                             Ctrl+Shift+N
Datastores and Datastore Clusters    Ctrl+Shift+D