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...
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
Which versions of PowerShell and PowerCLI are you using?
Did you do a recent update of PowerCLI? Or PowerShell?
Did you stop/start your PowerShell session from which you start the scripts?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerShell: 10.0.14393.0
PowerCLI: 10.1.0.8403314
I haven't updated anything, and only about half my scripts are failing.
I have rebooted the script server entirely. Issue still continued.
Thank you for your help so far!
That PowerShell version seems odd.
Check what is in $PSVersionTable.
Can you do this and check the versions fo the PowerCLI modules?
Select Name,Version
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Very sorry I ran a different command, but this is the version I get:
Name Value
---- -----
PSVersion 5.1.14393.2273
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2273
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
VMware.DeployAutomation 6.7.0.8250345
VMware.ImageBuilder 6.7.0.8250345
VMware.PowerCLI 10.1.0.8403314
VMware.Vim 6.7.0.8343295
VMware.VimAutomation.Cis.Core 10.1.0.8377811
VMware.VimAutomation.Cloud 10.0.0.7893901
VMware.VimAutomation.Common 10.1.0.8342134
VMware.VimAutomation.Core 10.1.0.8344055
VMware.VimAutomation.HA 6.5.4.7567193
VMware.VimAutomation.HorizonView 7.1.0.7547311
VMware.VimAutomation.License 10.0.0.7893904
VMware.VimAutomation.Nsxt 10.1.0.8346947
VMware.VimAutomation.PCloud 10.0.0.7893924
VMware.VimAutomation.Sdk 10.1.0.8342078
VMware.VimAutomation.Srm 10.0.0.7893900
VMware.VimAutomation.Storage 10.1.0.8313015
VMware.VimAutomation.StorageUtility 1.2.0.0
VMware.VimAutomation.Vds 10.1.0.8344219
VMware.VimAutomation.Vmc 10.0.0.7893902
VMware.VimAutomation.vROps 10.0.0.7893921
VMware.VumAutomation 6.5.1.7862888
VMware.DeployAutomation 6.7.0.8250345
VMware.ImageBuilder 6.7.0.8250345
VMware.PowerCLI 10.1.0.8403314
VMware.Vim 6.7.0.8343295
VMware.VimAutomation.Cis.Core 10.1.0.8377811
VMware.VimAutomation.Cloud 10.0.0.7893901
VMware.VimAutomation.Common 10.1.0.8342134
VMware.VimAutomation.Core 10.1.0.8344055
VMware.VimAutomation.HA 6.5.4.7567193
VMware.VimAutomation.HorizonView 7.1.0.7547311
VMware.VimAutomation.License 10.0.0.7893904
VMware.VimAutomation.Nsxt 10.1.0.8346947
VMware.VimAutomation.PCloud 10.0.0.7893924
VMware.VimAutomation.Sdk 10.1.0.8342078
VMware.VimAutomation.Srm 10.0.0.7893900
VMware.VimAutomation.Storage 10.1.0.8313015
VMware.VimAutomation.StorageUtility 1.2.0.0
VMware.VimAutomation.Vds 10.1.0.8344219
VMware.VimAutomation.Vmc 10.0.0.7893902
VMware.VimAutomation.vROps 10.0.0.7893921
VMware.VumAutomation 6.5.1.7862888
Looks like you have PowerCLI installed in 2 locations.
Possible in the C:\Program Files\WindowsPowerShell\Modules and C:\Users\<your-account>\Documents\WindowsPowerShell\Modules
Can you do
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are correct, 2 locations. How can I correct this?
In the output from Get-Module -Name VMware* -ListAvailable, you'll see the directories into which the modules are installed.
You can just delete the module folders in one of those directories.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I deleted the directory and no change 😕
Next step, delete all the PowerCLI directories and do the Install-Module again.
I suspect your installation might have an issue.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did that, same result. 😕
Very strange.
Do you by any chance have another station where you can have PowerCLI installed?
Does that show the same behaviour?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ran it from my local machine and got the same error.
Both machines have the same OS?
Same patch level?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nope, one is a win16 server other is my laptop with windows 10
I'm a bit out of ideas, perhaps you should consider opening a SR for this.
And yes, you can open a SR for PowerCLI, see PowerCLI Support Breakdown
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I ran the script on a 2008 R2 server, and it seemed to run fine. It errored out on no FTP server, but the HTML page created fine.
Can you run it without that cred file?
Can the system be restored to a time when you know the script was running?
I did remove the .xml file and still no success. I am wondering if I installed powercli wrong, I must admit I really struggled when the simple install file method was removed and the sleek update/install method was put in place. I just feel old and dumb for not getting it.
Did you use Install-Module or Save-Module?
Did you follow the instructions in Welcome PowerCLI to the PowerShell Gallery – Install Process Updates
Are you using any VICredentialStoreItem cmdlets?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did the Install-Module and looked it over and seems to be same as what I did. I am not using that command in my scripts.