0

I am getting an error on very few occasions while running the below script. I have written the script to get the data from an SCVMM server and copy it to a CSV file. This script is runing in every 15 minutes. we have scheduled this using our scheduler. But the issue here is that sometimes it is throwing below warning and it is not copying the required data to the CSV file. Most of the time it is running. Very few instances it is throwing an error:

Get-SCCloud : VMM is unable to connect to the VMM management server calo-infvmm-01.calocosn.local because the specified computer name could not be resolved.

2016-05-15 19:01:30,334 INFO  running system command: C:\cc-working\scripts\PowerShell\VMHours\Sydney\GetStorageDetails.bat -d 20160515 > C:\cc-working\usage_files\VMUphours\Sydney\Output\VMHours_20160515.csv
2016-05-15 19:01:33,874 WARN  Get-SCCloud : VMM is unable to connect to the VMM management server 
2016-05-15 19:01:33,874 WARN  calo-infvmm-01.calocosn.local because the specified computer name could not be 
2016-05-15 19:01:33,890 WARN  resolved. (Error ID: 1601)
2016-05-15 19:01:33,890 WARN
2016-05-15 19:01:33,890 WARN  Ensure that the computer name is correct, and then try the operation again. If 
2016-05-15 19:01:33,890 WARN  the problem persists, contact your network administrator.
2016-05-15 19:01:33,890 WARN  At C:\cc-working\scripts\PowerShell\VMHours\Sydney\usage.ps1:7 char:11
2016-05-15 19:01:33,890 WARN  + $clouds = Get-SCCloud -VMMServer $VMMServer
2016-05-15 19:01:33,890 WARN  +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2016-05-15 19:01:33,890 WARN      + CategoryInfo          : ReadError: (:) [Get-SCCloud], CarmineException
2016-05-15 19:01:33,890 WARN      + FullyQualifiedErrorId : 1601,Microsoft.SystemCenter.VirtualMachineManage 
2016-05-15 19:01:33,890 WARN     r.Cmdlets.GetSCCloudCmdlet
2016-05-15 19:01:34,373 INFO  command completed successfully with an exit value of '0'
2016-05-15 19:01:34,389 INFO  reader charset from auto-detect: ASCII
2016-05-15 19:01:34,389 INFO  INPUT: file [C:\cc-working\usage_files\VMUphours\Sydney\Output\VMHours_20160515.csv]
2016-05-15 19:01:34,404 INFO  collection feed: Sydney-VMHours-Collection

Below is my script:

$VMMServer = "calo-infvmm-10001.calocosn.local"
$a = ((Get-Date).ToUniversalTime()).ToString("yyyyMMddTHHmmss")

$clouds = Get-SCCloud -VMMServer $VMMServer

$vmHeader = [string]::Concat("VMId",",","SubscriptionId",",","VMName",",","OperatingSystem",",","Memory(MB)",",","CPUCount",",","DiskUsed(GB)",",","DiskAllocated(GB)",",","StorageClassification",",","Owner",",","CreationTime",",","SampleTime",",","Status",",","StartAction",",","StopAction")
Write-Output $vmHeader

foreach ($cloud in $clouds) {
    $VMs = Get-SCVirtualMachine -Cloud $cloud
    foreach ($VM in $VMs) {
        $size = 0
        $maxSize = 0
        $classification = "Standard"
        foreach ($disk in $VM.VirtualHardDisks) {
            $classification = $disk.Classification
            $size += $disk.Size / 1gb

            $parentDisk = $disk.ParentDisk
            while ($parentDisk) {
                $size += $parentDisk.Size / 1gb
                $parentDisk = $parentDisk.ParentDisk
            }

            $maxSize += $disk.MaximumSize / 1gb
        }
        $vmText = [string]::Concat($vm.ID,",",$vm.UserRoleID,",",$vm.Name,",",$vm.OperatingSystem,",",$vm.Memory,",",$vm.CPUCount,",",$size,",",$maxSize,",",$classification,",",$vm.Owner,",",$vm.CreationTime,",",$a,",",$vm.Status,",",$vm.StartAction,",",$vm.StopAction)
        Write-Output $vmText
    }
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Hemant
  • 49
  • 1
  • 8
  • *"VMM is unable to connect to the VMM management server [...] because the specified computer name could not be resolved."* What exactly don't you understand about the error message? Apparently you have intermittent name resolution issues. BTW, the .local TLD is reserved for mDNS nowadays so it shouldn't be used for regular DNS. – Ansgar Wiechers May 17 '16 at 11:36
  • Hi Thanks for your reply.. But this script is scheduled in every 15 mins.in a day it is producing 96 files ( 24 hr) but some times it is throwing above error. it is not always throwing.. so script is working fine but few occasion it is failing... – Hemant May 17 '16 at 12:53
  • So? What is that supposed to change about the obvious facts? – Ansgar Wiechers May 17 '16 at 12:56
  • i am not able to understand your questions . Please elaborate. – Hemant May 18 '16 at 05:20
  • You. Have. Intermittent. Name resolution. Failures. What don't you understand about this? It's not a PowerShell or programming issue. Go check your DNS, your network, and your local system for things that may cause these failures. – Ansgar Wiechers May 18 '16 at 13:37

0 Answers0