Saturday, November 21, 2020

Run PowerShell Scripts like Normal

 This is going to be a quick post, how to run a PowerShell script with a double click rather than right clicking and telling it to "Run with PowerShell." I get all the security measures, I really do. However, I want to run things when I want them and how I want them rather than making an intermediary Batch file to do so.


So it's real simple, right click your .ps1 file and go to the "Run with" option. Select the powershell.exe in C:\Windows\System32\WindowsPowerShell\v1.0 and set that as the default. Like magic, you can now double click your PowerShell scripts to run them.


The main reason I wanted this was to be able to create macros with PowerShell for my macro keys. I could have gone about it other ways, but I wanted to use PowerShell because recently I have really been digging deep into it for work. Hope this helps people.

Thursday, November 12, 2020

Fixing CPU and Other Information not Showing in Settings

 Recently at work, I was met with something I had not seen before. The CPU, RAM, and other various hardware information was not showing. It was also reporting incorrectly to our WSUS server. On top of that, tools that needed that information were not working. I did some looking around to try to find what it was, originally people at work said it was a BIOS issue. The problem there is nothing on the BIOS changed and it was working fine before. Not to mention the BIOS reported everything correctly. So I did some digging and tried to view the information with Powershell.


Get-WMIObject Win32_Processor


This would give me a message that the Win32_Processor class was missing. This is rather odd, so I did some digging. Of all the results I got, the "last resort" did the trick. I also fixed part of the batch file they had to run it because one of the commands was just giving an error and there was so much text you never would notice otherwise.


rebuildWMI.bat

@ECHO OFF
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /resetrepository
sc config winmgmt start= auto
net start winmgmt
for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s


Then I decided to make a Powershell version as a challenge to myself. Unfortunately the executables I have to run mess with the flow with their / flags, but despite that it looks okay.


Rebuild-WMI.ps1

Set-Service -Name Winmgmt -StartupType Disabled
Stop-Service -Name Winmgmt
Set-Location $env:windir\system32\wbem
Get-ChildItem -Filter "*.dll" | ForEach-Object {
    regsvr32.exe /s $_
}
wmiprvse.exe /regserver
winmgmt.exe /resetrepository
Set-Service -Name Winmgmt -StartupType Automatic
Start-Service -Name Winmgmt
Get-ChildItem .\* -Include ("*.mof", "*.mfl") | ForEach-Object {
    mofcomp.exe $_
}


This should hopefully get you all set and going should the same problem happen to you.

Tag Cloud

.NET (2) A+ (5) ad ds (1) addon (4) Android (4) anonymous functions (1) application (9) arduino (1) artificial intelligence (1) backup (1) bash (6) camera (2) certifications (3) comptia (5) css (2) customize (11) encryption (3) error (13) exploit (5) ftp (1) funny (4) gadget (4) games (3) GUI (5) hardware (16) haskell (6) help (14) HTML (3) imaging (2) irc (1) it (1) java (2) javascript (13) jobs (1) Linux (19) lua (1) Mac (4) malware (1) math (6) msp (1) network (13) perl (2) php (3) plugin (2) powershell (8) privacy (2) programming (24) python (10) radio (2) regex (3) repair (2) security (16) sound (2) speakers (2) ssh (1) story (5) Techs from the Crypt (5) telnet (1) tools (13) troubleshooting (11) tutorial (9) Ubuntu (4) Unix (2) virtualization (2) web design (6) Windows (16) world of warcraft (1) wow (1) wx (1)