Skip to main content

check admin privileges

\$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
\$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

PowerShell AutoComplete

https://dev.to/animo/fish-like-autosuggestion-in-powershell-21ec

Install-Module PSReadLine -RequiredVersion 2.1.0

To find your PowerShell Profile location we are going to use PowerShell.

  1. Open PowerShell
  2. Type $profile

How to create your PowerShell Profile (It's the equivalent of source .bashrc or source .zshrc, etc. if you are familiar with Linux.) Using PowerShell Profiles can really make your daily work a lot easier. You no longer need to navigate to the correct folder to run a script that you often use. Or you can create easy-to-use aliases for cmdlets that you use often.

The first step in creating your own profile is to test if you already have a profile. Open PowerShell and type:

test-path  \$profile

To use the profile you will need to make sure you have set the Execution Policy to Remote Signed. Otherwise, you won't be able to run the script when PowerShell opens. Make sure you run PowerShell with elevated permissions (admin mode) to change the execution policy:

Get-ExecutionPolicy

# Set the ExecutionPolicy to RemoteSigned:
Set-ExecutionPolicy RemoteSigned

Syntax

VERSION: \$PSVersionTable.PSVersion \$host.Version

Using semicolons (;):

powershell

Command1; Command2; Command3

In this example, each command is executed sequentially, regardless of the output or result of the previous command.

Rename-Item cmdlet basic syntax:

rename directories (folders). Here's the

Rename-Item -Path "<current_directory_path>" -NewName "<new_directory_name>"
  • -Path: Specifies the path of the directory you want to rename.
  • -NewName: Specifies the new name for the directory.

Here are a few examples of using the Rename-Item cmdlet to rename directories:

  1. Renaming a directory in the current location:
Rename-Item -Path "C:\Path\to\CurrentDirectory" -NewName "NewDirectoryName"

This command renames the directory CurrentDirectory to NewDirectoryName in the same location.

  1. Renaming a directory using a relative path:
Rename-Item -Path ".\OldDirectory" -NewName "NewDirectory"

This command renames the directory OldDirectory to NewDirectory in the current location.

  1. Renaming a directory using an absolute path:
Rename-Item -Path "C:\Path\to\OldDirectory" -NewName "NewDirectory"

This command renames the directory OldDirectory to NewDirectory using the absolute path.

You can also use wildcards and variables in the -Path parameter to rename multiple directories or dynamically rename directories based on certain conditions.

For more information about the Rename-Item cmdlet and additional options it supports, you can use the PowerShell help system by running Get-Help Rename-Item -Full in the PowerShell console or by referring to the official Microsoft documentation.