Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting a batch file to powershell

Posted on 2016-08-10
11
Medium Priority
?
62 Views
Last Modified: 2016-10-10
I tried to convert the below to powershell and had a lot of errors. I obviously am not good at that. Could someone help
me out here?

DEL /F /S /Q /A "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*"REG DELETE

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband /F

taskkill /f /im explorer.exe

start explorer.exe
0
Comment
Question by:arosenboom
10 Comments
 
LVL 14

Expert Comment

by:Schnell Solutions
ID: 41751078
Remove-Item -Recurse -Force "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*"

Remove-Item -Force hklm:\software\Microsoft\Windows\CurrentVersion\Explorer\Taskband

Stop-Process -Force -Name "explorer.exe"

Start-Process explorer.exe
0
 
LVL 14

Assisted Solution

by:Schnell Solutions
Schnell Solutions earned 1000 total points
ID: 41751080
You can also conserve a 'cmd' look like syntax, and it is still going to be powershell:

Del  -Recurse -Force "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*"

Del  -Force hklm:\software\Microsoft\Windows\CurrentVersion\Explorer\Taskband

Kill  -Force -Name "explorer.exe"

Start explorer.exe
0
 

Author Comment

by:arosenboom
ID: 41751161
Thanks for the quick comment, but this is kind of what I am getting this... I got the same thing  (I think)when I tried to write it myself...  The bat file works like a charm....

But when I highlight line one and run it I get..First Error
The profile comes in off our profile server.. You should be able to see that with the lines I have grayed out...

And then when I highlight line two, and run I getSeconf line Error
Any suggestions or thoughts?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:arosenboom
ID: 41751248
I believe I got rid of the top error by adding the profle server name and share to the path, but
I am still getting the bottom error.... :o(.
0
 
LVL 14

Expert Comment

by:Schnell Solutions
ID: 41751456
Ok, let's ensure that it is reading the registry...

Can you please execute this...

Get-Item   HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband

(Let me know the result)
0
 
LVL 19

Assisted Solution

by:Mike T
Mike T earned 500 total points
ID: 41751898
Looks like you can't assume the path is there so you need to use "try" first. PowerShell is *very* unforgiving with non-existent paths and goes all red.

The reason the bat file works is it doesn't care what reg.exe does and carry on regardless.

Mike
1
 

Author Comment

by:arosenboom
ID: 41752370
Get-Item..
That is what I got in return... Before I go on further, I should say, what I originally wanted to get done, I figured out. I originally  wanted for a 2012r2 Citrix/RDSH sessions to lock the desktop down for all users... So, I started with classic shell and Group policy and got most of it locked down, but I still had file explorer in the taskbar and I couldn't figure out how to get rid of that and posted to many Microsoft forums and nobody had a good answer... The reason I couldn't use GPO to unpin it, was because it keeps everything from being pinned to the taskbar and we have our companies apps that
we need to pin there (through powershell)...  I (FINALLY) found this bat that gets rid of file explorer...

DEL /F /S /Q /A "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*"
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband /F
taskkill /f /im explorer.exe
start explorer.exe

So what I was originally wanting to do is just put that in our current powershell  that pins our companies apps, but it is just as easy to put it in a vbscript that calls the bat first, and then calls
the powershell to pin the apps we want and put the vb in the all users startup folder...  Not very elegant or pretty, but it does work...

This was a pain, as I had many people suggesting powershell scripts that didn't work and other options that didn't work. and I was losing hope that I could get rid of file explorer for every user that logs into Citrix on that machine... Most of the powershells were written for 2008r2 and if I understand it correctly, explorer.exe is pinned to 2012r2 differently...

Am curious on the powershell, why it was erring out though, for future reference.  Thanks for all the help with this.
0
 
LVL 14

Accepted Solution

by:
Schnell Solutions earned 1000 total points
ID: 41752436
Lovely,

If Get-Item found the data, you just need to pipe the exact command and then delete it adding:
Remove-Item -Recurse -FOrce -Confirm: $False
DEL -Recurse -FOrce -Confirm: $False (This is an alias that means the same)

So, that line can be something like this:
Get-Item HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband | DEL -Recurse -FOrce -Confirm: $False
0
 

Author Comment

by:arosenboom
ID: 41752504
Slick... Thanks for all your help on this.
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 500 total points
ID: 41754610
The first line needs to be
Remove-Item -Recurse -Force "$env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*"

Open in new window

to be correct.
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Loops Section Overview
Suggested Courses

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