General
|
Command |
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 |
Select a line in a list |
$cmd=(Get-ChildItem ./ -Recurse -Include EditBin.exe).fullname | Select-String -Pattern 'Hostx86\\x86' -CaseSensitive |
Execute a variable |
& $cmd |
Delete entire directory |
Remove-Item -Recurse -Force some_dir |
Gets all commands that are installed on the computer, |
Get-Command or 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 |
Manipulation de chaine de caractères
|
Command |
Contatenation |
$VERSION_ID= $GIT_MAJOR + '.' + $GIT_MINOR + '.' + $GIT_PATCH |
Select a String (like Grep) |
Select-String "What I Look for" |
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
|
PS Command |
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 |
TBD |
tbd |
Disk & Volume
|
Command |
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 |
Exchange Online
Exchange Online PowerShell V2 module
|
PS Command |
Connect to Exchange Online |
Connect-ExchangeOnline -UserPrincipalName <admin email> |
Get Mailboxes config |
Get-EXOMailbox |