PowerShell(備忘録4)2011/03/31 20:05

2010-01-12 指定したディレクトリのExcelのファイル名とシート名を表示する

http://d.hatena.ne.jp/bhunji2000/20100112/1263305671

IE に HTML を表示した状態で、DOM のオブジェクトツリーを確認したい場合

http://mapexinfo.sblo.jp/index-2.html

XmlDocument v.s. XPathNavigator(.Netでは、XmlDocumentを使う必要があるようです。XPathNavigatorはメンテナンスモード。LINQ for XMLが本命かも)

http://ii.cocolog-nifty.com/sasurai/2005/01/xmldocument_vs_.html

Using Xml.Linq in PowerShell

http://www.dougfinke.com/blog/index.php/2007/08/07/using-xmllinq-in-powershell/

連載 .NETで簡単XML

http://www.atmarkit.co.jp/fdotnet/easyxml/index/index.html

CSV の読み込み方

get-content aaa.csv | convertfrom-csv

とする。そうしないと、文字コードが変換されません。

CSV の書き方

Export-CSV aaa.csv

CSV の特定のカラムを取得

get-content aaa.csv | convertfrom-csv | foreach-object{$_.name}

foreach-object, Where-object の使い方

dir | where-object{ $_.extension } | foreach-object{ $_.fullname }

PowerShellで、cd で移動できる場所をPSDriveと呼ぶ

Get-PSDrive ←移動できる全ての場所の一覧を取得

Command一覧の取得

Get-Command 
get-service | Select Object{ $_.name } ←単純に名前だけ取得
get-service | Select Object Name ←名前を取得(ただし、オブジェクトなので、プロパティあり)

表で表示。

dir | out-gridview

out-ie.ps1 PowerShellからHTMLをIEに流し込む。(その2)

http://scripting.cocolog-nifty.com/blog/2010/07/powershellhtmli.html

Excel 一番下のセルを取得

1.Ctr+End または、編集(E)→ジャンプ(G)→セル選択(S)→最後のセル(S)で最後のセルを確認

PowerShell で Excel 2007 のシートを操作する(xlsx形式のEXCELファイル)

http://blogs.technet.com/b/stanabe/archive/2007/08/08/how-to-read-excel-sheets-with-powershell.aspx

Excel の開き方

$excel=New-Object -com Excel.Application
$excel.visible=$true
$workbooks=$excel.workbooks.open("ssss.xls")
$sheet=$workbooks.worksheets.item(1)
$workbooks.worksheets |%{if($_.index -eq 1){$sheet=#$_}}
$sheet.cells.item(1,1).text
$lastcell=$sheet.cells.specialcells(11) 11 は、xlLastCellsである。
$lastcell.row
$lastcell.column
1..100 | foreach-object{ $sheet.cells.item(1,$_).value() } .text でも良い。

スクリプトを現在のスコープで実行(UNIX のsource コマンドと同一)

. $profile