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