Solved

Powershell script against list of computers

Posted on 2014-12-10
7
313 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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