Solved

Powershell script against list of computers

Posted on 2014-12-10
7
364 Views
Last Modified: 2014-12-11
I want to run a script against a list of computers in order to remove some shortcuts from the public desktops.  question is two fold- top set is win7 bottom is XP.  are both of those correct?  I could not determine the working "public" variable for XP.

second is how do write this to pull from a text file with a list of computer names?

Remove-Item -Path "$env:public\Desktop\Microsoft Access 2010.lnk"
Remove-Item -Path "$env:public\Desktop\Microsoft Excel 2010.lnk"
Remove-Item -Path "$env:public\Desktop\Microsoft Outlook 2010.lnk"
Remove-Item -Path "$env:public\Desktop\Microsoft Word 2010.lnk"
Remove-Item -Path "$env:public\Desktop\adobe reader XI.lnk"

Remove-Item -Path "c:\all users\Desktop\Microsoft Access 2010.lnk"
Remove-Item -Path "c:\all users\Desktop\Microsoft Excel 2010.lnk"
Remove-Item -Path "c:\all users\Desktop\Microsoft Outlook 2010.lnk"
Remove-Item -Path "c:\all users\Desktop\Microsoft Word 2010.lnk"
Remove-Item -Path "c:\all users\Desktop\adobe reader XI.lnk"
0
Comment
Question by:GreshAssoc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 40492766
According to http://www.askvg.com/list-of-environment-variables-in-windows-xp-vista-and-7/ it's %public% for everything after Vista.  XP didn't have a "public" per se, I believe it was %ALLUSERSPROFILE%
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 500 total points
ID: 40492784
Second part of your question takes on some assumptions, but seems like it should work for you:
*Code is 'non-destructive' when used 'as-is'...
$shortcuts = 'Microsoft Access 2010','Microsoft Excel 2010', 'Microsoft Outlook 2010','Microsoft Word 2010','adobe reader XI'

foreach ($pc in get-content C:\TestFolder\myComputers.txt) {
    $OS = Get-WmiObject -Computer $pc -Class Win32_OperatingSystem 
    #assumes you don't have anything other than XP and Vista/Win7...
    if ($OS.caption -like '*xp*'){
        $path = "\\$pc\c$\documents and settings\all users\desktop"
    } else {
      $path = "\\$pc\c$\users\public\desktop"
    }
    foreach ($shortcut in $shortcuts) {
        #remove "WhatIf" parameter to enforce remove-item
        remove-item -Path "$path\$shortcut.lnk" -WhatIf
    }
}

Open in new window

0
 
LVL 2

Author Comment

by:GreshAssoc
ID: 40492867
awesome, so that seems to work well. now what if I wanted to remove an all user start menu program too?  do I just add in those paths too?
else {
$path = "\\$pc\c$\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office"
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 67

Expert Comment

by:sirbounty
ID: 40492892
Everything beneath that path?  If it contains subfolders, you'll need to include the -recurse parameter
0
 
LVL 2

Author Comment

by:GreshAssoc
ID: 40492917
No subfolders there. Would only be the office programs lnk's again. Idea is to get them of the desktop and the programs menu
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40492945
In that case, I think you can just perform a remove-item and specify *.lnk for the files, using the -recurse parameter.  That will remove and and all shortcuts underneath that path...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40494588
Glad I could help - thanks for the grade. :^)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question