0

Windowsでスケジュールされたタスクのような「cronジョブ」をセットアップするために、以前のstackoverflowの質問で推奨されたコードを使用してPowershellスクリプトをセットアップしました。

毎日クリーンアップして古いバックアップを削除する必要があるバックアップがいくつかあるので、このタスクを実行するための asp.net スクリプトを作成しました。ファイル名は BackupCleanup.aspx で、ASP.net スクリプトを上記のURLにアクセスして所有します-ただし、以下のPowershellスクリプトを使用して実行することはできません。

私が使用しているPowershellスクリプトコードは次のとおりです。

$request = [System.Net.WebRequest]::Create("http://127.0.0.1/BackupCleanup.aspx")
$response = $request.GetResponse()
$response.Close()

このファイルを PS1 拡張子で作成しました。OS (Windows 2008) で正しく表示されます。右クリックして [Powershell で実行] を選択することで、このタスクを手動で実行しようとしました。また、これをタスクとしてスケジュールしました。役立たず。

スクリプトが機能しない理由がわかりません - どんな助けでも大歓迎です。

4

2 に答える 2

0

同じ問題がありました。PowerShell を手動で開いてスクリプトを実行したところ、「このシステムではスクリプトの実行が無効になっているため、WebPage.ps1 を読み込めません。」というメッセージが表示されました。

スクリプトの実行を許可する必要があります

PowerShell で以下を実行します。

Set-ExecutionPolicy RemoteSigned -Scope LocalMachine

于 2014-02-06T16:12:55.020 に答える
0

これは、IE を使用して Web ページを呼び出すために使用する Powershell スクリプトです。うまくいけば、これもうまくいくでしょう。

Function NavigateTo([string] $url, [int] $delayTime = 100)
{
  Write-Verbose "Navigating to $url"

  $global:ie.Navigate($url)

  WaitForPage $delayTime
}

Function WaitForPage([int] $delayTime = 100)
{
  $loaded = $false

  while ($loaded -eq $false) {
    [System.Threading.Thread]::Sleep($delayTime) 

    #If the browser is not busy, the page is loaded
    if (-not $global:ie.Busy)
    {
      $loaded = $true
    }
  }

  $global:doc = $global:ie.Document
}

Function SetElementValueByName($name, $value, [int] $position = 0) {
  if ($global:doc -eq $null) {
    Write-Error "Document is null"
    break
  }
  $elements = @($global:doc.getElementsByName($name))
  if ($elements.Count -ne 0) {
    $elements[$position].Value = $value
  }
  else {
    Write-Warning "Couldn't find any element with name ""$name"""
  }
}

Function ClickElementById($id)
{
  $element = $global:doc.getElementById($id)
  if ($element -ne $null) {
    $element.Click()
    WaitForPage
  }
  else {
    Write-Error "Couldn't find element with id ""$id"""
    break
  }
}

Function ClickElementByName($name, [int] $position = 0)
{
  if ($global:doc -eq $null) {
    Write-Error "Document is null"
    break
  }
  $elements = @($global:doc.getElementsByName($name))
  if ($elements.Count -ne 0) {
    $elements[$position].Click()
    WaitForPage
  }
  else {
    Write-Error "Couldn't find element with name ""$name"" at position ""$position"""
    break
  }
}

Function ClickElementByTagName($name, [int] $position = 0)
{
  if ($global:doc -eq $null) {
    Write-Error "Document is null"
    break
  }
  $elements = @($global:doc.getElementsByTagName($name))
  if ($elements.Count -ne 0) {
    $elements[$position].Click()
    WaitForPage
  }
  else {
    Write-Error "Couldn't find element with tag name ""$name"" at position ""$position"""
    break
  }
}

#Entry point

# Setup references to IE
$global:ie = New-Object -com "InternetExplorer.Application"
$global:ie.Navigate("about:blank")
$global:ie.visible = $true

# Call the page
NavigateTo "http://127.0.0.1/BackupCleanup.aspx"

# Release resources
$global:ie.Quit()
$global:ie = $null
于 2013-01-28T14:25:14.950 に答える