How can I completely reset Powerhsell? - powershell

I'd like to reset every single change made to Powershell. Including permission, window sizes, colors, formatting, etc. As if I just installed Powershell on my machine, totally virgin.
Is there a way to do this with one command?

Related

Mysterious blank space randomly appears in Powershell console buffer

I am plagued by a very strange phenomenon. I tend to write fairly esoteric Powershell modules for stuff I do at work. Often, after running one of these, and the module has ended I will move onto some other tasks, and when I happen to bring up my Powershell console window again, several blank lines (or just blank "space") will have appeared in the buffer. It never appears right away, which is the most confounding part.
Afterwards, the blinking cursor exists at the end of this blank space, and the blank space cannot be "backspaced" (so it's not something inadvertently entering spaces or newlines). It's just there, as part of the buffer. I usually just clear the screen with cls to keep it from annoying me.
I used to just chalk this up to the buggy Windows Powershell 5.1 buffering. However now that I've begun using Powershell 7 (and Windows Terminal), I see that the issue still exists.
Here is a screenshot of a v7 Windows Terminal tab an hour or so after my module finished running:
Sometimes it seems the longer I wait the more blank space has appeared. Here is a screenshot of the same console tab about 20 hours later:
I'm sorry I don't have a better way of explaining this. I realize that without any code or pattern to analyze, that this is a very poor question, by SO standards, but I am just as confused as you are. The only pattern I've noticed is that this only seems to happen after I run my various custom modules. However this accounts for the majority of my Powershell usage, so it might be a red herring.
Usually my modules simply do some processing (talking to computers, AD, etc) and just output some information via Write-Host, and occasionally output a [PSCustomObject], which I always capture in a variable. Even if I was accidentally outputting some blank lines or something to the pipeline, I can't see how that would manifest as blank buffer space that grows over time. I thought maybe I was incorrectly killing async jobs or something and that was somehow causing this, but this happens even in purely synchronous code.
To be clear, in the screenshots above there is no code actually running. That module was the only thing I had run in this particular console tab/session, and it doesn't run any background processes. So I can't understand why the buffer is changing all on its own. In both screenshots, the tab/window is the same size as it was when the module first completed, so it's not just a bunch of spaces in the buffer that are being dynamically resized. And as noted, when the module fist completed there were NO rogue characters in the buffer at all.
One other thing about my usage is that it's all done on a remote VM, accessed through RDP, which I use daily. The only other thing I can think of is that maybe something about the console window being minimized/maximized/resized, the resolution changing, or the login session being connected/reconnected has something to do with it.
Does this sound familiar to anyone? Any ideas for what could be causing this or what I can try to understand the behavior better are much appreciated.
I've confirmed that this actually happens as a direct result of simply "restoring" and "maximizing" the Powershell console window and/or Windows Terminal window. When the issue is "present", doing this will often add another "set" of blank space to the buffer before the cursor. Minimizing seems to have no effect, only going from maximized to "restored" and back to maximized.
I've also confirmed that this has nothing to do with my custom modules. I can replicate the issue by simply opening a fresh, maximized console window/tab, running get-process and then "restoring" and maximizing. It doesn't happen every time though.
It also has nothing to do with my custom profile script, as it happens even on a freshly-imaged computer with no profile.
At this point I'm going back to blaming it on buffer/rendering/window manager implementation bugs in powershell and moving on with my life.

Change Epson Cash Drawer setting

I'm looking for a way to change the settings that control the cash drawer either with powershell, vbscript, batch, etc. We have over 40 stores with several registers each. All of those receipt printers were originally configured to open the cash drawer before each print. I have updated our POS software such that it now sends the correct code to prompt the printer to open the drawer only when it is needed (cash transaction, not credit/debit). I'm looking for a way to update the driver setting for all of these printers without having to manually adjust each one. The computers are running Windows 7.
I have tried using PowerShell with some combination of Get-Printer and Set-PrinterProperty, but those cmdlets are not available with Windows 7. I've tried using cscript prncnfg.vbs, but there are no configurable settings options with that command that I could use for this specific settings.
There are only so many places that settings can be saved (Registry, File...). Use Sysinternal's Process Monitor to monitor where the setting is changed.
Start the application.
Just before you go to configure the setting, start capturing in Process Monitor.
Make the change to the setting.
Stop capturing in Process Monitor.
Filter by the PID or Process Name.
Look for write operations to the registry or a file that might represent that setting in your application.
Verify the setting by making changes manually and checking in the application GUI.
You can then use batch, Powershell, VBS, DSC, SCCM or whatever to make that change for all of your clients.

Automated Updating of a Program via powershell

I am trying to updating a software that is company wide. When the update is applied to the server, the client machines recognize they need an update and ask if you wish to update or not. To update, the user would need to run as admin, which is'nt an option in this case.
We would like to automate this process using powershell, using the Invoke-Command feature. For the most part, the only thing that the update does is copy new files to the programs folder, which we have achieved with robocopy. However, there is one registry key that needs to be added in multiple locations. There is a setup file that does this, but requires a user (with admin privileges) click a couple buttons, and we want this to be completely automated.
So I guess the short version of my question is, what is the best way to handle the registry changes that setup.exe does? It would be nice if there was a way to invoke the script that the executable does.
As for my question, I solved the problem with a slightly diferent approach. (One that should have been tried initially)
When (ProgramName).exe is run, if it sees that it needs updated, it runs a program called (ProgramName).setup.exe with the parameters :
Client="Local folder" server="server location"
These parameters did NOT work from the command line, however, and so I ended up using a powershell script to make a scheduled task that ran (ProgramName).setup.exe with said parameters.
Another huge advantage to this was the fact that I could create an icon that allowed a regular user to run the scheduled task with admin privileges. I couldn't setup a shortcut directly, however, I wrote an AUTO-it Executable that would run the task as admin.
I hope someone can get some level of help out of this post!

Script to reset printer settings to black and white

I am new to the whole scripting scene if I'm honest. I have done various things with batch files in the past, but have been looking at PowerShell.
As it is I really don't have any idea where to begin or if what I want to achieve is even possible.
My boss is after getting printing costs reduced so need to look at being able to set a printer default of black and white, a user then has to manually select colour through preferences and then it will automatically revert back to a default of black and white.
I have been looking at various things online today and cant seem to find anything specific to this requirement, so not sure it is even possible.
I have considered the possibility of either a logon script that forces the print settings back or some form of task that will run say every hour in the background.
We use UTAX devices, but they are rebadged Kyocera.
The printers are connected to PCs via network, but there is no server involved. Each printer is a local install on each PC, no shares or anything like that.
PCs are running mix of Win7 and WinXP.
Something I've also considered is two instances of the printer installed - 1 for colour and 1 for black and white, naming them to reflect what they are. But I'm not convinced this will take off due to people being set in their ways for printing.
The driver version we have to work with is UTAX v6.0.2212. You can set profiles, but the factory default is colour and also if the user logs on and they change to colour from the printing default of black and white and forget to revert back then it remains on setting of colour.
Thanks in advance for any help.
I happened across your posting yesterday whilst I was looking for a similar application.
One of my clients is attempting to reduce their printing costs, specifically by reducing the number of colour prints that are produced.
We also thought about having 2 printers for each physical printer eg.
HP LaserJet (Colour)
HP LasreJet (Mono)
But felt that this was a bit of a heavy handed approach to seomthing that should be relatively simple to resolve !
As such I was looking for a methodology to allow:-
a. Automatically set the Printer to Mono at Startup
b. Allow users a rapid way to switch to Colour, if they really need to print in Colour
c. Revert back to Mono after printing
So after much head scratching I managed to produce a VB.NET application that sits in the System Tray as an icon.
This application can be started in the Login Script or Startup folder.
Ith then forces the current Default Printer to Mono
Double Clicking the System Tray icon sets the current Default Printer to Colour mode
A 60 second countdown then starts, after which the printer is reverted back to Mono.
I am hoping that this will be sufficient for my clients needs and will reduce the number of accidental colour prints.
Let me know if this would be of interest to you !
James

Change compatibility mode/run as using logon script

We have 200+ freshly imaged machines and have learned that in some of them Audacity does not work properly. For some reason, on certain (seemingly random) machines, Audacity needs to be in XPSP3 compatibility mode to run properly and be run as an administrator. Since we have 200+ of these, we are trying to find a way to tell a logon script to change Audacity for us. That way, all we have to do is start the machines and log in. I have looked around and haven't found much. Is this even possible? Thanks
To set these on a system wide basis you just need to push out a reg file like so:
-----------------------------------
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Full\\Path\\To\\File.exe"="WINXPSP3"
-----------------------------------
There are additional options if you need them, manually set some yourself and check this registry key.