vSphere 4.x Web Console – Missing VM’s

I’ve had difficulty finding this in the VMware forums and thought I’d post something on it here.

You may find that the vSphere web console is missing some VM’s. But, in the regular vSphere client, they are all there and accessible.

Chances are there’s a folder that was renamed or deleted.

In the vSphere client, select the VMs and Templates view. Expand your datacenter icon. You should have 1 folder. I believe the name should beDiscovered virtual machine“. If not, create one. Don’t do anything else. Don’t place any VM’s in that folder. Just leave it as is.

Wait several minutes and log into your vSphere web console. You should give vCenter some time to rebuild that list. If you launch the vSphere web console and the VM’s still aren’t there. Log off vSphere web console and give it some more time. Log back in and refresh if necessary.

You should be good to go after that.

If you don’t use the vSphere web console, then you don’t need that folder under the VMs and Templates view.

Password Expiration Notifications – PowerShell to the Rescue

I grappled with posting this. Google PowerShell with Password Expiration Notification and you’ll find a bunch of posts and questions. I typically don’t like to make a PowerShell blog post when there is a lot of info out there.

So a little background. Microsoft changed the behavior of how users receive system based messages. That’s all fine and dandy I guess. In this case, I think what they did was a mistake when Windows 7 is in an Active Directory domain. If a GPO is in place to notify users of expiring passwords, often times they never see the message in the notification center.

Instead of receiving a dialogue box which makes it obvious to the users that their password is expiring, the message shows up in the notification area. Most users don’t pay attention to the notification area. And, it’s not customizable enough to force password notifications to be more prevalent.

There are a few possibilities here. You can write a PowerShell script that runs on demand, or is a scheduled task, which can email notifications to your users. There are a few examples of this out there using a variety of methods to email users. However, I don’t like this approach.

What if someone on your staff, in the future, decides they want to modify the email content or the script in any way? Like it or not, there are still a lot of people who have NOT jumped on board with PowerShell.

My alternate solution is still PowerShell based.

Wait, didn’t I just say… ? Yes, I did. The script I put together is more of a static script that (potentially) wouldn’t necessarily need changes. The script is run as a scheduled task and runs on a weekly basis. The script itself will look for expiring passwords in the next 14 days and send an HTML report to a distribution list. In my case, the distribution list members are help desk technicians. They use the report to be little proactive in speaking with managers or other important internal customers who might show up on this list allowing them to be aware of who they may be receiving calls from.

Instead of including the style sheet as an external document, the information is small enough and was included it in the script itself.

The script is relatively simple. Please realize that this was a quick script using one that Richard Siddaway posted in 2007. There are more dynamic and efficient ways to do what’s in this script. But, to get the job completed quickly to meet our needs, this is what I came up with.

I convert the csv to html so I can send the converted csv as html in the body of the email.

Giving credit where credit is due, many thanks to Richard Siddaway and Richard L. Mueller for some ideas from their blogs. The base of the script is pretty much Richard Siddaway’s script modified to meet my needs.

Also a note, since we’re dealing with objects here this line is important:

import-csv $Filename | ConvertTo-Html -Title "Password Expiration Report" -head $style | Out-File $FilenameHTML
$Body = Get-Content $FilenameHTML | Out-String

I used this simple trick be2cause with send-mailmessage you can’t send an object as an attachment.

# The "base" for this script is from Richard Siddaway
# http://richardspowershellblog.wordpress.com/2007/10/07/password-expiry/</code>

# Need requires 2.0 since it's using the send-mailmessage cmdlet
#requires -version 2
write-host "Requires PowerShell v2 because of the use of the send-mailmessage cmdlet."

