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...