Solved

Converting a batch file to powershell

Posted on 2016-08-10
11
31 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
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
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.

 

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 17

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 69

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article will help you understand what HashTables are and how to use them in PowerShell.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.

776 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