【发布时间】:2018-12-19 14:45:47
【问题描述】:
我们为自动报告脚本设置了 Win Server 2016,以便在作为计划任务执行时将报告推送到 github。
当我以代理用户身份登录时,我可以毫无问题地运行此脚本。我已经启动了 sshagent 并且它正在运行。当作为计划任务运行时,该脚本在脚本的第二部分(git push)中终止。
我已尝试将 git-push 部分作为计划任务单独运行,但仍然无法运行(ssh 代理仍在运行)。我也可以毫无问题地在 git-bash 中运行它。
#git checkout the most recent vCenter list.
cd D:\virtualization-reporting
git checkout vcenters.csv
cd D:\scripts
#list of vCenters to be queried
$vcenters = import-csv D:\virtualization-reporting\vcenters.csv
#connect to vCenters, get templates, export to csv.
foreach ($vc in $vcenters){
$creds = Get-VICredentialStoreItem -host $vc.vcenter -file D:\scripts\creds.xml -ErrorAction Ignore
Connect-VIServer -Server $creds.host -User $creds.User -Password $creds.Password
foreach($dc in Get-Datacenter){
foreach($cluster in Get-Cluster -Location $dc){
Get-Template |
Select Name,
@{N='vCenter';e={$vc}},
@{N='Cluster';E={$cluster.Name}},
@{N='Path';e={$_.extensiondata.config.files.VmPathName}}|
sort Name,vCenter,Cluster,Path|
export-csv -append -path D:\virtualization-reporting\Template_Distribution_Report\Template_status-$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation
}
}
#disconnects from each vCenter after gathering data and appeneding to csv
disconnect-viserver * -confirm:$false
}
#change directory to the repo path on the POSH host.
cd D:\virtualization-reporting
#git merge output with GitHub
$date = (get-date)
git checkout master
git pull
git add -A
git commit -m "Updated Template Distribution Report for $date"
git push
#exit PowerShell Session
Exit-PSSession
如果我不能在 PowerShell 中运行它,我会很高兴有一个在 POSH 或 git bash 中运行的计划任务来执行 git push。
谢谢。
【问题讨论】:
-
这里没有问题。
-
您的错误信息是什么?我猜您需要将 powercli 模块添加到顶部,因为您的计划任务将打开 powershell 而不是 powercli。 Get-Module -Name VMWare* -ListAvailable |导入模块
标签: git powershell github powercli