1 2 Previous Next 17 Replies Latest reply on Jun 5, 2019 4:31 AM by Vineeth

    issue with scriptoutput while using invoke-vmscript

    Vineeth Hot Shot

      I am seeing different outputs for few set of vms.

      If i execute the script(Code present in $script) from inside the guestos and from outside using invoke-vmscript then the two outputs are different.

      Can some one pls correct the flaw in the script.

      Here is the script-

      $Script=
      @'
      if([IntPtr]::Size -eq 8){
          $text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
              %{"$($_.AgentGUID) and ePOServerList is $($_.ePOServerList)"}
      }
      elseif([IntPtr]::Size -eq 4){
          $text = Get-ItemProperty -Path "HKLM:\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
              %{"$($_.AgentGUID) and ePOServerList is $($_.ePOServerList)"}
      }
      if(-not $text){
          $text = Get-Service -Name "McAfee*" -ErrorAction SilentlyContinue |select -First 1 | %{"$($_.Name) is $($_.Status)"}
          if(-not $text){
              $text = "McAfee Not Installed"
          }
      }
      $cbstatusinfo= "CarbonBlack Not Installed"
      $cbout = Get-Service -Name "CarbonBlack" -ErrorAction SilentlyContinue
      if($cbout){
      $cbstatusinfo = "$($cbout.name -join ',') installed"
      }
      $wuserv= Get-Service -Name "wuauserv" | Select -first 1 | %{"$($_.Name) is $($_.Status)"}
      $windowsUpdateObject= New-Object -ComObject Microsoft.Update.AutoUpdate
      $wup= $windowsUpdateObject.Results
      $windowsupdateresult= "LastSearchSuccessDate is $($wup.LastSearchSuccessDate) and LastInstallationSuccessDate $($wup.LastInstallationSuccessDate)"
      $hotfix = "KB4012598", "KB4012598", "KB4012598", "KB4012598", "KB4012212", "KB4012215", "KB4012212", "KB4012215", "KB4012213", "KB4012216", "KB4012214", "KB4012217", "KB4012213", "KB4012216", "KB4012606", "KB4013198", "KB4013429", "KB4013429"
      $val = Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters -Name "SMB1" -ErrorAction SilentlyContinue
      $fixes = Get-WmiObject -Class "win32_quickfixengineering" | where{$hotfix -contains $_.HotFixID} | Select -ExpandProperty HotFixID
      if($fixes){
          $hotfixinfo = "$($fixes -join ',') installed"
      }
      elseif($fixes -eq $null -and $wup.LastSearchSuccessDate -ge (Get-Date 12-03-2017) ){
      $hotfixinfo= "$("KB4012598" -join ',') installed"
      }
      elseif($fixes -eq $null -and $val.SMB1 -eq 0){
      $hotfixinfo= "$("KB4012212" -join ',') installed"
      }
      else{
      $hotfixinfo = "No hotfix found!" 
       }
      $outputarray=@()
      $outputarray+=$hotfixinfo
      $outputarray+=$cbstatusinfo
      $outputarray+=$text
      $outputarray+=$wuserv
      $outputarray+=$windowsupdateresult
      $outputarray -join ','
      '@
      #$vm=Get-VM 'AJDBServer (f2c5ae1c-f84b-4c83-9202-7a1a484314c8)'
      Invoke-VMScript -VM 'AJDBServer (f2c5ae1c-f84b-4c83-9202-7a1a484314c8)' -GuestUser 'admin' -GuestPassword '' -ScriptText $Script -ScriptType Powershell
      
      

      Out Put :

       

       

      If I execute the code which in present in $script inside the guest OS for the same vm then the output is different.

       

      Here is the output from inside the guest os

       

      Regards
      Vineeth.K
        1 2 Previous Next