Solved

Converting a batch file to powershell

Posted on 2016-08-10
11
43 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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 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