Aide-Mémoire
General
PowerShell |
---|
| # Write to Screen
Write-Output "The condition was true"
# Get Power Shell Version
Get-Host | Select-Object Version
# Get Network Profile
Get-NetConnectionProfile
# List environment variables
dir env:
# Set an Env Var
$env:VAR = 'foo'
# View an Env Var
$env:VAR
# Add entry to PATH
$env:Path += ";SomeRandomPath"
# Search for a file
Get-ChildItem ./ -Recurse -Include EditBin.exe
# See fullpath of a search file
$editBinFile=(Get-ChildItem ./ -Recurse -Include EditBin.exe).fullname
# Execute a variable
& $cmd
# Delete entire directory
Remove-Item -Recurse -Force some_dir
# Gets all commands that are installed on the computer,
Get-Command
gcm
# Get location of a specic commands installed on the computer,
Get-Command <cmd name>
# Unzip Files
Expand-Archive -LiteralPath $ZIP_LOCAL -DestinationPath $APP_LOCAL
# Change Execution Policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
About Execution Policy
String manipulation
PowerShell |
---|
| # Contatenation
$VERSION_ID= $GIT_MAJOR + '.' + $GIT_MINOR + '.' + $GIT_PATCH
# Select a String (like Grep)
Select-String "What I Look for"
# Select a line in a list
$cmd=(Get-ChildItem ./ -Recurse -Include EditBin.exe).fullname | Select-String -Pattern 'Hostx86\\x86' -CaseSensitive
# Replace a string
($GIT_DESCRIBE).replace('-','.').replace('v','')
# Split a String
($GIT_DESCRIBE).split('.')
# Select an element of the split
($GIT_DESCRIBE).split('.')[2]
|
Netwoking
PowerShell |
---|
| # Get Network Profile
Get-NetConnectionProfile
# Set network connection type to private
Set-NetConnectionProfile -NetworkCategory Private
# Getting http(s) files
wget https://aka.ms/vs/16/release/vs_buildtools.exe -OutFile c:\temp\vs_buildtools.exe
|
Disk & Volume
PowerShell |
---|
| # Get Disk
Get-Disk
# Get List of Partitiona
Get-Partition
# Get List of Volime
Get-Volume
# Get number of a not partionned disk
$diskNumber = (Get-Disk | ? { ($_."PartitionStyle" -eq "RAW") }).Number
# Initialize a Disk
Initialize-Disk -Number $diskNumber -PartitionStyle "MBR"
# Create a New Partion
New-Partition -DiskNumber $diskNumber -UseMaximumSize -IsActive -AssignDriveLetter
# Format a Disk
Format-Volume -DriveLetter $part.DriveLetter -Confirm:$FALSE
|
Users & Groups
PowerShell |
---|
| # Get List of local User
Get-LocalUser
# Get List of Local Groups
Get-LocalGroup
# Add User to a Group
Add-LocalGroupMember -Group "Remote Desktop Users" -Member "RDPUserAuto"
Add-LocalGroupMember -Group "Utilisateurs du Bureau à distance" -Member "RDPUserAuto"
# List of Member in a group
Get-LocalGroupMember -Group "Utilisateurs du Bureau à distance"
Get-LocalGroupMember -Group "Administrateurs"
|
Exchange Online
Exchange Online PowerShell V2 module
PowerShell |
---|
| # Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName <admin email>
# Get Mailboxes config
Get-EXOMailbox
|