Solved

Powershell script against list of computers

Posted on 2014-12-10
7
289 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
  • 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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