#Test for QAD Snapin
$TestQADSnapin = get-pssnapin | where { $_.Name -eq "Quest.ActiveRoles.ADManagement"}
if($TestQADSnapin -eq $null){
Write-Host "Requires ActiveRoles Management Shell for Active Directory http://www.quest.com/powershell/activeroles-server.aspx"
add-pssnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue

# Create date for filename
$date = get-date -Format MM-dd-yyyy
$Filename = "c:\temp\PasswordsExpireReport-$date.csv"
$FilenameHTML = "c:\temp\report.html"

#create base CSV
Add-Content $Filename "Last Name, First Name, Username,Password Expires in (days)"

$date = Get-Date
## get the Domain Policy for the maximum password age
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()

## get the account policy
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(objectclass=domainDNS)"
$result = $search.FindOne()

## maximum password age
$t = New-Object System.TimeSpan([System.Math]::ABS($result.properties["maxpwdage"][0]))

## want all accounts where password will expire in next 7 days
## ie password was set (max password age) – 7 days ago
$d = ($t.Days)* -1 ## max password age days ago
$d1 = $d + 14 ## 7 days on from max password age

$ExpiringPasswords = Get-QADUser -SizeLimit 0 -IncludedProperties FirstName, LastName, SamAccountName, pwdLastSet, PasswordExpires, PrimarySMTPAddress | where {($_.PwdLastSet -gt (Get-Date).AddDays($d)) -and ($_.PwdLastSet -lt (Get-Date).AddDays($d1)) -and ($_.PasswordExpires) -and ($_.memberof -ne "CN=Service Account,CN=Users,DC=contoso,DC=com") -and -not ($_.AccountIsDisabled) } | select FirstName, LastName, SamAccountName, pwdLastSet, PasswordExpires, PrimarySMTPAddress

foreach ($user in $ExpiringPasswords | sort PasswordExpires){
$DaysLeft = (($user.PasswordExpires - $date).Days)
$Username = $User.SamAccountName
$FirstName = $User.FirstName
$LastName = $User.Lastname
Add-Content $Filename "$LastName, $FirstName, $Username, $DaysLeft"

$style = "
BODY{background-color:white;} TABLE{border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;} TH{border-width: 1px; padding: 2px; border-style: solid; border-color: black; background-color:#C0C0C0} TD{border-width: 1px; padding: 2px; border-style: solid; border-color: black; background-color:white} "

import-csv $Filename | ConvertTo-Html -Title "Password Expiration Report" -head $style | Out-File $FilenameHTML
$Body = Get-Content $FilenameHTML | Out-String
$From = "IT Automated Messages "
$To = "helpdesk@contoso.com"
send-mailmessage -SmtpServer "smtprelay.contoso.com" -to $To -from $From -subject "Expired Password Report for $date" -body $Body -BodyAsHtml

if (test-path $Filename){
Remove-Item $Filename -Force

if (test-path $FilenameHTML){
Remove-Item $FilenameHTML -Force

Powershell and Wireshark

This links in to another post I had: http://trwagner1.blogspot.com/2010/03/using-powershell-with-process-monitor.html

We recently had a need to provide Wireshark logs for a support incident on an issue that was quite random. One of the problems with Wireshark when you leave it run for any period of time is the pcap files can be quite large in size. Also, after running Wireshark for a long period of time, it will eat up a lot of resources and several instances of the dumpcap.exe process are left running.

The script below isn’t 100% polished or perfected as I didn’t have a whole lot of time to dedicate to it. I borrowed some quick script functions from others here as well.

This ran as a scheduled task on a Windows 2008 R2 server. In order to do so, a profile.ps1 had to be set up for the account used to run the scheduled task and an execution policy had to be set up. The script runs every 2 hours and creates a new pcap file each new run.

Command line: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
Arguments: -nologo \\scriblib\start-WireShark.ps1

# start-WireShark.ps1
# Ted Wagner
# 12/22/2011

# Install WireShark. Run wireshark.exe -D to find device names and place in script

# Requires the use of Windows Sysinternals handle.exe to check for open files
# http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

# Logstamp function by Jeffery Hicks
# http://jdhitsolutions.com/blog/2006/05/create-timestamp-log-in-powershell/
function logstamp {
$now = get-Date
$yr = $now.Year.ToString()
$mo = $now.Month.ToString()
$dy = $now.Day.ToString()
$hr = $now.Hour.ToString()
$mi = $now.Minute.ToString()
if ($mo.length -lt 2) {
$mo = "0"+$mo #pad single digit months with leading zero
if ($dy.length -lt 2) {
$dy = "0"+$dy #pad single digit day with leading zero
if ($hr.length -lt 2) {
$hr = "0"+$hr #pad single digit hour with leading zero
if ($mi.length -lt 2) {
$mi = "0"+$mi #pad single digit minute with leading zero
write-output $yr$mo$dy$hr$mi


# Kill WireShark Process first
Start-Sleep -seconds 2
$ProcMonTestProcess = Get-Process | where {$_.ProcessName -eq "wireshark"}
if ($ProcMonTestProcess){
Stop-Process $ProcMonTestProcess.Id}
$ProcMonTestProcess.Id -eq $true

# Kill any dumpcap.exe processes
Start-Sleep -seconds 2
$ProcMonTestProcess = Get-Process | where {$_.ProcessName -eq "dumpcap"}
if ($ProcMonTestProcess){
Stop-Process $ProcMonTestProcess.Id}
$ProcMonTestProcess.Id -eq $true

$WireShark = "E:\Program Files\Wireshark\wireshark.exe"
$HandleExe = "\\server\tools\Utilities\Sysinternals\handle.exe"

# Start WireSharp, capture immediately and provide file name
# make sure to have the correct device name below. I suppose a script could be written to gather and provide this automatically but I didn't
# have a lot of time to spend on this script and grabbed the value using "wireshark -D"
&amp; $WireShark -i '\Device\NPF_{17B9CF31-0C9F-4C57-92AF-09294FB634F5}' -k -w "\\server\share\wireshark\Wireshark-Output-$(logstamp).pcap"

# Error Handling
Write-Host "Exception: " + $_.Exception.Message
Writing & Editing
Code » Posting Source Code

Code, Embed, Languages, php, programming, Shortcode

    Configuration Parameters


    404 Not Found error
    Archives Shortcode
    Contact Form
    Copy a Post
    Deleted Posts and Pages
    Distraction Free Writing
    Editing With Multiple Authors
    Featured Images
    Memolane Embed
    Microsoft Word
    Missing Visual Editor
    Offline Editing
    Plinky: A Tool for Writer’s Block
    Post by Email
    Post by Voice
    Post vs. Page
    Press This
    Request Feedback
    Splitting Content
    Twitter Follow Button
    Visual Editor
    Write a Book
    Writing and Formatting Poetry
    Writing Helper

While WordPress.com doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:
1	#button {
2	    font-weight: bold;
3	    border: 2px solid #fff;
4	}

To accomplish the above, just wrap your code in these tags:

your code here