PowerCLI Invoke-VMScript re - ip guest - how to get the variable hostname comments

I run the following script as a task Post-Power-we a re - ip our VMs after that MRS. them rocking.  I was able to run this script successfully without the variable hostname of comments (in the test, he runs a script by test VM with the hostname assigned...), but I'm stumped on how to get comments variablized according to the machine's host name works on, it will take the host name and use it in the GuestUser variable and the command - VM.  I tried the bold part, but it does not work.

$srv = Connect-VIServer 10.0.0.10 - administrator of the username-password password

$Hostname = (get-wmiobject win32_computersystem). Name

$script = "%windir%\system32\cmd.exe/c c:\dr\drIPsettings.bat".

$HostUser = "root".

$HostPassword = "password"

$GuestUser = ' $Hostname\Administrator '.

$GuestPassword = "password"

$ScriptType = "bat".

SE connect-VIServer 10.0.0.10 - Session $srv. SessionID

Invoke-VMScript - ScriptText $script - VM $Hostname - HostUser $HostUser - HostPassword $HostPassword - GuestUser $GuestUser - GuestPassword $GuestPassword - ScriptType $ScriptType

Thank you!

How you code the - VM on the Invoke-VMScript cmdlet parameter, it seems that Displayname of the guest is the same as the host name.

Can't you just use a loop on guests and then use the displayname property

$script = "%windir%\system32\cmd.exe /c c:\dr\drIPsettings.bat"
$HostUser = "root"
$HostPassword = "password"
$GuestPassword = "password"
$ScriptType = "bat"

Get-VM | %{
   $GuestUser = $_.Name + "\Administrator"
   Invoke-VMScript -ScriptText $script -VM $_ -HostUser $HostUser -HostPassword $HostPassword -GuestUser $GuestUser -GuestPassword $GuestPassword -ScriptType $ScriptType
}

