Author Posts

August 9, 2016 at 2:01 pm

I need to delete a file from 5 servers in the following location. C:\Users\*USERNAMES*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WorkInstructor – Shortcut
this will be replaced with another program that is currently on the desktop of all the users that have logged into the servers.
Also the shortcut is in the C:\Users\Public\Desktop\MES_Administration.jnlp
if i can have the workinstructor removed and replaced with the MES_admin file that will be great!

August 9, 2016 at 2:05 pm

OK... so, what have you tried, and where do you need some help?

August 9, 2016 at 2:07 pm

i started with dos but i cannot find the syntax if it even exists to include all the users with the users folder. so i am guessing another language will need to be used that is robust. i do not know powershell as well and i chose powershell since its windows.

August 9, 2016 at 2:16 pm

"del \\servername\C:\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\shortcut" this was my attempt

August 9, 2016 at 2:22 pm

So, there's probably a little Windows-ish stuff, too, that has nothing to do with PowerShell. \\servername\c: isn't a valid UNC path, for example. Most Windows machines will have the C: drive shared as C$, so \\servername\c$\users\whatever... would work, if you're an administrator. And, in Windows, it isn't legal to use a wildcard (*) as part of a file path the way you have. Instead, you'd recurse the available directories.

So the goal is to delete this specified shortcut from all Users' folders on the computer? Do you know if the C$ share is available to you?

August 9, 2016 at 2:25 pm

i can remote into \\computername\c$

August 9, 2016 at 2:36 pm

OK, so there's the easy-to-understand way, which will be incredibly slow, and the harder way, which won't be. I suppose the faster way makes more sense.

You'll need to start by getting a list of user folders, since you can't use a wildcard.

Get-ChildItem -Path \\server\c$\users -Directory

The -Directory switch won't work earlier than PowerShell 3, but it keeps you from getting any files.

Get-ChildItem -Path \\server\c$\users -Directory |
ForEach-Object {
  $full_path = "\\server\c$\$($_.Name)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WorkInstructor – Shortcut"
  Remove-Item $full_path
}

Within the {script block} of ForEach-Object, $_ represents whatever was piped in. In this case, it was a folder that was piped in, so $_ will be that folder. The folder's Name property will be the... well, the name of the folder. So I'm just mashing that folder name into the full UNC path of what you're trying to delete, and then trying to delete it.

Make sense? Hopefully that gives you a starting point to work from. Not being in your environment I can't guarantee it'll work, but hopefully you can tweak it as needed from there. Good luck!

August 9, 2016 at 2:37 pm

And I want to make sure you know what all this means, rather than just copying and pasting it, so if something isn't clear, please ask so that I can explain it.

August 9, 2016 at 2:39 pm

(and I should point out that we don't do "script creation requests" here – we're volunteers, and most have our own jobs to do, and so creating full scripts for other people is not usually practical. Our goal is to try and answer questions and get you pointed in the right direction, where we can – hopefully, the above will help do that in this case.)

August 9, 2016 at 2:52 pm

I would suggest getting a PowerShell book like Learn Windows PowerShell in a Month of Lunches and going over to https://mva.microsoft.com. Like Don said, we are here to help. Use the get-help within PowerShell, it's a great way to learn.

August 9, 2016 at 2:55 pm

thank you guys for the learning experience. I will invest in the book for learning.