【发布时间】:2017-05-09 19:41:44
【问题描述】:
我有一个简单的 PowerShell 脚本,它只创建一个文件。测试更大的 PowerShell 脚本。
在 Windows Server 2012 R2 - 64 位上运行
它在管理员帐户下运行。
无论用户是否登录都运行
以最高权限运行
行动: 程序/脚本 : Powershell.exe(我试过这种方式和完整路径)
添加参数:-NoProfile -executionpolicy remotesigned -file C:\Scripts\test.ps1
获取执行策略:远程签名
将“管理员”添加到: Set-PSSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI
“管理员”具有“作为批处理作业登录”权限 “管理员”在管理员组中
用于测试的 PowerShell 脚本:
$text = "Hello World"
$text | Set-Content TestMyFile.txt
$text | Out-File TestMyFile.txt
$text > TestMyFile.txt
# This is to write into a file or append to the text file created:
$text | Add-Content TestMyFile.txt
$text | Out-File TestMyFile.txt -Append
$text >> TestMyFile.txt
没什么花哨的,只是想确保任务计划程序将执行 PowerShell 脚本。
那么我错过了什么?
【问题讨论】:
-
您没有在文件上使用完整路径,因此它将它们写入工作目录(可能不是存储脚本的位置),所以 1)您是否有权在那里写入和 2)你真的去看了吗?
-
他说“在管理员权限下运行”。这可能意味着:1) 是的 2) 数据将在 %systemroot%\system32 结束。甚至有错误吗? “历史”标签显示什么?
-
哇,好的,我没有考虑文件目录.....我将代码更改为使用目录$text |输出文件 C:\Script\TestMyFile.txt
标签: powershell scheduled-tasks