Solved

Converting a batch file to powershell

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

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

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 68

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Synchronize a new Active Directory domain with an existing Office 365 tenant
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now