Chinaunix首页 | 论坛 | 博客
  • 博客访问: 876502
  • 博文数量: 275
  • 博客积分: 3904
  • 博客等级: 中校
  • 技术积分: 4605
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-17 21:10
文章分类

全部博文(275)

文章存档

2014年(9)

2013年(124)

2012年(142)

分类: 系统运维

2013-12-05 13:50:38

可以作为计划任务运行一些向您发送电子邮件或者一个监控脚本,但最近我一直在如何可以做到这一点你把运行行什么脚本能够正常工作一个公平一些的PowerCLI脚本

这样做有真正方法有两种:

1.  Add a line to a start of each of your scripts to make sure it loads the PowerCLI snapin, without which PowerShell will not recognise any of the PowerCLI cmdlets.

Add the following line to the top of each script you will be running as a scheduled task:

add-pssnapin .VimAutomation.Core

Then in the run box on your scheduled task you can call your script with the following command:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe “& ‘C:\Scripts\MyScript.ps1′”

But remember when you are troubleshooting this script or amending it you will most likely get an error as your script editor will automatically add the VMware snapin.

2.  This method is the one I use as its easier than remembering to put the line at the top of each file and then commenting it out when you want to edit it etc, this method runs the PowerCLI Console file before it runs your script.

A PowerShell Console file is a xml like file containing information on what snapins to load when PowerShell is started.

This will enable the snapin for you and there is nothing to ad to the scripts.

The run command then looks like this:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ ” &  “C:\Scripts\MyScript.ps1″

You can test both of these methods by running them from a cmd prompt before using it to ensure they work properly.

 
   
阅读(2945) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~