Mes Notes PowerShell

Je mets ici mes notes PowerShell diverses et variées.

E-mail

Function Mail
 {
        param ([string]$sujet)

        $encoding = [System.Text.Encoding]::UTF8
        Send-MailMessage -To destination@shebangthedolphins.net -Subject $sujet -From source@shebangthedolphins.net -smtpserver smtp.shebangthedolphins.net -Body $sujet -Encoding $encoding
 }

Mail "Subject"

Fichiers

Get-WmiObject -Class Win32_service | Select-Object Name,DisplayName,startmode | Out-File -FilePath C:\services.txt
Get-ChildItem -filter *mp4 | Rename-Item -NewName {$_.Name -replace "o"}
Compare-Object (Get-Content .\kb01.csv | Sort-Object | Sort-Object -unique) (Get-Content .\kb02.csv | Sort-Object | Sort-Object -unique)
 $(Get-FileHash C:\01.zip | Select-Object -Property Hash).Hash -eq $(Get-FileHash C:\02.zip | Select-Object -Property Hash).Hash

Divers

PowerShell.exe -ExecutionPolicy Bypass -File Script.ps1
Set-Date -date "12/7/2017 4:00 PM"
Get-Date -Format "dd/MM/yyyy"
Get-HotFix | Select-Object hotfixid | Sort-Object hotfixid  | Export-Csv -path c:\$(get-date -Format "yyyy.MM.dd")_kb.csv -NoTypeInformation
Get-HotFix | Select-Object hotfixid | Sort-Object hotfixid  | Where-Object { $_ -match ".*KB156.*" }
$a = Get-Item '.\Download\myfile.txt'
$a.LastWriteTime = "10/03/2016 8:00 AM"
foreach ($app in $(Get-ChildItem | ? { $_.Name -match "exe" })) { Start-Process -FilePath ".\$($app.Name)" -ArgumentList "/s /e=.\_$($app.Name)" -Wait }

Tableaux

$myUsers = @("Stan Marsh","Kyle Broflovski","Eric Cartman","Kenny McCormick")
$myUsers = New-Object System.Collections.ArrayList
[void]$myUsers.AddRange( ("Stan Marsh","Kyle Broflovski","Eric Cartman","Kenny McCormick") )

Réseau

Get-NetIPAddress
New-NetIPAddress -InterfaceAlias "Ethernet" -ipaddress "192.168.1.111" -PrefixLength 24 -DefaultGateway "192.168.1.254"
Remove-NetIPAddress -IPAddress 192.168.1.111 -Confirm:$false
Get-Netadapter | where-object { $_.status -eq 'up' } | set-netadapter -MacAddress '001122334455' -Confirm:$flase
Get-NetConnectionProfile
Set-NetConnectionProfile -InterfaceIndex 10 -NetworkCategory Private

Programmes

Get-WmiObject Win32_product | Select-Object -Property Name,Vendor,Version | Sort-Object -Property name
Get-WmiObject Win32_product | Select-Object -Property Name,Vendor,Version | Sort-Object -Property name | Export-Csv -Path C:\prog_list.csv

Services et Processus

Services

Get-WmiObject -Class Win32_Service | Select-Object Name,DisplayName,StartMode
Get-Service | Select-Object Name,DisplayName,StartType

Processus

Get-Process -IncludeUserName | Select-Object UserName,SessionId
Get-Process -IncludeUserName | Select-Object Username,processname | Where-Object { $_.ProcessName -eq "explorer" }  | ForEach-Object {"{1}" -f $_.UserName.ToString().Split('\')}
Get-Process -IncludeUserName | Select-Object Username,processname | Where-Object { $_.ProcessName -eq "explorer" } | %{"{0}\{1}" -f $_.UserName.ToString().Split('\')[0],$_.UserName.ToString().Split('\')[1]}
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :