Help PowerShell script/Windows VI Toolkit

OK, I am new to Windows PowerShell since I started watching this VI Toolkit yesterday.  I am trying to create an automated task on my Virtual Center Server to update VMWare tools on my production virtual machines within hours early in the morning, so a restart does not affect users, and I have no schedule maintence of this request.

According to me, I'm pretty close, but I'm stuck.  I have the command that I created and that will run the cmdlet Connect-VIServer, however, I must place another order to run the Cmdlet Update-Tools in this same window PowerShell.  Below in bold in the command I am running in a CMD file.  This will open a Windows Powershell and I can for example type Get - VM and it lists all the virtual machines in Virtual Center

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe - PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" - NoExit-command '& {Connect-VIServer-server localhost} '.

Any suggestions?

You are almost done. Just replace {Connect-VIServer-server localhost} with something like:

{VIServer is Connect-Server localhost; get - vm |-update tools}

[PowerShell MVP |] [ https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], the VI Toolkit forum moderator

Author of the forthcoming book: VMware Infrastructure Management with PowerShell

Co-host, PowerScripting Podcast (http://powerscripting.net)

Tags: VMware

Similar Questions

  • Planning and running my script powershell crashed Windows 7

    Hi all

    I created a powershell script that works perfectly when I run it using powershell. Just, it reads XML files and email some information on their part. But as soon as I have this schedule using the Windows Task Scheduler and run it, it blocks the windows. First of all, trying to open the Task Scheduler, after planning script, it give error, the Task Scheduler service is not available. Then I rebooted my system, and windows starts in recovery mode. I even tried windows recovery to a point recorded earlier, but also, that did not help. My BUSINESS team had to redeploy full Windows 7 on my system. I already tried this on two different systems, both with Windows 7 Professional and it crashes in the same way.

    Please help me understand what I am doing wrong.

    I don't know how to download my forum script, please let me know if any of you wish to have a look, and I'll send my code.

    Thank you

    Vittoz

    _______@____.com

    Hello Ashish,

    Thanks for posting your question on the Microsoft community.

    This question fits better to the developers on MSDN forums.

    I suggest you to ask your question on the MSDN forums.

    MSDN forum
    https://social.msdn.Microsoft.com/forums/en-us/home?category=windowsdesktopdev

    Thank you

  • I need an example script Powershell in Windows 7

    I can repeat this request I presented during my "subscription", but he doesn't know if it took.

    I would be recognizing an example of a Windows Powershell Script that looks up a record in a file and displays the content of this record on my screen. Records are scanned from Documents. They are scanned by user 'XX' within the Date.

    The path is: C:\Documents\DailyPosting

    I've programmed in a distant past, but did not use scripts. If I had an example I could go from there. I don't read very well of manuals.

    I am 78 years old. Would be grateful yourhelp!

    Thank you

    Cmawsquaw

    Hello

    The question you posted would be better suited in the TechNet Forums. I would recommend posting your query in the link below.

    http://social.technet.Microsoft.com/forums/en/category/scripting

    Hope this information helps.

  • When you try to perform a factory restore I get this error: "could not find"JScript.Encode"script engine: C:\Windows\Help\OEM\scripts\launche.jse.

    I'm trying to restore my PC to the preassembled initial state

    I followed this as mentioned in the help, but I got this message
    Cannot find "JScript.Encode" script engine

    C:\Windows\Help\OEM\scripts \launche. JSE

    I use windows Vista

    So what can I do to restore my system?
    waiting for your support with kindness

    Hello

    There are two ways to do this.

    Most computers these days don't come with recovery discs.

    Instead, computer image makers a recovery Partition on the hard drive in order to reinstall the operating system to.

    That the recovery process says return to factory (new State) settings

    To access the recovery partition, you should be able to find it in the start menu > programs > list of software from the manufacturer of your > search for recovery options.

    A simpler method to start the press a key or sequence of keys at startup (when you start your computer)

    So maybe F10, F11, Alt + F10, etc. depending on your manufacturer.

    You must ask them or online on their website or the Support Forums to know the exact key / s press.

    Another method is to ask them to send you a set of recovery discs, which will do the same.

    They will charge a small cost for this service.

    Back up the data that it will be lost during the recovery process, and all programs that you have installed will need to be reinstalled from the original media (CD, DVD, download Net).

    Some manufacturers have more available Vista recovery disks.

    If this happens, you may need to try this instead:

    You can also borrow and use a Microsoft Vista DVD, which contains the files for the different editions of Vista (Home Basic, Home Premium, Business and Ultimate) must be installed. The product key on your computer / Laptop box determines what Edition is installed.

    Other manufacturers recovery DVDs are should not be used for this purpose.

    And you need to know the version of 'bit' for Vista, as 32-bit and 64-bit editions come on different DVDs

    See you soon.

  • Running Powershell script with ESXCLI commands via a scheduled task in Windows 2012 does not work.

    I'm trying to run a powershell script of a scheduled task in Windows 2012. The script calls the commands ESXCLI and ends with success (exporting to a CSV file) but the file has no data inside.  If I run the script manually without the scheduled task file has all the I expect to exit.

    I wonder if there is a framework with Powershell or a PSSnapin I need to add to the script for it to run via a scheduled task.  Has anyone done this before with the ESXCLI commands?

    panhvr - you may to something.  The process account that I use to run this script has only read-only access in vCenter.  I logged on the server I am running these reports with the process ID and tried to run the script.  He gave me errors indicating permission to perform the operations of esxcli was denied.

    I think we found the culprit!  I'll have this process ID in vCenter rights upward.

    Thank you all!

  • Such a powershell script exist?

    Windows Server Standard 2012R2. I know not enough about powershell scripts to be dangerous. So I guess that its better to ask for help on this one. As you know, in the Windows backup program, the e-mail feature is depreciated on server 2012. However, I had no problem of customization of a powershell script that I found so that it sends an email when the nightly backup is completed successfully. Te was easy to do. In Manager tasks I just put the firing an event, with the event being backup Windows and a number of event 4 - which means backup completed successfully. In fact, it works very well for my clients.  But it is not the fault of my client. (of course!)

    Customers only the desire to receive an email if the backup is not successful. But the reasons for a backup failed are many which can generate any number of errors in the event log. Since I'm just not knowledgeable of powershell scripts, I hope someone can help me here, or at least direct me to where I can get help. Basically, I need a script powershell like this:

    Trigger is "the eventID 14 (completed backup operation).

    If eventID in the Microsoft-Windows-backup/OPerational log prior to the triggering event is not 4, while sendmail

    This above would of course, include my work already sendmail script. Is this possible? Maybe someone has already done? Any help would be appreciated.

    Hello

    For technical support, repost the question in the Windows Server Forum.

    https://social.technet.Microsoft.com/forums/WindowsServer/en-us/home

  • Struggling to run Powershell scripts / commands

    Hi all!

    I'm fighting to get the Powershell vCO workflow.  I think I missed something really obvious, but I can't see it...

    I did the set Kerberos in place on the line of my vCO 5.5.2 machine.  I added a Powershell v2 host using VMWare provided Powershell 1.0.4 workflows plugin install, Kerberos authentication and using a shared account (mine, I know that I am an admin on Windows Server).  I assured the Kerberos authentication and unencrypted traffic is accepted on the Powershell host.  If I validate the object created at the CVO, he says it's fine.

    When I come to run another VMware provided workflow, I get responses to error because the workflow doesn't seem to be properly trained, or I get a null response.  When I run a workflow, I can see my account by logging in the Windows Server 2008 security log, so I'm pretty confident that the basic connection and portions of Kerberos are all ok.

    I just tried to simplify a VMware provided workflow, to make it as a possible base (code below).  I always get a Null response.  Anyone have any ideas why?  Or did someone is able to provide the code for a very simple Powershell-based workflow that they know works so I can test it on my set up?

    The VMWare-based simple powershell script provided one to get the contents of some directories and the values that I use - it returns null:

    the hostentry, type: PowerShell:PowerShellHost, value: < myPowershellHostSelectedFromPluginManually >

    Directoryentry, type: String, value: I manually enter $home.  Or C:.  Or C:\Windows.  Or any other directory I know there is that my user account has no light problem.

    output of the result, type: string, value: regardless of the ("DIR" + directory) output >

    var Sess;

    connect to the host

    Sess = host.openSession)

    Send the command in powershell

    sess.addCommandFromString ("dir" + directory)

    invoke the command

    invResult = sess.invokePipeline ();

    get the result

    Result = invResult.getResults)

    Send to open a session

    System.log ("Result is" + result)

    Thank you very much in advance!

    And there we go...  Who sets: powershell.exe wasn't in the path of the Windows host!

    Thanks for the help everyone, especially igaydajiev for giving me the pointer of the final to my answer!

  • Get-QADComputer fails if run PowerShell script through Orchestrator workflow

    I use the "Get-QADComputer" cmdlet in my .ps1 script that is supposed to run via Orchestrator.  I have several PowerShell scripts started by Orchestrator and run on a host windows without any problem.  For this script, I have these 2 commands and still error.  The script does not error when run locally.

    Add-PSSnapin Quest.ActiveRoles.ADManagement - ErrorAction SilentlyContinue

    $Computer = get-QADComputer-identity "server01" | where {$_.name - eq "server01"}

    In troubleshooting, I ran Get-PSSnapin and can see that the snap for AD is loaded successfully.  I tried Connect-QADService and who also gives the same error, although it works very well on place.

    I use vCO 5.1.1. device.   On the hosts Windows where are the scripts PowerShell, the AD snap is version 1.6.0.2683.

    Here is the error in the logs Orchestrator...

    PowerShellInvocationError: Errors found during execution of script

    System.Runtime.InteropServices.COMException (0x8007054B): the specified domain does not exist or could not be contacted.

    at Interop.ActiveDs.IADsOpenDSObject.OpenDSObject (String lpszUserName, String lpszPassword, String lpszDNName, Int32 lnReserved)

    to Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.AdsiDirectory.NativeBind (adsPath String, AuthenticationTypes bindFlags)

    at Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.AdsiDirectory.BindToObject (String dn)

    at Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ConnectorFactory.Create (String serverName, user String, SecureString password, type of ConnectorType)

    to Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.ConnectionAwareCmdlet.EstablishConnection (ConnectionProperties connectionProperties)

    at Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.ConnectionAwareCmdlet.GetContainer)

    at Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetUserCmdlet.BeginProcessing)

    at System.Management.Automation.Cmdlet.DoBeginProcessing)

    at System.Management.Automation.CommandProcessorBase.DoBegin)

    (Name of the dynamic Script Module: invokeScript #14)

    Thanks for the info.  I use the workflow "Invoke an external script" to run many of my host admin PowerShell scripts.  It is easier for me to keep all .ps1 files in one place and not import them into Orchestrator.  The article prompted me to switch my connection to host basic Powershell to Kerberos.  To do this, I had to update /etc/krb5.conf on the device of the vCO.  I've referenced VMware KB2036986 to work around the problem "unable to get kdc for the Kingdom.  This issue was mainly because we couldn't have krb5 configured previously.

    Now, I got a different error during execution of the workflow after bouncing vCO.

    System.NullReferenceException: Object Reference not set to an instance of an object.

    Has pointed out me the need to first make the connection AD.  He has not worked before without Kerberos authentication.  Once I added these lines of code, Get-QADComputer finally worked without error!   Thanks for the help.

    $pass = ConvertTo-SecureString - AsPlainText-Force - String "password".

    Connect-QADService - "example.com\serviceaccount" ConnectionAccount - ConnectionPassword $pass

    $Computer = get-QADComputer-identity "server01" | where {$_.name - eq "server01"}

    Disconnect-QADService

  • PowerShell / script PowerCLI is not execution of the stimulus package SRM

    I posted this in the community of the Site Recovery Manager, but thought that the PowerCLI community may be able to help as well. *****

    I can't run a script PowerShell to a recovery plan, even if I can't run interactively from the SRM of recovery server and command CMD run OK.

    Here is the error I get:

    Error: user designed legend "C:\Windows\system32\cmd.exe /c C:\test.cmd" has not returned in 300 seconds.

    The recovery plan called test.cmd, which is basically redirected to the PowerShell script.

    REM ===== test.cmd =====
    @echo off
    echo > C:\1.txt
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -ExecutionPolicy RemoteSigned -Command C:\test.ps1
    echo > C:\3.txt
    REM ===== end of test.cmd =====
    

    Test.cmd called test.ps1, that only creates a CSV file for troubleshooting.

    # ===== test.ps1 =====
    Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue     # Load VMware PowerCLI functionality
    Write-Host foo | Export-CSV C:\2.txt
    exit
    # ===== end of test.ps1 =====
    

    Note that I created the process text files to see where the script stops. When I run test.cmd of the stimulus package, 1. txt is created, but 2. txt and txt 3. are not created. When I run test.cmd interactively from the SRM of recovery server, all three text files are created.


    My environment is 4.1 SRM and PowerCLI 4.1 build 332441 U1.

    Any help would be appreciated. Thank you.

    Things to check.

    (1) under which the account is the .cmd file and therefore the .ps1 file, executed in SRM?

    Maybe the RS account does not have the same privileges

    (2) I would like to start the PowerShell engine in the with the parameter - NoProfile .cmd file.

    A general Council, try to use the cmdlets Start-Transcript and Stop-Transcript at the beginning and at the end of your PS script.

    Have you ever tried to create a .txt file before loading the PowerCLI snap?

  • How to run a Powershell script via a batch file

    I'm new on using Powershell and I have a fundamental question regarding running a powershell script. Basically, I wrote a file of commands as shown below.

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe - PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" - NoExit-command "C:\MyScripts\RunSpanshot.ps1".

    I run the batch file and nothing seems to happen. What is the problem with trying to run the RunSpanshot.ps1 script as shown above? -any help is appreciated.

    Thank you

    You could do

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "& 'C:\My Scripts\RunSpanshot.ps1'"
    
  • Run the cmd PowerShell script

    Hello

    I am trying to run a powershell script from a file cmd with the snap of VMware has added. Here's what I'm trying to run:

    PowerShell.exe - noexit Add-PSSnapin VMware.VimAutomation.Core | k:\work\DeployVM.ps1

    He adds the snap, and then launches the ps1 in Notepad, which is obviously not what I'm after. I'm sure it's something simple I'm missing, but I can't get it. The reason why I want to run it this way is to associate with a button, vb, I've sorted everything else, just this last piece, I need to finish.

    See you soon,.

    Josh

    If there is a reason that you do not add the Add-PSSnapin VMware.VimAutomation.Core as the first line of your script, then you can run it as below:

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe - PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" "& C:\MyScript.ps1 '"

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

  • Publishes a PowerShell Script

    I have a system which gives some issues where I have to restart some services from time to time.

    The problem is that these are problems on the server for a period of work of China - so I'm Home sleep away.

    I can easily restart services using PowerShell, so I thought I have publish a PowerShell script that one guys can run from AppPortal.

    Thought it would be easy (probably is and my brain doesn't work)...  Publish path to powershell (C:\windows\...) and use the file "path\to\script.ps1" as an argument - however, I can't seem to make it work.

    So, how in the heck would I do this?

    Hey Mike,

    Is this a problem of execution policy? You can try adding '-ExecutionPolicy Unrestricted ' at the command line?

    Adam

  • PowerShell script

    Hello

    Say I want to install the Microsoft Patches each month on a field with 50 + servers. I need a script that could give me the following,

    (i.) the availability of each server present in the field, while running the script.

    II.) he should list on the fixes that have been set up so far and this should be exported to excel.

    Servers are 2003 & 2008. Also, I'm not particularly on Powershell scripts. So anything that meets the objective would be really useful.

    Please help me with this.

    Thank you much in advance.

    René-coral. (* E-mail address is removed from the privacy *)

    This issue is beyond the scope of this site and must be placed on Technet or MSDN

    http://social.technet.Microsoft.com/forums/en-us/home

    http://social.msdn.Microsoft.com/forums/en-us/home

  • Newbie question - tide may run a remote PowerShell script or BAT file?

    My first post.  I am new to raz, but I've had experience with other planners.

    I have a PowerShell script that must be run on a remote computer.  All the script needs software is installed on this computer.

    In addition, I need the script runs under a service account.  Is it possible and if yes, how can I go about it?

    This work will be be launched manually whenever this is necessary.

    Sure. There are some screenshots. A variable one, I used for the location of the folder on the server of tide (not required but I use a lot of scripts). One for the command of tide itself. The last one is the script runs remotely on windows work. Let me know if they don't make sense.

  • How to change power mode using powershell script?

    In Windows 7, there are 2 available for selection (balance or eco) power switch mode.

    I would like to know if it is possible to script powershell code to pass these 2 modes of window 7 or not.

    Does anyone have any suggestions?

    Thanks in advance for your suggestions

    Hello

    You want to know about the encoding of a PowerShell script, I recommend that you post the question on the Forum on TechNet script where you will have the best support for any problem related to scripts.

    http://social.technet.Microsoft.com/forums/scriptcenter/en-us/home?Forum=iTCG

    Thank you.

Maybe you are looking for