FMON's Accepted Solutions

Like DZ1 was saying, you can use the credential store.  An alternative way to store your credentials to the credential store is by using the -SaveCredentials switch when calling the Connect-VISer... See more...
Like DZ1 was saying, you can use the credential store.  An alternative way to store your credentials to the credential store is by using the -SaveCredentials switch when calling the Connect-VIServer cmdlet. Connect-VIServer -Server "server1","server2","server3" -Credential $(Get-Credential) -SaveCredentials Keep in mind that any method that uses the credential store is not very secure as the credentials in the credential store are stored on disk using reversible encryption!  Somebody who knows what they're doing can extract the credentials if they gain access to the credential store on disk. LucD's method of storing your creds in a variable is more secure since most of the time that will stay in memory.  Keep in mind that even with Get-Credential, your password is stored in memory with reversible encryption.  Still can be compromised but it's more difficult. Bottom line:  if this is a scheduled thing that needs to run, the credential store is probably (unfortunately) the way to do this.  if this is for an interactive session, then storing in a variable is more secure. Would be nice if this Connect-VIServer could use the session user as previous PowerCLI versions did.  If someone know how please share! EDIT: final thought: if you use the -SaveCredentials switch with Connect-VIServer as shown above, the next time you can connect without specifying -Credential.  For example you can just do this the next time: Connect-VIServer -Server "server1","server2","server3" If your password changes then you'll need to use -SaveCredentials again.
Here is what I was saying about the $orphanSize = 0 foreach ($vCenter in $vCenters) {   $orphanSize = 0   #   <<< since you want to tally orphan size per vcenter, for each vcenter you n... See more...
Here is what I was saying about the $orphanSize = 0 foreach ($vCenter in $vCenters) {   $orphanSize = 0   #   <<< since you want to tally orphan size per vcenter, for each vcenter you need to set it back to zero     $Report= @()   $arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}   Get-View -ViewType Datastore -Property Name,Browser,Host | %{   $ds = $_     $dsBrowser = Get-View $ds.browser     $rootPath = "[" + $ds.Name + "]"     $searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec -property @{matchPattern="*.vmdk";details=New-Object VMware.Vim.FileQueryFlags -property @{filesize=$true;modification=$true} }     $searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)     foreach ($folder in $searchResult) {       foreach ($fileResult in $folder.File) {         if ($fileResult.Path -match "-flat.vmdk"-and ($fileResult.Modification -lt $DaysOld)) {           if (-not ($arrUsedDisks -contains ($folder.FolderPath + $fileResult.Path))){             $orphanSize += $fileResult.FileSize             $row = "" | Select DataStore, Path, ProbablyOrphanedFile, SizeGB, LastModifiedOn, Host             $row.DataStore = $ds.Name             $row.Path = $folder.FolderPath             $row.ProbablyOrphanedFile = $fileResult.Path             $row.SizeGB = [math]::Round($fileResult.FileSize/1GB,1)             $row.LastModifiedOn = $fileResult.Modification             $row.Host = (Get-View $ds.Host[0].Key).Name             $report += $row           }         }       }     }   }   #also the following 5 lines were originally not part of your foreach vcenter loop   $ovmdkscount = $report.Count   $totalorphanedspace = ([Math]::Round($orphanSize/1GB,1))   $report | ConvertTo-Html –title "$vCenter - Orphaned VMDK Report" –body "<H2>$vCenter - Orphaned VMDK Report</H2>" -head $Header | Out-File $BasePath\$Date\$vCenter-OrphanedVMDKs-$Date.htm   $text = "$vCenter has got $ovmdkscount Orphaned VMDKs - Total Orphaned Space that could be reclaimed is $totalorphanedspace GB"   $text | Out-File $BasePath\$Date\ReportedvCentersStatus.txt -Append -Force } Not sure if that will solve your problem or not but that was a problem. Alternatively you could add this to each of your rows: $row.SizeBytes = $fileResult.FileSize and then calculate the total size at the end: $otherTotalOrphanedSpace = $report | Measure-Object -sum -property SizeBytes | select -expand Sum | foreach { [Math]::Round($_ / 1GB, 1) }