1 2 3 Previous Next 33 Replies Latest reply on Nov 11, 2019 10:30 PM by LucD Go to original post
      • 15. Re: Disk consolidation script -- Need help testing
        vmk2014 Hot Shot

        PS D:\vmk> .\consolidate-Disk.ps1

        D:\vmk\report.txt : The term 'D:\vmk\report.txt' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was

        included, verify that the path is correct and try again.

        At D:\vmk\consolidate-Disk.ps1:1 char:13

        + $logPaths = D:\vmk\report.txt

        +             ~~~~~~~~~~~~~~~~~~~

            + CategoryInfo          : ObjectNotFound: (D:\vmk\report.txt:String) [], CommandNotFoundException

            + FullyQualifiedErrorId : CommandNotFoundException

         

         

        Out-File : Cannot bind argument to parameter 'FilePath' because it is null.

        At D:\vmk\consolidate-Disk.ps1:10 char:57

        + ...  "$(Get-Date -Format G) : $msg" | Out-File -FilePath $logpath -Append ...

        +                                                          ~~~~~~~~

            + CategoryInfo          : InvalidData: (:) [Out-File], ParameterBindingValidationException

            + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.OutFileCommand

         

         

        Thanks

        vmk

        • 16. Re: Disk consolidation script -- Need help testing
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          My bad, there should be quotes around the filename

          • 17. Re: Disk consolidation script -- Need help testing
            vmk2014 Hot Shot

            You mean it should be D:\vmk\"report.txt"  ?

             

            Also, report it will be output file ?

             

            Thanks

            vmk

            • 18. Re: Disk consolidation script -- Need help testing
              vmk2014 Hot Shot

              LucD,

               

              Tried with quote, but still shows an error.

               

              D:\vmk\report.txt : The term 'D:\vmk\report.txt' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was

              included, verify that the path is correct and try again.

              At D:\vmk\consolidate-Disk.ps1:1 char:13

              + $logPaths = D:\vmk\'report.txt'

              +             ~~~~~~~~~~~~~~~~~~~~~

                  + CategoryInfo          : ObjectNotFound: (D:\vmk\report.txt:String) [], CommandNotFoundException

                  + FullyQualifiedErrorId : CommandNotFoundException

               

               

              Out-File : Cannot bind argument to parameter 'FilePath' because it is null.

              At D:\vmk\consolidate-Disk.ps1:10 char:57

              + ...  "$(Get-Date -Format G) : $msg" | Out-File -FilePath $logpath -Append ...

              +      

               

              Thanks

              vmk

              • 19. Re: Disk consolidation script -- Need help testing
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                No, quotes around the complete string.
                See my updated answer earlier.

                • 20. Re: Disk consolidation script -- Need help testing
                  vmk2014 Hot Shot

                  HI Lucd,

                   

                  I did run the script after removing the quotes around the string but still same error. Script attached for you ref.

                   

                  PS D:\vmk> .\consolidate-Disk.ps1

                  D:\vmk\report.txt : The term 'D:\vmk\report.txt is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was

                  included, verify that the path is correct and try again.

                  At D:\vmk\consolidate-Disk.ps1:1 char:13

                  + $logPaths = D:\vmk\report.txt

                  +             ~~~~~~~~~~~~~~~~~~~

                      + CategoryInfo          : ObjectNotFound: (D:\vmk\report.txt:String) [], CommandNotFoundException

                      + FullyQualifiedErrorId : CommandNotFoundException

                   

                   

                  Out-File : Cannot bind argument to parameter 'FilePath' because it is null.

                  At D:\vmk\consolidate-Disk.ps1:10 char:57

                  + ...  "$(Get-Date -Format G) : $msg" | Out-File -FilePath $logpath -Append ...

                  +                                                          ~~~~~~~~

                      + CategoryInfo          : InvalidData: (:) [Out-File], ParameterBindingValidationException

                      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.OutFileCommand

                   

                   

                  Type Value

                   

                  is it possible to modify attached script.

                   

                  Thanks

                  vmk

                  • 21. Re: Disk consolidation script -- Need help testing
                    LucD Guru
                    vExpertCommunity WarriorsUser Moderators

                    There should be quotes around the full filename, as I mentioned in Re: Disk consolidation script -- Need help testing

                    • 22. Re: Disk consolidation script -- Need help testing
                      vmk2014 Hot Shot

                      LucD,

                       

                      I tried the script suggested but it keeps showing in log.

                       

                      11/8/2019 12:55:32 PM : Cannot connect to $vCenter

                      11/8/2019 12:55:36 PM : Cannot connect to $vCenter

                      11/8/2019 12:58:09 PM : Cannot connect to $vCenter

                      11/8/2019 12:58:13 PM : Cannot connect to $vCenter

                      11/8/2019 1:05:20 PM : Cannot connect to $vCenter

                      11/8/2019 1:05:24 PM : Cannot connect to $vCenter

                      11/8/2019 1:06:58 PM : Cannot connect to $vCente

                       

                      i got prompted for vcenter credential and i entred the credential

                       

                      Thanks

                      vmk

                      • 23. Re: Disk consolidation script -- Need help testing
                        LucD Guru
                        vExpertCommunity WarriorsUser Moderators

                        Did you initialise the $vcenters variable somewhere in your script?
                        It should contain the names of the vCenters for which you want to consolidate the VM disks.

                        • 24. Re: Disk consolidation script -- Need help testing
                          vmk2014 Hot Shot

                          Yes, like this

                           

                          $vCenters = @('XXXX', 'YYYY')

                           

                          replaced - $vCenters = @('my vc', )

                          • 25. Re: Disk consolidation script -- Need help testing
                            LucD Guru
                            Community WarriorsUser ModeratorsvExpert

                            Do you really have that comma after the 1st VC name?

                            • 26. Re: Disk consolidation script -- Need help testing
                              vmk2014 Hot Shot

                              LuCd,

                               

                              No comma after VC. Right now only one VC, i'm trying to connect.

                               

                              Thanks

                              vmk

                              • 27. Re: Disk consolidation script -- Need help testing
                                vmk2014 Hot Shot

                                LucD,

                                 

                                In log still shows cannot connect vcenter but in console output

                                 

                                Cannot compare "VM00M967" because it is not IComparable.

                                At D:\vmk\consolidate-Disk2.ps1:78 char:7

                                +   if ($VMsNeedingConsolidation -gt 0){

                                +       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

                                    + FullyQualifiedErrorId : NotIcomparable

                                 

                                 

                                Thanks

                                vmk

                                • 28. Re: Disk consolidation script -- Need help testing
                                  LucD Guru
                                  Community WarriorsUser ModeratorsvExpert

                                  I don't see that line in the last script you attached.

                                  • 29. Re: Disk consolidation script -- Need help testing
                                    vmk2014 Hot Shot

                                    I have vcenter ip address, might that is causing issue but np difference. Attaching entire script

                                     

                                    $vCenters = $vCenters = @('10.x.x.78')

                                     

                                     

                                    $logpath = "$env:D\vmk\VM_Consolidation.log"

                                     

                                     

                                    ############

                                     

                                     

                                     

                                    <#

                                     

                                     

                                    .SYNOPSIS

                                     

                                     

                                    Logs messages to a file

                                     

                                     

                                    .DESCRIPTION

                                     

                                    Receives messages and logs them to an output file.

                                     

                                     

                                     

                                    .PARAMETER msg

                                     

                                     

                                    The message to be written

                                     

                                     

                                     

                                     

                                    .EXAMPLE

                                     

                                     

                                    Write-Log 'Write this to the logfile'

                                     

                                     

                                     

                                     

                                    .NOTES

                                     

                                     

                                    Requires $logfile to be configured as the path to the output log file

                                     

                                     

                                    #>

                                     

                                     

                                    function Write-Log {

                                     

                                     

                                      param($msg)

                                     

                                     

                                      "$(Get-Date -Format G) : $msg" | Out-File -FilePath $logpath -Append -Force

                                     

                                     

                                    }

                                     

                                     

                                     

                                    foreach ($vCenter in $vCenters) {

                                     

                                     

                                      try {

                                     

                                     

                                       Connect-VIServer $vCenter -ErrorAction Stop

                                     

                                     

                                      } catch {

                                     

                                     

                                       Write-Log 'Cannot connect to $vCenter'

                                     

                                     

                                      }

                                     

                                     

                                    }

                                     

                                     

                                     

                                     

                                    if ($Global:DefaultVIServers.Count -gt 0) {

                                     

                                     

                                      $VMsNeedingConsolidation = Get-VM | Where-Object {$_.ExtensionData.Runtime.consolidationNeeded}

                                     

                                     

                                     

                                     

                                      if ($VMsNeedingConsolidation -gt 0){

                                     

                                     

                                       Write-Log "VMs needing consolidation: $VMsNeedingConsolidation"