【发布时间】:2014-10-28 12:56:23
【问题描述】:
我遇到了一个脚本问题,该脚本将删除服务器 C 驱动器上的文件。脚本如下所示:
param(
[Parameter(Mandatory=$true)][string]$hostname
)
$StrFileName = "C:\Program Files\NSClient++\nsclient.log"
$LogLocal="c:\Nagios\naf_delete_nscp_log_file.log"
$Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
"$date : NSClient logfile deletion requested on $hostname" | Out-File -filepath $LogLocal -Append
If (Test-Path "$strFileName"){
Remove-Item $strFileName -Force
$Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
"$date : NSClient logfile deleted on $hostname" | Out-File -filepath $LogLocal -Append
}
该脚本从 Nagios 快速操作启动,该操作将使用 nrpe 将主机作为参数传递,并使作为本地系统运行的 nscp 服务运行它。它在没有启用 uac 的服务器上完美运行,但我无法让它在具有 uac 的服务器上运行。 我尝试了许多选项,但似乎没有一个有效。非常感谢任何提示或建议在启用了 uac 的服务器上运行此功能。
谢谢。
威廉
【问题讨论】:
-
nsclient.ini 中的条目是什么样的?您应该能够将
-Verb runAs添加到 powershell 包装器ps1 = cmd /c echo scripts\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -Verb RunAs -或您的[/settings/external scripts/wrapped scripts]定义中。 -
Remove-Item有凭证参数,或许你可以这样解决 -
atm 看起来像这样:naf_delete_nscp_log_file=cmd /c echo scripts\naf_delete_nscp_log_file.ps1 $ARG1$;退出 $LastExitCode | powershell.exe -command - 我将尝试使用 -Verb RunAs
-
@Matt 似乎 -verb RunAs 确实成功了。谢谢!
标签: powershell uac nagios access-denied