小编Dou*_*oug的帖子

任务调度程序 powershell 脚本永远不会结束

我有一个手动运行很好的脚本。但是,当我在 Task Scheduler 中安排它时,脚本永远不会结束,因此下次尝试运行时,它会失败,因为前一个实例仍在运行。脚本本身在第一次或手动运行时需要几秒钟才能完成。这是脚本:

$source = "\\server1\upload"
$destination = "\\server2\upload"
$logfile = "c:\Scripts\fileMover\log.txt"
$table = Get-ChildItem $source -include *
foreach ($file in $table){
    $filename = $file.FullName
    #write-host $filename
    try
    {
        move-item -LiteralPath $filename -destination $destination -force
        $body = "Successfully moved $filename to $destination"
        $subject = "fileMover Succeeded"
    }
    catch
    {
        $body = "Failed to move $filename to $destination"
        $subject = "fileMover Failed"
    }
    finally
    {
        $body | out-file $logfile -append -width 1000 -encoding ascii
        Send-MailMessage -To "filemoverconfirmations@domain.com" -From "uploader@domain.com" -Subject …
Run Code Online (Sandbox Code Playgroud)

powershell scheduler task

7
推荐指数
2
解决办法
8131
查看次数

Powershell: write XML to file

I'm working with XML files for the first time in PowerShell. I have a simple script that fails. I need to get XML content using web-request and then save it to a folder for later processing.

Here is the code:

$IP = 8.8.8.8
$ipgeo = new-object System.Xml.XmlDocument
$ipgeo = ([xml](Invoke-WebRequest "http://freegeoip.net/xml/$IP").Content).Response
$ipgeo.save("c:\ipgeo\IPXML\$IP.xml")
Run Code Online (Sandbox Code Playgroud)

When I run this, I get the following error:

Method invocation failed because [System.Xml.XmlElement] does not contain a method named 'save'. At line:3 char:1
+ $ipgeo.save("c:\ipgeo\IPXML\$IP.xml")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ …
Run Code Online (Sandbox Code Playgroud)

xml powershell

4
推荐指数
1
解决办法
5368
查看次数

标签 统计

powershell ×2

scheduler ×1

task ×1

xml ×1