Un petit memento des commandes Powershell de base qui dépanne toujours.
Memento
Remote connect
Connect on remote conputer with powershell :
Enter-PSSession $HOSTNAME
Grep
Equivalent du grep Linux avec Powershell
AnyList | where {$_ -match ‘$FIND’}
AnyList | where {$_ -like ‘%FIND%’}
Process manage
Process list and order by %CPU
ps | sort CPU -desc
Find a process by app name
ps | where {$_ -match “$APPNAME”}
Kill process, $PROCESSID is a ID obtain with ps command.
Kill $PROCESSID
Kill process by app name
kill (ps | where {$_ -match “$APPNAME “}).Id
UPTime
Get uptime of system
(get-wmiobject -class “win32_operatingsystem” -namespace “root\CIMV2”).lastbootuptime
Get-WmiObject win32_operatingsystem | select csname, @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
Hotfix
List of hotfix installed
Get-HotFix
Get-HotFix | sort InstalledOn
RAM
Any memory informations
get-wmiobject -class “win32_physicalmemory” -namespace “root\CIMV2”
Memory quantity in Go:
To change unity change the value of Pow function.
((get-wmiobject -class “win32_physicalmemory” -namespace “root\CIMV2”).Capacity)/([math]::Pow(1024,3))
CPU
Any CPU informations
get-wmiobject -class “win32_processor”
CPU informations socket and core
get-wmiobject -class “win32_processor” | select NumberOfCores, NumberOfLogicalProcessors | FT
Drivers
List of drivers
pnputil -e
Add and install driver
pnputil –i –a $pathOfINFFiles
Disks
Space disk usage
get-WmiObject win32_logicaldisk | ForEach-Object {write-host $_.DeviceId ” : ” ($_.FreeSpace / 1GB) “Go \ ” ($_.Size / 1GB) “Go ==> % Free :” ($_.FreeSpace*100/$_.Size)}
Page File
Page file infos
Get-WmiObject Win32_PageFileusage | Select-Object Name,AllocatedBaseSize,PeakUsage
Event logs
Find event in event log security
Get-EventLog -logname security | where eventid – eq 4624 | select -first 50
Office Online
Connection to the tenant
mport-Module MSOnline
$c = Get-Credential
#Dans le fenetre saisir username + MDP : benoit@mondomain.onmicrosoft.com
Connect-MsolService -Credential $c