You can encode the Get - VM with more specific selection criteria or use a Where-Object after the Get - VM.

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • How to get the variable 'dn' in a script

    Hello

    I have a problem, get the variable "dn" of the script is not a "public" variable, but I'm able to see in the log file. I bet it's in an object java somewhere - I don't know how to access it. No one knows how to get it. I have attached some of the newspaper:)

    CN = 8485 [5-6] XX, dn = 8485601 = 9812 cgn, ani = null, dnis = null, clid = null, atype = FORWARD_ALL lrd = 9817, ocn = 9817,

    I have a similar problem but I did not find the repo. package... Where?

    Thank you

  • How to get the variable substitution essbase in ODI

    Hi all
    I have a problem that I need to get the variable substitution of Essbase /EAS to work on a SQL in ODI.
    How can I do in ODI?
    Thank you all for...

    Thomas

    Hello

    If you read my blog:-http://john-goodwin.blogspot.com/2009/11/odi-series-planning-11113-enhancements.html
    In the post, there is a section on the recovery of the essbase substitution variables and their use in ODI.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • How to get the name of sbRIO programmatically

    How to get the 'name' and 'Comment' by sbRIO I write to sbRIO-9602 Max in the box of Identification (model, serial number, MAC address, name)?

    Use RT Information.vi of target is located under the range of public services under LabVIEW Realtime.

    Christian

  • How to get the secondary variable

    Hello

    Can I know how to get the variable of the Secondary VI?

    Please see my VI, when I run the test in high school, I can't any variable in the indicator "get all the control values.

    Is there a wrong?

    Thank you.

    Try this:

  • How to get the cpu host machine virtual mhz by PowerCLI

    How to get the cpu host machine virtual mhz by PowerCLI

    Thank you

    TEST.JPG

    The following command of PowerCLI will list the maximum cpu MHz for all of your virtual machines from the host:

    Get - VM | Select-Object - property Name,@{Name='MaxHostCpuMhz'; Expression = {$_.} NumCpu * $_. VMHost.CpuTotalMhz / $_. VMHost.NumCpu}}

  • PowerCLI 5.5 R2 and SRM - how to check the status of a Recovery Plan?

    I need to write a script that will examine the current status (apparently called a "RunMode") of a Recovery Plan, is the appropriate status (1 = Test, 3 = cleaning), then get a list of all virtual machines in a suitable specific folder and they will light up (wait 15 seconds between move them on to the next). There are reasons why the Recovery Plan cannot be responsible to do, so why do I need to write a script (the reasons have nothing to do with PowerCLI). And I have problems with the first part, determination of status.

    I have this (I won pretty well most of this pure and simple of the blog of Ken Werneburg. Thank you, Ken!) :

    $DR_vCenter = "xxxxxx".

    $SRM = connect-SrmServer-Server $DR_vCenter

    $SRM_API = $SRM. ExtensionData

    $PlanMoRef = $SRM_API. . Moref Recovery.ListPlans () [2]

    (My plan is #2, others their test plans. I checked this by looking at the name of each plan. And all the good things I want is in this 'moref,"apparently...)

    $HistoryMoRef = $SRM_API. Recovery.GetHistory ($PlanMoRef)

    (it's the history of the races of this plan. Here it is the story of the last race)

    $HistoryMoRef.GetRecoveryResult (1)


    Key: 68835

    Plan: VMware.VimAutomation.Srm.Views.SrmRecoveryPlan

    Name: Recovery_Plan_PHA

    Description:

    StartTime: 15/07/2014 11:03:15

    StopTime: 15/07/2014 11:09:29

    ExecutionTimeInSeconds: 374

    TotalPausedTimeInSeconds: 0

    ResultState: success

    RunMode: CleanupTest

    WarningCount: 0

    ErrorCount: 0

    SO: I understand how to get the history of the plan that I want, and it's more progress. The problem I have is that if the RunMode is a specific value (either "Test" or "Failover", then I need to launch other actions (power of virtual machines.) And I can't seem to do. «$HistoryMoRef.GetRecoveryResult (1).» RunMode"is empty return. I don't know how it is that the value of "CleanupTest".

    How can I query the RunMode, to see if it is a value which I am interested in?

    $HistoryMoRef.GetRecoveryResult (1) | GM


    TypeName: VMware.VimAutomation.Srm.Views.SrmRecoveryResult


    Name MemberType definition

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

    Equals method Boolean Equals (System.Object, obj)

    GetHashCode method int GetHashCode()

    Type of the method GetType GetType()

    String the ToString ToString() method

    Description property System.String Description {get; set ;}}

    ErrorCount property System.Int32 ErrorCount {get; set ;}}

    ExecutionTimeInSeconds property System.Int64 ExecutionTimeInSeconds {get; set ;}}

    Key key of System.Int32 property {get; set ;}}

    Property System.String name {get; set ;}}

    Plan of property VMware.VimAutomation.Srm.Views.SrmRecoveryPlan {get; set ;}}

    ResultState property VMware.VimAutomation.Srm.Views.SrmRecoveryResultResultState ResultState {get; set ;}}

    RunMode property VMware.VimAutomation.Srm.Views.SrmRecoveryPlanRecoveryMode RunMode {get; set ;}}

    StartTime property System.DateTime StartTime {get; set ;}}

    StopTime property System.DateTime StopTime {get; set ;}}

    TotalPausedTimeInSeconds property System.Int64 TotalPausedTimeInSeconds {get; set ;}}

    WarningCount property System.Int32 WarningCount {get; set ;}}

    Thank you

    Well, I managed to reproduce the problem and to understand what might happen.

    First the error "you can not call a method on an expression evaluated to null." seems to be linked to the "Write-Output"PG ="$pg" line. When I remove the error to go away (I'm not a person of PowerShell so don't know why this is the case).

    The second error (not not being filled seems to be linked to how they make the connection virtual computers SRM.) Specifically, you will need to establish the connection of VC and then do SRM login without specifying the SRM server, let that be determined by searching the SRM recorded with the VC you are connected to.

    The following code worked in my environment when it is connected to the protected so site full of hope that it will work for you as well:

    SE connect-VIServer-Server $protectedSiteVC - user $user-password $pass

    Connect-SrmServer-user $user-password $pass

    Write-Host "implementation details on Protection groups.

    Get-ProtectionGroup | {ForEach-Object

    $pg = $_

    Get-ProtectedVM - ProtectionGroup $pg} | {ForEach-Object

    #Write - Output 'do for each virtual computer.

    $output = "" | Select VmName, PgName

    $_. Vm.UpdateViewData)

    $output. VmName = $_. Vm.Name

    $output. PgName = $pg. GetInfo(). Name

    $output

    } | Format-Table @{Label = 'Name of the virtual computer'; Expression = {$_.} VmName}}, @{Label = 'Protection Group name'; Expression = {$_.} PgName}

    }

  • How to get the IP Address of the Console for all my guests

    How to get the IP Address of the Console for all my guests

    a simple...

    Get-VMHost | Select Name, @{N="ConsoleIP";E={(Get-VMHostNetwork $_).ConsoleNic | ForEach{$_.IP}}}
    
  • How to get the specific information of hardware and software data center

    How to get the specific information of hardware and software data center with powercli...

    What kind of information you need?

    No matter what Esxi host hardware info., if so could below thread is useful.

    Information about the host material with information on the nic and HBA drivers

  • How to get the list of RDM?

    Hi all

    In our environment both of RDM is presented to different virtual machines in physical compatibility mode. It was very difficult for me to keep track

    Could you get it someone please let me know, how to get the list of the RDM presented to ESXI 5.0 host?

    Thank you!

    Ravindra Reddy

    Thank you... A P... for your response tools RV is the right tool, but I wanted to naa number of LUNS as well.

    After 2 hours, I had below power CLI command to get the list of the virtual machine.

    PowerCLI C:\ > Get - VM | Get-hard drive - DiskType "RawPhysical", "RawVirtual" | Select name, Parent, ScsiCanonicalName, DiskType | FL | Out-file C:\RDMlist.xlx

    Thank you!

  • OSB: How to get the proxy service_name

    Hi all
    Could someone please tell me how to get the proxy service name within the stream of messages of OSB.


    Kind regards
    Rakesh Ranjan.

    Published by: Rakesh Ranjan on October 1, 2010 14:27

    Variable context Inound ($inbound) keeps the value of the service name and the name of the invoked operation. Use the expression $inbound/@name to get the name of the service and the expression $entrants / name of the ctx:service/ctx:operation/text() for the invoked operation.

    Do not forget that this Polish name will be there only for services that have operations (such as a WSDL based service)

    Kind regards
    Anuj

  • How to get the text have the same effect as the video?

    Hello

    For the first time post here, but I wonder how to get the text of the titles have the same effect as the video behind her.

    For my video, I use 'bad tv' and other effects such as Gaussian that obviously changes the appearance of video, creating the look of VHS. However, I then inserted text via the title, but it normally appears. How can I make this text have the same effects as the video behind it?

    A friend told me I might need to add text to the video first, then do the effects, I have not tried, but wonder if there is an easier way, as this would require me to restart.

    EDIT: That's what I'm looking for. https://youtu.be/7_2PHQI89dI?t=24s The text has the same effect as the video.

    Thank you

    One way is to create a clip made up based on the title and the original clip. Then apply the effect.

    Another way is to use an adjustment layer.

    Good luck.

    Russ

  • How to get the podcast of the website on the phone

    I was told to put that feed into the PODCASTING app on your iOS device.

    The site in question is https://randirhodes.com/how-to-get-the-podcast/

    I paid for a premium podcast, now how o I get this podcast to appear on my iphone 6 s more in the podcast app?

    Podcasts > select my Podcasts > press the '+' > Add Podcast > paste the URL that you got on the site.

  • How to get the video intro off my google home screen I already saw it, where is the firefox logo used to be.

    How to get the video intro off my google home screen I already saw it, where is the firefox logo used to be. I started with the last update that I rebooted.

    Hello
    to change the homepage when opening firefox-press 'Alt' and click on tools-> Options.

    Main menu, you can change the URL.

    If the problem persists, you can follow these simple steps:

    Enter about: config in the address bar and press ENTER. Accept the message of 'dragons' to see the Advanced preferences screen. Use the above search box to enter the below pref.

    You can assign an empty string to stop your Firefox to retrieve "extracts" and brandLogo changes the browser.aboutHomeSnippets.updateUrl pref. Right-click this pref and select Edit then clear the value as pref in the box that appears, and then click OK. Who will also disable "snippets" that appear under the container of the research on the default home page.

    Then you must open the folder of your profile, via help > Troubleshooting Information > profile folder > > button view folder. Then close Firefox. Your profile file open with Firefox closed (Firefox '3-bar' menu key > exit/Quit), wait or two minutes, then remove the storage\moz-safe-about + home folder in the Firefox profile folder to remove the brandLogo and stored in IndexedDB code snippets to make Firefox use the default brandLogo and a defined default code snippet.

    If you later change your mind about these changes, you can reset the pref browser.aboutHomeSnippets.updateUrl via the context menu and Reset allows to retrieve the default value using the storage\moz-chest-fort-about + home folder again.

  • where and how to get the new Firefox add - one of who is spying on us. Please mail to...

    Heard speak adds the new on Fire Fox. Where and how to get the new Firefox add - one of who is spying on us. Please mail to maheshubhayakar at rediffmail.com

    edited by email address - moderator

    It is helpful if you provide a link to the article you were reading.

Maybe you are looking for

  • How to: close the Application properly

    Hi all I could not find a recent (LV 2009) thread on this topic. I have an application that consists of two main voluntary initiatives.  The first VI (that the user never sees) called the VI of the user interface. I got hurt when the user wants to le

  • Resuming a suspended play list?

    Recently, I created a playlist for an audio book (with 70 records).  To halfway through I loaded a few podcasts on the Clip that intends to listen to when the book was finished.  To remove the USB connector Clip, I was invited for what I wanted to li

  • How to view the log file of Disk Defragmenter?

    After I run disk defragmentation, I can't find a recording that said it was over. How will I know if the defragmentation has been completed or a record that it has been completed?

  • HP LaserJet P1606dn: Paper feed 1/3 and printer jams

    I got the impression for about 2 years.  Jams printer after paper feeds about 1/3 of rolls.  I inspected all areas of paper jam.  I think that there are papers torn or other debris in.  I cleaned the rollers with compressed gas area.  Attention no lo

  • question about IPP

    "IPP injects a static route in the routing table of the router network for network address referenced by the crypto ACL of the remote router. These static routes can be redistributed by using a dynamic routing protocol. » "The static IP route is pres