Solved

Converting a batch file to powershell

Posted on 2016-08-10
11
47 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 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 250 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
Ready to trade in that old firewall?

Whether you need to trade-up to a shiny new Firebox or just ready to upgrade from whatever appliance you're using now, WatchGuard has the right appliance for you! Find your perfect Firebox today with appliance sizing tool!

 

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 18

Assisted Solution

by:Mike T
Mike T earned 125 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 250 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 70

Assisted Solution

by:Qlemo
Qlemo earned 125 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

624 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