database-tools

Creating Local Admins

Here is a piece of code that will create a local user account and put it into the local Administrators group: $computername = $env:computername #...

read more

Bulk Renaming Files

Rename-Item can rename hundreds of files in one step. Have a look: $global:i = 1 dir c:\test1\ -Filter cover*.jpg | Rename-Item -NewName {...

read more

Monitoring Folder Content

You can use a FileSystemWatcher object to monitor a folder and write a log for all newly created files. For example, this can be used as an...

read more

Renaming Computers

PowerShell can also rename computers. The next example will read the serial number from the system enclosure class and rename the computer...

read more

Return Arrays

Normally, PowerShell will not preserve the type of an array returned by a function. It is always reduced to Object[]: function test {...

read more

Removing CSV Headers

Try this to remove column headers from a CSV file: $result = get-process | ConvertTo-Csv -Delimiter ";" $count = $result.Count -1...

read more

Finding Files

Dir (Get-Childitem) is a simple, but effective way to find files. The following line will find any file or folder called "hosts" anywhere...

read more

Open File Exclusively

To open a file in a locked state so no one else can open, access, read, or write the file, you can use the low-level .NET methods like this: $path =...

read more

Simple Breakpoint

If you want PowerShell to halt your script at some point, you can simply add this line: $host.EnterNestedPrompt() This will suspend execution and...

read more

Locking the Computer

To lock your computer from PowerShell, remember that you can launch applications, including rundll32.exe, which can be used to call methods from...

read more