Automation

 View Only
Expand all | Collapse all

script to check a setting in a vmx file for specific entry

life4dummies

life4dummiesNov 14, 2019 09:09 PM

  • 1.  script to check a setting in a vmx file for specific entry

    Posted Jul 24, 2013 08:51 PM

    HI Friends,

    I am wondering if it is possible to check the specific entry in VMX file through powercli script. Actually i wanted to search set of VMs which has "scsi0:1.writeThrough = "true" in VMX file. Can you guys please help me.



  • 2.  RE: script to check a setting in a vmx file for specific entry

    Posted Jul 24, 2013 09:10 PM

    You can always check the content of a VMX file by copying it to local storage on your client with the Copy-DatastoreItem cmdlet.

    Once you have the file on local storage, use Get-Content to "read" the content.



  • 3.  RE: script to check a setting in a vmx file for specific entry

    Posted Jul 25, 2013 02:24 PM

    All those VMs are running, is it possible to copy vmx file even VM is running? there are more than 100 VMs that I need to check for the scsi0:1.writeThrough = "true" entry. Is it possible to check this entry in vmx file using script like we check for advance config entry of VM?



  • 4.  RE: script to check a setting in a vmx file for specific entry

    Posted Jul 25, 2013 04:32 PM

    Yes, you can copy the VMX file while the VM is running.

    With a script it will not matter if you do it for 1 or 100 VMs.



  • 5.  RE: script to check a setting in a vmx file for specific entry

    Posted Jul 25, 2013 05:00 PM

    Thanks Luc for the help... could you please show me how to use Copy-DatastoreItem to get the VMX files



  • 6.  RE: script to check a setting in a vmx file for specific entry
    Best Answer

    Posted Jul 25, 2013 07:00 PM

    Sure, try something like this

    $vmName = "VM*"
    $tgtFolder = "C:\Temp\VMX\"
    $tgtString = 'scsi0:1.writeThrough = "true"'

    Get-VM -Name $vmName | %{
     
    $dsName,$vmxPath = $_.ExtensionData.Config.Files.VmPathName.Split()
     
    $dsName = $dsName.Trim('[]')
     
    $ds = Get-Datastore -Name $dsName
     
    New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
     
    Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder
     
    Remove-PSDrive -Name DS -Confirm:$false
    }

    Get-ChildItem -Path $tgtFolder -Filter "*.vmx" |
    Where {Get-Content -Path $_.FullName | Select-String -Pattern $tgtString} |
    Select Name

    It will display the name of each VMX file in which the string 'scsi0:1.writeThrough="True"'  is found.



  • 7.  RE: script to check a setting in a vmx file for specific entry

    Posted Jul 25, 2013 07:13 PM

    Thanks a lot Luc....it worked perfectly... Thanks a lot... :smileyhappy:



  • 8.  RE: script to check a setting in a vmx file for specific entry

    Posted Mar 10, 2021 08:00 PM

      Hi Lucd ,

     

    Can you please help if I want to make change in .VMX file using Powercli in same script ?

    I want to set one property of VM as:   uuid.action = "keep"



  • 9.  RE: script to check a setting in a vmx file for specific entry

    Posted Mar 10, 2021 08:17 PM


  • 10.  RE: script to check a setting in a vmx file for specific entry

    Posted Jul 25, 2013 04:57 PM

    Issue is, because of scsi0:1.writeThrough = "true" in vmx file for 2 HDD, whenever VM migrated to ESXi 5.1 2nd HDD disappear within OS and we have to migrate it back to ESXi 4.1 to resolve the issue. after investigation we found that those VMs were deployed using the BMC orchestrator  automation and 2 HDD was added at the time of VM deployment. Now if we remove and re-add the 2nd HDD above entry goes away from vmx file and then VM works fine on ESXi 5.1.

    Now Issue is I need to find out the VMs those have scsi0:1.writeThrough = "true" entry in VMX file so that we can remove this entry from vmx file and upgrade the HOSTS to ESXi 5.1. Our upgrade project is stuck because of this issue.



  • 11.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 14, 2019 05:31 PM

    I know this is a really old post but hopefully my reply will alert someone. Also, fair warning, I'm very bad with PowerCLI/Powershell/Scripting in general.

    I'm trying to do the same thing as OP did, but with a different target string and across my entire vSphere environment. I'm not sure if I'm just doing something wrong or if the versions of PowerCLI/PowerShell are different enough to where some parameters/variables/cmdlets are different from the original posting.

    The specific error(s) I'm running into are during the 'Copy-DatastoreItem' and 'Get-ChildItem' pieces, and both are presenting errors that my path to my datastore doesn't exist. It seems to be defaulting to a local mapped drive on my workstation, and then looking for the datastore there.

    I modified the original script to target only a single VM for testing reasons, as well as a target folder of a VSAN datastore where the VM in question currently resides.

    $vmName = "VM"

    $tgtFolder = "datastore"

    $tgtString = 'sound.virtualDev = "hdaudio"'

    In the following error message, "X:\" is the mapped drive on my workstation.

    Copy-DatastoreItem : The specified destination folder 'X:\datastore' does not exists. Use the Force parameter to force

    operation.

    At line:10 char:3

    +   Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

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

        + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], PathException

        + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Cmdlets.Provider.Exceptions.PathException,VMware.VimAutomation.ViCore.Cmdl

       ets.Commands.CopyDatastoreItem

    Get-ChildItem : Cannot find path 'X:\d_tst_cl1_vsan\VM' because it does not exist.

    At line:14 char:1

    + Get-ChildItem -Path $tgtFolder -Filter "*.vmx" |

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

        + CategoryInfo          : ObjectNotFound: (X:\datastore\VM:String) [Get-ChildItem], ItemNotFoundException

        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

    Hopefully my explanation isn't too confusing. Thanks in advance for any help!



  • 12.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 14, 2019 05:44 PM

    The problem seems to be with what you have in $tgtFolder.
    Is that a local, full path?
    In other words something like <Drive-letter>:\<FolderName>

    In that location the script will offload the VMX files.

    The 2nd error is probably a result of the 1st error.

    Since the files was not copied, there is nothing there.

    You would need to provide a bit more information on the location where you want to store the VMX files.
    And also on the DisplayName of the VM you are testing with.
    Easiest would be to provide the full script as you are using it (including your changes)



  • 13.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 14, 2019 08:35 PM

    I realize my first mistake. I thought that $tgtFolder would be the datastore that the VM(s) resided on.

    Now that I have corrected that, i'm getting two different errors that you see below.

    Copy-DatastoreItem : 11/14/2019 2:32:12 PM VimDatastore Download of file

    'https://phdvc01/folder%2fdpacsorat01%2fdpacsorat01.vmx?dcPath=DBD+DC&dsName=dxi0827_tst_cl2_lun017' failed. Error message: The

    remote server returned an error: (404) Not Found.

    At line:10 char:3

    +   Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

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

        + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], VimException

        + FullyQualifiedErrorId : Client20_StorageServiceImpl_DownloadFile_DownloadFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.C

       opyDatastoreItem

    Copy-DatastoreItem : Object reference not set to an instance of an object.

    At line:10 char:3

    +   Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

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

        + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], NullReferenceException

        + FullyQualifiedErrorId : System.NullReferenceException,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyDatastoreItem

    Full script is below. All I did was change $tgtFolder, $tgtString, and I specified a single VM as to not run it against the entire environment (yet)

    $vmName = "dpacsorat02"

    $tgtFolder = "D:\TEMP\VMX\"

    $tgtString = 'sound.virtualDev = "hdaudio"'

    Get-VM -Name $vmName | %{

      $dsName,$vmxPath = $_.ExtensionData.Config.Files.VmPathName.Split()

      $dsName = $dsName.Trim('[]')

      $ds = Get-Datastore -Name $dsName

      New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null

      Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

      Remove-PSDrive -Name DS -Confirm:$false

    }

    Get-ChildItem -Path $tgtFolder -Filter "*.vmx" |

    Where {Get-Content -Path $_.FullName | Select-String -Pattern $tgtString} |

    Select Name



  • 14.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 14, 2019 08:56 PM

    Do you actually have a '+' character in your datacentername, as the URI in the 1st error message seems to say?



  • 15.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 14, 2019 09:09 PM

    No, but there is a space in the name.



  • 16.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 14, 2019 09:30 PM

    Ok, that is probably where the '+' is coming from.


    You could have a look in the vpxd log to check if there any more clues why the Copy-DatastoreItem fails.



  • 17.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 03:25 PM

    This particular VM is on a VSAN datastore. Not sure if that would make a difference or not.



  • 18.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 03:45 PM

    Just tested this with a VM on a VSAN datastore, works as well for me.

    Does the script work for you when you test with a VM that is not on a VSAN datastore?



  • 19.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 03:53 PM

    Nope. Same error. vpxd.log shows the following. Looking into this now.

    2019-11-15T15:50:04.283Z info vpxd[04810] [Originator@6876 sub=Default opID=req=00007f84182d4e30-af] [VpxLRO] -- ERROR session[52fa64f6-1fdf-c947-9c69-6f5f997c1070]521aafb6-a7a4-bc0f-232e-6c7ac778cc09 -- datastoreBrowser-datastore-1525140 -- vim.host.DatastoreBrowser.search: vim.fault.FileNotFound:

    --> Result:

    --> (vim.fault.FileNotFound) {

    -->    faultCause = (vmodl.MethodFault) null,

    -->    faultMessage = <unset>,

    -->    file = "[dxi0827_prd_cl1_lun035]2fdpacsdicmp01"

    -->    msg = "Received SOAP response fault from [<cs p:00007f840c101220, TCP:dprd01esx08.txhealth.org:443>]: searchDatastore

    --> "

    --> }

    --> Args:

    -->

    --> Arg datastorePath:

    --> "[dxi0827_prd_cl1_lun035]2fdpacsdicmp01"

    --> Arg searchSpec:

    --> (vim.host.DatastoreBrowser.SearchSpec) {

    -->    query = (vim.host.DatastoreBrowser.Query) [

    -->       (vim.host.DatastoreBrowser.FolderQuery) {

    -->       },

    -->       (vim.host.DatastoreBrowser.Query) {

    -->       }

    -->    ],

    -->    details = (vim.host.DatastoreBrowser.FileInfo.Details) {

    -->       fileType = true,

    -->       fileSize = false,

    -->       modification = false,

    -->       fileOwner = false

    -->    },

    -->    searchCaseInsensitive = <unset>,

    -->    matchPattern = (string) [

    -->       "dpacsdicmp01\.vmx"

    -->    ],

    -->    sortFoldersFirst = <unset>

    --> }



  • 20.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:03 PM

    This is strange (and I didn't expect it in the vpxd log).

    -->    matchPattern = (string) [

    -->       "dpacsdicmp01\.vmx"

    -->    ],

    It looks as if you are doing the Get-ChildItem on the datastore.
    That should be on the folder where the VMX was downloaded.

    Can you check if the following downloads the VMX file?

    $vmName = "pacsdicmp01"

    $tgtFolder = "C:\Temp\VMX\"


    Get-VM -Name $vmName | %{

      $dsName,$vmxPath = $_.ExtensionData.Config.Files.VmPathName.Split()

      $dsName = $dsName.Trim('[]')

      $ds = Get-Datastore -Name $dsName

      New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null

      Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

      Remove-PSDrive -Name DS -Confirm:$false

    }



  • 21.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:05 PM

    It's something to do with the "%2f" getting added in there. Powershell error:

    Copy-DatastoreItem : 11/15/2019 10:00:25 AM VimDatastore Download of file

    'https://phdvc01/folder%2fdpacsdicmp01%2fdpacsdicmp01.vmx?dcPath=DBD+DC&dsName=dxi0827_prd_cl1_lun035' failed. Error message: The remote server

    returned an error: (404) Not Found.

    At D:\Scripts\SearchVMX.ps1:10 char:3

    +   Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder

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

        + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], VimException

        + FullyQualifiedErrorId : Client20_StorageServiceImpl_DownloadFile_DownloadFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyDatastoreItem

    vpxd.log message:

    2019-11-15T15:50:04.283Z info vpxd[04810] [Originator@6876 sub=Default opID=req=00007f84182d4e30-af] [VpxLRO] -- ERROR session[52fa64f6-1fdf-c947-9c69-6f5f997c1070]521aafb6-a7a4-bc0f-232e-6c7ac778cc09 -- datastoreBrowser-datastore-1525140 -- vim.host.DatastoreBrowser.search: vim.fault.FileNotFound:

    --> Result:

    --> (vim.fault.FileNotFound) {

    -->    faultCause = (vmodl.MethodFault) null,

    -->    faultMessage = <unset>,

    -->    file = "[dxi0827_prd_cl1_lun035]2fdpacsdicmp01"

    -->    msg = "Received SOAP response fault from [<cs p:00007f840c101220, TCP:dprd01esx08.txhealth.org:443>]: searchDatastore

    --> "

    --> }

    --> Args:



  • 22.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:08 PM

    I don't think so.
    The 0x2F is just a way to encode the '/' character in the URI



  • 23.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:08 PM

    It downloaded/create a dpacsdicmp01.vmx file, but it's blank.



  • 24.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:09 PM

    And is there something in the VMX file on the source datastore?



  • 25.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:13 PM

    Yep. Full of all of the normal info, including the string I'm searching for.



  • 26.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:22 PM

    Any chance I could be missing a PS module that is required, or something like that?



  • 27.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:49 PM

    What does this how?

    Get-Module -Name VMware* -ListAvailable



  • 28.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 04:52 PM

    ModuleType Version    Name                                ExportedCommands                                                                          

    ---------- -------    ----                                ----------------                                                                          

    Binary     6.5.1.5... VMware.DeployAutomation             {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...}                   

    Binary     6.5.1.5... VMware.ImageBuilder                 {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, Export-EsxImageP...

    Manifest   6.5.3.6... VMware.PowerCLI                                                                                                               

    Binary     6.5.3.6... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}                                 

    Binary     6.5.1.5... VMware.VimAutomation.Cloud          {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}                  

    Manifest   6.5.1.5... VMware.VimAutomation.Common                                                                                                   

    Binary     6.5.2.6... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostN...

    Binary     6.0.0.5... VMware.VimAutomation.HA             Get-DrmInfo                                                                               

    Binary     7.1.0.5... VMware.VimAutomation.HorizonView    {Connect-HVServer, Disconnect-HVServer}                                                   

    Binary     6.5.1.5... VMware.VimAutomation.License        Get-LicenseDataManager                                                                    

    Binary     2.0.0.6... VMware.VimAutomation.Nsxt           {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtService}                              

    Binary     6.5.1.5... VMware.VimAutomation.PCloud         {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDatacenter}          

    Manifest   1.0.0.5... VMware.VimAutomation.Sdk            {Get-PSVersion, Get-InstallPath}                                                          

    Binary     6.5.1.5... VMware.VimAutomation.Srm            {Connect-SrmServer, Disconnect-SrmServer}                                                 

    Binary     6.5.1.5... VMware.VimAutomation.Storage        {Copy-VDisk, Export-SpbmStoragePolicy, Get-NfsUser, Get-SpbmCapability...}                

    Script     1.0        VMware.VimAutomation.StorageUtility Update-VmfsDatastore                                                                      

    Binary     6.5.1.5... VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSw...

    Binary     6.5.1.5... VMware.VimAutomation.vROps          {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition...}            

    Binary     6.5.1.5... VMware.VumAutomation                {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}        



  • 29.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 05:09 PM

    Welp, I owe you a case of beer.

    Turns out, the VDI which I was running these commands from has/had an outdated version or was missing something. Went to a mgmt server with VScode, script ran fine.

    THANK YOU for all of your help. So sorry for wasting your time.



  • 30.  RE: script to check a setting in a vmx file for specific entry

    Posted Nov 15, 2019 05:31 PM

    No problem, glad you found the solution