今天抓Snapshot快照大小时发现输出值太长了,类似这张图。

My IT Adventure
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.
首先,这篇文章不是关于PowerCLI的。也许你知道用vSphere Client可以设置LUN的路径选择策略,但是如果需要修改100个LUN呢?脚本可以轻松搞定。
获取RDM磁盘信息是一件很磨人的事儿,如果你很仔细你就需要把每台都检查一遍以确保信息是一致的。研究出来两行命令,可以批量获取RDM磁盘信息。
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?
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:
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.
I developed a script to take snapshot on VM and delete older snapshot regularly. I used variable $snapshots to receive data from Get-Snapshot command, then determine how many existing snapshots according to return of $snapshots.count. Somehow the script always ran incorrect behavior. When I deep looked into $snapshots, I found a interesting things.
Computer A, $snapshots.count return nothing if no, or one snapshot received.
Computer B, $snapshots.count returned 0 if no, or returned 1 if one snapshots received.
Then I checked out $PSVersionTable, found computer A powershell version is 2.0, B is 3.0, looks like this is a bug in 2.0.
The issue got fixed after upgrade to 3.0, one more benefit is I got performance improve to load PowerCLI components after upgrading.
You could install Widnows Management Framework 3.0 to upgrade PowerShell. I tested it on PowerCLI 5.5 Update1.
It’s busy month, I haven’t update my blog since I back from Phuket with my wife. I’m running into multiple projects, a little overload.
Just a quick share, my storage team ask me provide WWPN of all hosts to do a health check. it’s nightmare to pull out the data from vSphere client or web client. Just found a way to get it.
Get-VMHost -Location | Get-VMHostHBA -type fibrechannel | select VMHost,Device,@{N=”WWPN”;E={“{0:X}” -f $_.PortWorldWideName}}
Especially “{0:X}” -f $_.PortWorldWideName}
{0:X} is format, check out here to find more.
-f is kind of pipeline.
$_.PortWorldWideName is the value you want to convert.
1. create a file with name “Profile.ps1” under %windir%system32WindowsPowerShellv1.0profile.ps1
2. Add following content to the file.
# Adds the base cmdlets
Add-PSSnapin VMware.VimAutomation.Core
# Add the following if you want to do things with Update Manager
#Add-PSSnapin VMware.VumAutomation
# This script adds some helper functions and sets the appearance. You can pick and choose parts of this file for a fully custom appearance.
. “C:Program FilesVMwareInfrastructurevSphere PowerCLIScriptsInitialize-PowerCLIEnvironment.ps1”
You need administrator permission to create file on the system32 location.