VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

Scripts Failing Suddenly

I have had a number of scripts fail recently, I run the script manually and here is the script and output:

#############################

# Connect to vCenter        #

#############################

Start-Transcript -Path 'C:\Temp\script.log'

Import-Module -Name VMware.PowerCLI

Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false

$vc = 'DNS'

$Cred = Import-Clixml C:\util\Scripts\creds\autoitjob.xml

Connect-VIServer $VC -Credential $Cred

#############################

#         Variables         #

#############################

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\Thin-$date.htm"

#############################

#          Content          #

#############################

$report = Get-VM | Get-HardDisk | where {$_.StorageFormat -ne "Thin"} | select Parent,StorageFormat,Filename

#$report = Get-VM | Get-HardDisk |

#where {$_.StorageFormat -ne "Thin"} |

#select Parent,StorageFormat,Filename

#############################

# Add Text to the HTML file #

#############################

$report | ConvertTo-Html -title "VMware Thin Provision Check" -body "<H1>Vmware Thin Provision Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation

ConvertTo-Html -title "VMware Thin Provision Check" -body "<H4>Date and time </H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

ConvertTo-Html -title "VMware Thin Provision Check" -body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

######################

# FTP HTML output #

#####################

#we specify the directory where all files that we want to upload 

$Dir="$filelocation"

#Below for test

#$Dir="C:/Users/administrator/Desktop/tmp/"   

#ftp server

$ftp = "ftp://IP/internal-backups/datacenter/vcenter/misc-reports/Thin/"

$user = "USER"

$pass = "PW" 

$webclient = New-Object System.Net.WebClient

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 

#list every sql server trace file

foreach($item in (dir $Dir "*.bak")){

    "Uploading $item..."

    $uri = New-Object System.Uri($ftp+$item.Name)

    $webclient.UploadFile($uri, $item.FullName)

}

##############################

# Disconnect session from VC #

##############################

disconnect-viserver -confirm:$false

OUTPUT:

PS C:\util\scripts\Reports\Daily> .\ThinReport.ps1

Transcript started, output file is C:\Temp\script.log

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout

                                                                                                  Seconds

-----    -----------     ------------------- ------------------------  -------------------------- -------------------

Session  UseSystemProxy  Multiple            Ignore                    False                      300

User                     Multiple            Ignore                    False

AllUsers

IsConnected   : True

Id            : /VIServer=vsphere.local\powercli@DNS:443/

ServiceUri    : https://vcenter6.ruralnex.com/sdk

SessionSecret : "7f2930a91d58a037dd232de769e26727c3338c71"

Name          : vcenter6.ruralnex.com

Port          : 443

SessionId     : "7f2930a91d58a037dd232de769e26727c3338c71"

User          : VSPHERE.LOCAL\PowerCLI

Uid           : /VIServer=vsphere.local\powercli@vcenter6.ruralnex.com:443/

Version       : 6.5.0

Build         : 8667236

ProductLine   : vpx

InstanceUuid  : e66b929f-6e6e-4791-aafc-621177fc31b1

RefCount      : 1

ExtensionData : VMware.Vim.ServiceInstance

Get-VM : 7/9/2018 11:01:54 AM   Get-VM          Value cannot be null.

Parameter name: array

At C:\util\scripts\Reports\Daily\ThinReport.ps1:22 char:11

+ $report = Get-VM | Get-HardDisk | where {$_.StorageFormat -ne "Thin"} ...

+           ~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Uploading C:\util\Scripts\Temp\Thin-2018-Jul-9.htm...

0 Kudos
50 Replies
LucD
Leadership
Leadership
Jump to solution

Seem to be good, dead end.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

What would be the best/cleanest method to uninstall powercli completely and reinstall?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you still have an entry in Programs and Features (from a MSI install), uninstall it.

Then manually delete all VMware PowerCLI related folders in the different Modules folders.

To check which ones those are, check the content of $env:PSModulePath.

You can also check by listing all the PowerCLI modules like this

Get-Module -Name Vmware* -ListAvailable

Finally, just for good luck, reboot your PC.

Then install again with

Install-Module -Name VMware.PowerCLI


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

Did a full uninstall/reinstall and still no go.  I am wondering if its the vcenter itself as the clients have so little in common.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since you confirmed you had the same issue on multiple stations, it seems indeed to be linked to that as well.
You sure there no VM with a funny name on that vCenter?
Or ghosted entry?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

Ghosted entry? What would that be?

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

I found that there was an invalid VM hanging out after some testing went south.  I erased it and now I have scripts running again.

Thanks again for hanging with me on this!!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're welcome.
It was an intriguing issue :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
nilly
Contributor
Contributor
Jump to solution

I couldn't find any 'invalid' VMs in my vcenter, however I do have some 'inaccessible' VMs, and a few hosts that I found out have expired licenses. It will take me a while to get some licenses for the hosts but I'll update if that (or removing the inaccessible vms) fixes my issue.

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

@nilly, my VM was considered invalid so I feel that is the cause for you, but hey every case is different.

@LucD, lol glad to see I can still intrigue a master like you! :smileysilly:

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think there should be kind of a validity check available on the vCenter DB.
Not sure if that exists, but I'm not aware there is such a check.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos