目前分類:PowerShell (163)
- Nov 19 Sun 2006 23:14
PowerShellIDE
- Nov 19 Sun 2006 22:31
How to Get Windows PowerShell 1.0
可從以下連結下載Windows PowerShell 1.0
http://www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx
[注意]電腦必須先安裝.NET Framework 2.0
安裝完成後可於
- Nov 18 Sat 2006 08:03
PowerShell:Start-Transcript,Stop-Transcript
若想要將PowerShell在此session中的所有執行過程以及執行結果(就是畫面上所有的東西)紀錄到某個檔案中,我們可以使用
PS C:\>Start-Transcript -path 檔案路徑
若欲結束紀錄則使用
- Nov 18 Sat 2006 05:33
PowerShell Rocks!
- Nov 18 Sat 2006 05:31
Managing IIS 7 with Windows PowerShell
- Nov 18 Sat 2006 05:14
The DFO Show - Windows Vista and Windows PowerShell
- Nov 18 Sat 2006 05:12
IT Forum Day One: Windows Vista and Windows PowerShell
- 12 Cool Features of Windows PowerShell
- Built-in Cmdlets (pronounced "commandlets") for Managing Windows
- The power of wildcards and working objects
- Whatif you could test your commands before committing to them
- PS> stop-service w3* -whatif
- Take a transcript
- PS> Start-Transcript -Path c:\demo\dfoshow.txt
PS> Stop-Transcript
- PS> Start-Transcript -Path c:\demo\dfoshow.txt
- Make Windows talk from the command line
- PS> $spVoice = new-object -com "SAPI.spvoice"
- PS> $spVoice = new-object -com "SAPI.spvoice"
- Nov 18 Sat 2006 04:36
An Introduction to Windows PowerShell and IIS 7.0
http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=1212
About Windows PowerShell
- PS C:\> set-location Data
- PS C:\Data> get-childitem Pow*
- PS C:\Data> copy-item 'PowerShell' 'C:\Data\PSBackup' -recurse -force
- 複製PowerShell資料夾及其底下所有的檔案與資料夾
- PS C:\Data> remove-item PSBackup
- 刪除PSBackup 資料夾及其底下所有的檔案與資料夾
- PS C:\Data> get-content 'Hello.txt' | out-file '.\HelloCopy.txt'
- PS C:\Data> get-content HelloCopy.txt
- the get-content cmdlet is roughly equivalent to the type (Windows) or cat (Unix) commands
- PS C:\Data> sl \
- 使用set-location的alias sl 將目前路徑改為C:\
- 查看sl為何者的alias
- PS C:\> get-alias sl
CommandType Name Definition
----------- ---- ----------
- Nov 18 Sat 2006 04:28
Windows PowerShell Visual Studio 2005 Templates (C# and VB.NET)
- Nov 18 Sat 2006 04:18
Writing PowerShell Command-lets for IIS7
- Nov 17 Fri 2006 05:30
PowerShell:Profile
一般情形下所設定的alias 其存續期間僅在此session內
因此關掉視窗之後alias則不存在
若想要保留此alias則需將其設定於Profile檔
<註>自行建立的function,variable也是如此
- Nov 16 Thu 2006 05:16
PowerShell Webcast Day 5
- 用PowerShell寫Event Log
- $a = new-object -type system.diagnostics.eventlog -argumentlist system #寫到事件紀錄器的系統中
- $a.source = "Windows PowerShell Week" #事件來源
- $a.writeentry("This is just a test.","Information") #前者為事件內容 後者為事件的種類(包含 Error,FailureAudit,Information,SuccessAudit,Warning)
- 一個source只能連結一種事件(應用程式,系統,安全性)
- Remote Computer
- $a = new-object -type system.diagnostics.eventlog -argumentlist system,ComputerName
- PowerShell Formating Files
- Nov 15 Wed 2006 07:39
PowerShell:Array(陣列)
- Nov 15 Wed 2006 06:41
PowerShell:Invoke-Expression
所需執行的指令如果是會變動的(可能透過程式動態組合出的指令字串)如
"get-process " + "| sort-object CPU -desc " + " |select-object -first 3"
則我們可以透過Invoke-Expression指令執行之
上述三個字串分別代表
- Nov 15 Wed 2006 05:19
PowerShell: 分頁顯示(Out-Host -Paging與more)
- Nov 13 Mon 2006 00:19
PowerShell Webcast Day 4
- 執行 PowerShell Script
- Nov 11 Sat 2006 05:52
PowerShell Webcast Day 3
- 0.Object
- object has..
- Unique name
- Properties
- Methods
- Like command tool
- unique name
- Let you do things
- group together related functionality
- Can be used from command prompt
- Like output strings
- Contain results
- Can be parsed for particular bits of info
- Can be used from command prompt
- Type of object
- COM obj
- WMI obj
- .NET framework obj
- Windows powerShell obj
- 1.Using Object
- COM
- $obj = new-object -comobject <PROGID>
- $obj = new-object -com <PROGID>
- PROGID look like "WScript.Network" and they stored in the registry HKEY_CLASSES_ROOT
- Accessing Properties
- $obj = new-object -com WScript.Network
- $obj.Name
- Setting Properties
- $ExcelObj = new-object -com Excel.Application
- $ExcelObj.Visible = $true
- $WorkBookObj = $ExcelObj.Workbooks.add()
- $WorkSheetObj = $WorkBookObj.Worksheets.Item(1)
- $WorkSheetObj.Cells.Item(1.1) = "Feel the Power"
- $ExcelObj.Quit
- Calling Methods
- $WorkBookObj = $ExcelObj.Workbooks.add()
- WMI
- $obj = get-wmiobject -class <WMI Class>
- $obj = get-wmiobject <WMI Class>
- $obj = get-wmiobject -query <WQL>
- Accessing Properties
- $obj = get-wmiobject win32_process
- $obj.WorkingSetSize
- $obj | foreach-obkect {$_.ProcessName +":"+$_.WorkingSetSize}
- Modifying Properties
- $wmi_settings = get-wmiobject win32_wmisetting
- $wmi_settings.ASPScriptDefaultNamespace = "root\default"
- Calling methods
- $obj = get-wmiobject win32_process -filter 'Name = "notepad.exe"'
- $obj.GetOwner()
- .NET framework
- $obj = new-object -typeName <Fully-Qualified Name>
- $obj = new-object <Fully-Qualified Name>
- $obj = [ADSI]"LDAP://localhist:389/dc=NA,dc=fabrikam,dc=com"
- $di = new-object System.IO.DiretoryInfo($PSHOME)
- $PSHOME : home dir for PowerShell
- Accessing Properties
- $di = new-object System.IO.DiretoryInfo($PSHOME)
- $di.CreationTime
- Calling methods
- $di.CreateSubdirectory("test")
- $web = new-object System.Net.WebClient
- $page = $web.downloadstring(http://www.scriptingguys.com)\
- UI
- [System.Refleciotn.Assembly]::LoadWithPartialName(" System.windows.Forms")
- $form = new-object System.Wondows.Forms.form
- 2.Exploring Object
- get-member
- OLEView
- Go to MSDN library
- $objshell = get-object -com "Shell.Application" | get-member
- $objFilder = $objshell.BrowseForFolder(0,"Pick Me!!",0) //跳出瀏覽資料夾視窗
- System.IO.DirectoryInfo //namespace
- $di = get-member -membertype Property
- 3.Displaying Object
- Many ways to "display" an object
- Windows PowerShell provides a default way
- XML config files let you change that default
- 修改types.ps1xml檔以修改預設顯示欄位
- $PSHOME\types.ps1xml
- ... | format -list *
- set-executionpolicy remotesigned
- update-typedata
- 4.Saving and Restoring Object
- Export-Clixml saves a representation of the object to a file you can revive later
- new-object -com "WScript.Network" | export-clixml "mothball.xml"
- Import-Clixml restores the object from a file
- $obj = import-clixml "mothball.xml"
- 5.Copying and Modifying Object
- Select-Object
- Creates a new object by copying a portion of an exising one
- Add-Member
- Augments an object by adding to an existing one
- Add property using select-object
- get-process | select-object ProcessName,@{Name="Start Day";Expression = {$_.startTime.DayofWeek}}
- 上述物件型態:System.management.automation.PSCustomObject
- Add property using add-mamber
- $a = "thanks for watching windows powershell week"
- $a = add-member -inputobject $a -membertype scriptmethod -name words -value {$this.splite()} -passthru
- 6.Comparing Object
- compare-object
- $process = get-process
- notepad
- $processes_now = get-process
- compare-object -ref $process -dif $process_now
- $process_now | where-object {$_.Name -eq 'notepad'} | select-object Name,HasExited //true
- , $procs | get-member //object[ ]
- Reflection uses Get-Member
- Simple,consistent,and use dot notation
- Nov 10 Fri 2006 08:31
PowerShell Webcast Day 2
- Nov 09 Thu 2006 05:06
PowerShell Webcast Day 1
- Nov 08 Wed 2006 07:11
PowerShell初探