Announcement

Collapse
No announcement yet.

Powershell passing info to cmd line

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Powershell passing info to cmd line

    This is the latest attempt to upload this topic. Can't include the actual PS commands, have played with characters to find something that the upload engine will allow.

    I have a need to script a cmd line action on my Win7 domain clients, but my DOS skills are only the most basic (never did well with DOS variables and conditional syntax). I am getting comfortable with PS, but find having to use both in concert to accomplish this job. What I want to do is use the invok_cmd to call this string:
    *d i s m / o n l i n e / g e t*p a c k a g e s -pipe- findstr KB2952664* to list all versions of that KB update package installed on the client, then invoke a 2nd cmd:
    *d i s m / o n l i n e / r e m o v e*p a c k a g e / P a c k a g e N a m e:<result>]* on each line found from the 'get_packages' line.

    Spot checks across my clients using the Get line remotely show as few as 4 and as many as 13 different versions installed on a client from previous update cycles. The latest drop now is giving us grief, so we want to remove it all. If it was pure PS I'd simply use a foreach loop, but since the dism is cmd line, how do I get the results from the Get, one at a time, and pass back to the Remove that's inside the loop? Oh, and the results lines all include the prefix characters: 'Package Installed : ' (and yes there's a trailing white space.) So I have to parse that too; everything from the 21st character and on is the package name to be included in the Remove statement. With a pure PS script I can use the *<result>Substring(nn)* class to get everything after the trailing whitespace, but how do I link that string into the 'dism' cmd line?

    If this is straight-forward I'll apologise now, but I can't seem to see the wood for the trees, if it is. Whether I execute this from a management server to remotely execute on the clients, or set it as a startup script to run locally on the clients isn't an issue. I'm only stuck on: just how do I hand over the list of answers from Get to the Remove dism cmd?
    *RicklesP*
    MSCA (2003/XP), Security+, CCNA

    ** Remember: credit where credit is due, and reputation points as appropriate **

  • #2
    Maybe this would help?

    https://gallery.technet.microsoft.co...-list-0955fe87

    then this to actually remove the fix?

    https://gallery.technet.microsoft.co...pdate-76f2dcb7

    or maybe this

    http://techibee.com/powershell/power...esupdates/1084

    Comment


    • #3
      I hadn't seen those from my searches, but I had run previous simple commands which looked like they worked for the KB name. But when the specimen PC rebooted, that KB showed as installed again as soon as the first login looked. And the KB number is disabled in WSUS, so it must be caching on the client (clearing out the SoftwareDistribution folder did nothing). I finally found the DISM command shown in my first post, and that's when I found the record of multiple installs on each client. Experimentation showed I had to use the remove - package command for each version on each client, newest to oldest, before I cured the thing of the spontaneous re-install. I'll have a look at your links, but it's gonna be a few days before I can report back on results.
      *RicklesP*
      MSCA (2003/XP), Security+, CCNA

      ** Remember: credit where credit is due, and reputation points as appropriate **

      Comment


      • #4
        Maybe something like,
        Code:
        Invoke-Command -ComputerName . -ScriptBlock {(Dism.exe /Online /Get-Packages | findstr /i "KB2952664") -replace "Package Identity : ", "" | % {Dism.exe /Online /Remove-Package /PackageName:$_}}

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Rems, i will certainly look into your proposed script. Many thanks. It still might be a couple of days, tho.
          *RicklesP*
          MSCA (2003/XP), Security+, CCNA

          ** Remember: credit where credit is due, and reputation points as appropriate **

          Comment

          Working...
          X