none
Powershell Script for DISM command on multiple servers RRS feed

  • Question

  • Good morning, Scripting Guys.  I recently completed a project to install Windows 2008 R2 Service Pack 1 on 550 servers.

    Looking for a powershell script to remotely run the command: dism /online /cleanup-image /spsuperseded /hidesp on these 550 servers.

    I tried and out error code 87 because of UAC. I used psexec with starting CMD.exe remotely then using dism /online /cleanup-image /spsuperseded /hidesp

    I searched Google and Technet and could not find a powershell script already, which is strange. I would like to see if you guys could assist in creating a powershell script to assist with this. I know that this command does not require a start and need to confirm that these servers do not restart and add the /norestart switch for confirmation. I have local administrator rights on all these servers as well.

    Thank you!

    Chris

    Monday, February 10, 2014 2:30 PM

Answers

  • Good morning.  Got it working using PSEXEC and a batch file.

    Thanks

    • Marked as answer by CSnyder79 Monday, February 24, 2014 2:24 PM
    Monday, February 24, 2014 2:24 PM

All replies

  • Can't be done like that.  You need to use PowerShell and you likely want to use DSC.

    Help about_desired_state


    ¯\_(ツ)_/¯

    Monday, February 10, 2014 3:34 PM
  • Thank you for the reply.  I would like to use powershell and looked into DSC.

    Does anyone have a script that was created to perform any DISM commands remotely on 2008 servers?

    Thanks!

    Chris

    Tuesday, February 11, 2014 12:33 PM
  • DISM manages images and not servers.  DISM is a commandline tool and not a scripting tool.

    Try posting your question in the platform forum for the OS you are using.  They will point you at the correct resources.

    If you have PowerShell remotinginstalled and enabled you might be able to use remoting.

    Get-AdComputer -Filter * | 
         ForEach-Object{
              invoke-command -ScriptBlock {Dism /online /Get-Features} -computer $_.Name
         }


    ¯\_(ツ)_/¯


    • Edited by jrv Tuesday, February 11, 2014 4:33 PM
    Tuesday, February 11, 2014 4:31 PM
  • Good morning.  Got it working using PSEXEC and a batch file.

    Thanks

    • Marked as answer by CSnyder79 Monday, February 24, 2014 2:24 PM
    Monday, February 24, 2014 2:24 PM
  • Do you mind sharing what you have because I've been looking for the same thing?

    Thanks!

    Thursday, May 8, 2014 10:03 PM
  • Late on this thread, but just in case someone comes across this with a search...

    You can use PSExec.exe within PowerShell to run the command on the remote server.  First, set the $CleanupComputer variable however you like and then you can:

    Start-Process-Wait"C:\PSTools\PsExec.exe""\\$CleanupComputerdism /online /cleanup-image /spsuperseded"

    Also, the progress bar won't be captured, but you'll see the rest of the output from the command and then the window will simply close and the script will continue when it's done.  I output the free space on the remote volume before and after this command just to see what was recovered.

    Matt

    Wednesday, November 1, 2017 10:19 PM