Category Archives: PowerShell

Helpful Windows Admin Tips


To launch Windows Update from the Windows Run dialog:

ms-settings:windowsupdate


Use Powershell to kill processes with a name filter:

Get-Process | Where-Object {$_.Path -like "*SOME-FILTER*"} | Stop-Process


See what time computer was booted up:

net statistics server


Restart or Shut Down a Remote Computer and Document the Reason

shutdown /i

(from https://technet.microsoft.com/en-us/library/cc770416(v=ws.11).aspx)


Using DISKPART from the command line to work on disk drives, volumes, partitions:

https://www.digitalcitizen.life/command-prompt-advanced-disk-management-commands

http://searchwindowsserver.techtarget.com/tip/Using-Diskpart-to-create-extend-or-delete-a-disk-partition


Activating Windows 10: https://www.howtogeek.com/245445/how-to-use-slmgr-to-change-remove-or-extend-your-windows-license/


Changing Windows Product Key After Install: http://tweaks.com/windows/39026/change-windows-product-key-after-install/


Windows Search error: “Search results aren’t quite ready yet, but we’re working on getting them together. Try back in a few minutes.”

https://www.weavweb.net/2016/12/19/search-results-arent-quite-ready-yet-but-were-working-on-getting-them-together-try-back-in-a-few-minutes/


Read original Windows 10 License Key using Power Shell:

Then, read Windows Key from “OA3xOriginalProductKey” property from output above.

(from https://gallery.technet.microsoft.com/scriptcenter/Get-windows-10-digital-7653fae4)

See also: https://robertsmit.wordpress.com/2017/03/19/get-windows-10-digital-license-with-powershell-winserv-osd-wds/


PowerShell: Get a list from the registry of all the software installed on your machine


PowerShell: List open files on a server/computer

Example with filename filter:

Example with domain\username filter:

 

Configure Windows Defender using PowerShell

References

I found these 2 links very helpful and informative which explain how to use PowerShell commands to observe the current setting of Windows Defender and make configuration changes such as disabling and enabling, and how to add exclusions on certain apps.

#1

http://www.thomasmaurer.ch/2016/07/how-to-disable-and-configure-windows-defender-on-windows-server-2016-using-powershell/

#2

and this one, which has a short but helpful video: http://www.netometer.com/blog/?p=1579

Add Windows Defender exclusion for iBackup exe

In my case, I wanted to add an exclusion for the iBackup exe which runs nightly to do a local disk backup to another drive on the same machine, and Windows Defender was watching every file write operation in real time, and this made the backup take a very long time. So, I added an exclusion for the iBackup processes exe using this command, and it sped up the backup tremendously:

 

Sql Server queries using PowerShell – Lesson 1

It’s actually pretty easy to throw a SQL query against Sql Server using PowerShell.   This would be very familiar to any C# or FoxPro developer, so don’t let the mystery of Power Shell scare you away from exploring this handy tool.

Here’s a tiny code snippet to show you how simple it is:

powershell_screenshot_1_getting_started

Note that the call to the DoSql() function is a wrapper function that I wrote which creates a few PowerShell objects to do all the low level work so that you don’t have to repeat all that connection and plumbing stuff in your scripts. Once you have that in place, executing Sql queries is a piece of cake.  After you get back the query results, PowerShell has all the standard language features you’d expect such as looping and counting, and even some cool sorting and filtering tricks that are pretty handy for working with the data rows.

Helper functions

 

From here, it becomes really easy to add system admin things shooting off an email, or calling a Stored Proc, or writing a Windows Event log entry, or call an external API, or blah-blah-blah.

Every modern version of Windows has PowerShell pre-installed, and it even has a simple IDE (Called PowerShell ISE ) to give you a coding environment with intellisense, code completion, and debugging tools.

Note: I found this article very helpful in learning how to do this: https://cmatskas.com/execute-sql-query-with-powershell/