I wrote an article to introducing how to integrate PowerCLI with PowerShell and PowerShell ISE. VMware just released PowerCLI 6.5 R1, it includes lot of new features and modules. And somehow my way doesn’t work. Following is new way to integrate PowerCLI 6.5 with PowerShell and PowerShell ISE in Windows 10.
PowerShell and PowerShell ISE both have it own $profile. So we need to do two times.
Before we start
Please make sure your PowerShell execution policy is not restricted. You can get the setting by run following command:
- Open PowerShell window. Run following command to confirm profile file is not existing.
If return is ‘False’, go to step 2.
If return is ‘True’, Backup the file and go to step 3.
- Run following command if the profile file doesn’t existing.
New-Item -Path $profile -type file -force | Out-Null
The return above should be ‘True’. Profile file is created.
- Run following command to include VMware PowerCLI modules in PowerShell.
Add-Content -Path $profile -value "# Load Windows PowerShell cmdlets for managing vSphere `r`n. 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'"
The blue text above maybe different in your environment base upon where your PowerCLI is installed.
PowerShell ISE Integration
PowerShell ISE process is same to PowerShell, only different is all the operation should be completed in PowerShell ISE window.
Reboot is not required in my environment. But anyhow please reboot if you see any issue.
The processes above integrate PowerCLI 6.5 with PowerCLI and PowerCLI ISE for current user only. If you want to integrate for all users on the machine, you need to refer to this article.
Continue reading “格式化PowerCLI输出”
First of all, this article is nothing related to PowerCLI. You probably know how to set Path Selection Policy (PSP) by vSphere Client, but how you can set up 100 LUNs manually? We have some script can make your life easy.
Continue reading “How to retrieve or set Path Selection Policy by vCLI”
Continue reading “如何使用vCLI获取或设定路径选择策略”
Continue reading “如何使用PowerCLI获取物理RDM LUN的路径选择策略”
I wrote a post about how to integrate PowerCLI with PowerShell manually. I rebuilt my computer few days ago, need to integrate PowerCLI again. I used to scripting by PowerGUI, but something always lead to PowerGUI lost menu, it frustrated me a long time. I cannot figured out what’s the root cause. So I wondered is it possible use PowerShell ISE instead of PowerGUI?
Continue reading “How to integrate PowerCLI with PowerShell and PowerShell ISE”
I like automition/programming as much as I like Windows, my first offical training in University was VB, then I learned PHP and HTML after graduated. I can’t believe my first PHP program was welcomed in internel. But I stopped develop the skill.
I got lot of special request for virtual environment. Some people want to monitor snapshot, some want to check space status, and some request to create backup for VM…etc. Regular operation cannot satisify the requests, most of the requests are time consuming operation. Automation can save my ass. :-)
You may know PowerCLI – VMware automation product for PowerShell. If you put PowerCLI scripts as scheduled task, you will be able to do any workflow you want by schedule.
But there is a problem stuggled me for a long time. The scheduled PowerCLI script is instable, sometimes script ran very well, sometimes script ran extremely slow, sometimes script hung, or sometimes script unexpected stopped. In troubelshooting I noticed it need a long waiting time (maybe 5 – 10 mintues) till execute first line of script when I ran it on Scheduled Task Window. Initially I thought it’s a bug of PowerShell 2.0. I upgraded to 3.0 but no lucky. I also suspected loading PowerCLI Snap-in may slow down the script exectue time, or bugs on PowerCLI components, tried to google but nothing was found.
Finally my colleague Amnon gave my some idea, he asked me change the scheduled taks priority. I figured out the trick after did some testing:
- Create a task as usual.
- Export the taks to a xml file.
- Open the xml file by editor.
- Search keyword priority.
- Change the default value 7 to 3. ( More detail about priority of Scheduled Task )
- Save the xml file and delete created task.
- Import the xml as a task.
It signaficantly improved the executive time! Same script was 2 hours, now only 10 minutes!
Here is my another post ($array.count does not show anything in PowerCLI) regarding a bug of PowerShell, it may helpful for your PowerCLI script.