none
SCCM CLient via powershell

    Question

  • So I have a batch file (located on a file share with a UNC patch name) that installs the SCCM client that includes all the required parameters.  It works beautifully!

     

    I want to use powershell to run that batch file remotely against a list of about 500 devices.  I can feel the comptuer names in and have done that with other scripts, but I am at a loss on how to call the batch file....suggestions?

    Wednesday, August 24, 2011 7:26 PM

Answers

  • Just my opinion, but I would rather have the file copied over to the location, install and then delete the installation file when completed. This way you are not taking the chance that a network issue might arise in the middle of an installation, thus corrupting it. Besides, the script will automate the copying, installing and deleting (you will need to add the code for this portion). If time is also an issue, then I would recommend using background jobs (see Help Start-Job) to run multiple installations at a time.
    Thursday, August 25, 2011 5:45 PM
    Moderator

All replies

  • This is a pretty simple script, but you can modify as needed. Has not been tested either and assumes you have your clients listed in a file called computers.txt...

    ForEach ($computer in (Get-Content "C:\computers.txt")) {
        If (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
            xcopy "install.bat" "\\$computer\c$" /C /Y
            Try {
                $value = (invoke-wmimethod -computer $computer -path win32_process -name create -argumentlist "C:\install.bat" -ea stop).returnvalue
            } Catch {
                "{0}: {1}" -f $computer,"$($Error[0])"
            }
            If ($Value -eq 0) {
                "{0}: {1}" -f $computer,"Success"
            } Else {
                "{0}: {1}" -f $computer,"Failed"
            }
        } Else {
            "{0}: {1}" -f $computer,"Unreachable"
        }
    }

    Wednesday, August 24, 2011 7:53 PM
    Moderator
  • Thank you so much for replying and I am almost there, but there seems to be something just not quite right.  The file copies correctly and the script returns 0 so it states successful.  But the batch file doesn't "run right"  The command from the script when typing in to powershellmanually

    _________

    Invoke-WmiMethod -computer $computer -path win32_process -name create -argumentlist "c:\installcmclient.bat" -ea stop

    _________

    it returns 0 but the batch file doesn't run.  It isn't the file as when I run it locally it functions.  I attempted to use the below:

    _________________

    $cmd = "comd.exe /c c:\installcmclient.bat"

    Invoke-WmiMethod -computer ns0062 -path win32_process -name create -argumentlist $cmd

    _________________

    and it still returns 0 with no action on the device.

     

    I tested the above script with a simple batch file "md c:\test folder" and it creates the folder....great!

    I tested it with a batch file that launches notepad "c:\windows\system32\notepad.exe" and the process is there but the app isn't loaded

     

    For my testing I am logged in on both devices as myself (admin on both)  I am running the script from a Win7 computer to a WinXP device...What am I missing?

     

    Thursday, August 25, 2011 1:50 PM
  • What is in tehis batch file.  All components MUST be located on the remote machine for a remote install to work, not just the batch file.

     

     


    jv
    Thursday, August 25, 2011 3:50 PM
  • The batch file installs the SCCM client with all the required parameters on the devices.  The install files are located on a file share and called in the batch file from a UNC path.  The install files are over 100MB and I don't want to have to copy them locally

    I have tried playing with the impersonation parameter but it isn't getting me anywhere.  Would mapping a drive and calling it from the mapped drive help?

     

    Thursday, August 25, 2011 5:25 PM
  • Just my opinion, but I would rather have the file copied over to the location, install and then delete the installation file when completed. This way you are not taking the chance that a network issue might arise in the middle of an installation, thus corrupting it. Besides, the script will automate the copying, installing and deleting (you will need to add the code for this portion). If time is also an issue, then I would recommend using background jobs (see Help Start-Job) to run multiple installations at a time.
    Thursday, August 25, 2011 5:45 PM
    Moderator
  • The batch file installs the SCCM client with all the required parameters on the devices.  The install files are located on a file share and called in the batch file from a UNC path.  The install files are over 100MB and I don't want to have to copy them locally

    I have tried playing with the impersonation parameter but it isn't getting me anywhere.  Would mapping a drive and calling it from the mapped drive help?

     


    You cannot use WMI to remotely install files that are not on teh target computer.  See the extensive Microsoft documentation on this.

    If you 'google' this you will find dozens of articles describing why you cannot do this.  Copy the files to the target machine, run the install and delete the files.

    The SCCM client is an MSI.  Just push it to the clients usiong Software Distribution Policy in Group Plicy.  That is what most of us do.

     

     


    jv
    Thursday, August 25, 2011 6:50 PM