Solved

Powershell script against list of computers

Posted on 2014-12-10
7
250 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now