LoginSignup
1
8

More than 1 year has passed since last update.

powershellでIEのいろいろ

Last updated at Posted at 2018-07-24

1.概要

①IEのインターネットオプションを設定する方法。
②IEをURL指定して開き、操作
③IEで開いているページを取得

2.環境

・powershell : 5.1
・IE : 11

3.コード

3.1.インターネットオプション

IE_set.ps1
#IEのスタートページをグーグルに変更
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Internet Explorer\Main' -Name "Start Page" -Value "https://www.google.co.jp/" 
#インターネットオプションのプロパティ確認
#gp "HKCU:\Software\Microsoft\Internet Explorer\Main" 

3.2.IEを開く

IE_ope.ps1
$ie = New-Object -ComObject InternetExplorer.Application  # IE起動
$ie.Navigate("開きたいページのURL") # URL指定
$ie.Visible = $true #IEの画面表示
$doc=$ie.document
#オブジェクトを配列で取得
$txtId=$doc.getElementsByName("操作したいオブジェクトのnameプロパティ") 
#idプロパティの場合:getElementById
@($txtId)[0].value = "代入したい値"
#TagNameプロパティでオブジェクトを取得。whereでオブジェクトの絞り込み
$btnDay = $doc.getElementsByTagName("操作したいオブジェクトのタグ名") | where {$_.innerText -eq ""} 
 #取得したボタンをクリック
@($btnDay)[0].click()

3.3.IEで開いているページを取得

IE_get.ps1
#シェルを取得
$shell = New-Object -ComObject Shell.Application
#ieで開いているページ一覧を取得
$ie_list = @($shell.Windows() | where { $_.Name -match "Internet Explorer" })
#URL指定でIEページのオブジェクトを取得する([-1]で同一ページの最新のタブのオブジェクトを取得する)
$ie = @($ie_list | where { $_.LocationURL -match "オブジェクトを取得したいページのURL" })[-1]
1
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
8