ČESTO POSTAVLJANA PITANJA O POWERSHELL-U NA BOSANSKOM

By | April 19, 2015

translated-bosnian


Koncept : Najčešće postavljana pitanja o Powershell-u.

Ovu listu možete koristiti na različite načine :

  • Da kopirate / zalijepite komande u niz (skriptu)
  • Da na brzinu vidite sintaksu specifične naredbe
  • Da poboljšate vaše tehničko znanje
  • Da otkrijete nove naredbe
  • Da se pripremite za razgovor za posao

Ažurirano
Jul 2, 2015
Autor powershell-guru.com
Izvor bosnian.powershell-guru.com
Kategorije
75
Pitanja
610


ACL
Active Directory
Alias
Arrays
Browsers
Certificates
Characters
CIM
Comments
COM Objects
Compare
Computer
Credentials
CSV
Culture
Date
Drives
Environment
Errors
Event Viewer
Files
Folders
Format Operator (-f)
Functions
GPO
GUI
Hardware
Hashtables
Help
History
Jobs
Keyboard
Loops
Math
Memory
Messages
Modules
Microsoft Excel
Microsoft Exchange
Microsoft Outlook
Microsoft SharePoint
Networking
Openfiles
Operators
Parameters
Password
Powershell ISE
Printers
Processes
PSObject
Quest
Random
RDP
Regedit
Regex
Remote
Restore
Scheduled Tasks
Search
SCCM
Services
SMTP
Snapins
Sounds
Static .NET Methods
Strings
System
Try/Catch
Variables
Symantec Vault
Windows10
Windows 2012
Windows Azure
Windows Forms
WMI
XML

System

Kako odrediti moju verziju PowerShella?

Kako pokrenuti PowerShell u drugoj verziji za kompatibilnost?
powershell.exe -Version 2.0

Kako zahtijevati minimalnu PowerShell verziju (3.0 i više) u scenariju s PowerShell?
#Requires -Version 3.0

Kako uz pomoć Powershella zahtijevati administrativne povlastice za niz?

Kako uz pomoć Powershella provjeriti parametre niza?
help -Name .\Get-ExchangeEnvironmentReport.ps1 -Full

Kako uz pomoć Powershella dobiti podatke za trenutnog korisnika?
[Security.Principal.WindowsIdentity]::GetCurrent()

Kako uz pomoć Powershella stvoriti, uređivati, i ponovo pokrenuti profil?

Kako uz pomoć Powershella napraviti pauzu od 5 sekundi / minuta u nizu?
Start-Sleep -Seconds 5
Start-Sleep -Seconds 300 # 5 minutes

Kako uz pomoć Powershella skratiti vrijeme butovanja?
(Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime

Kako uz pomoć Powershella ubrzati tipkanje?

Kako uz pomoć Powershella izlistati programe koji se pokreću prilikom podizanja sistema?

Kako uz pomoć Powershella deinstalirati aplikaciju?

Kako uz pomoć Powershella uraditi screenshot cijelog desktopa ili aktivnog prozora?
Take-ScreenShot -Screen -File 'C:\scripts\screenshot.png' -Imagetype JPEG
Repository : Take-ScreenShot

Kako uz pomoć Powershella dobiti brojač poruka za MSMQ redove?

Kako uz pomoć Powershella podesiti naredbe izvršavanja?

Kako uz pomoć Powershella stvoriti prečac?

Kako uz pomoć Powershella postaviti ili ukloniti program sa alatne trake?

Kako s Powershellom otvoriti Windows Explorer?
[Diagnostics.Process]::Start('explorer.exe')
Invoke-Item -Path C:\Windows\explorer.exe

Kako uz pomoć Powershella izlistati drajvere?
Get-WmiObject -Class Win32_PnPSignedDriver
Get-WindowsDriver -Online -All
driverquery.exe

Kako uz pomoć Powershella stvoriti GUID?

Kako uz pomoć Powershella dobiti lokaciju privremenog direktorija za trenutnog korisnika?
[System.IO.Path]::GetTempPath()

Kako uz pomoć Powershella putanju i potputanju spojiti u jednu putanju?
Join-Path -Path C:\ -ChildPath \windows

Kako uz pomoć Powershella izlistati sve cmdlets “Get-*”?
Get-Command -Verb Get

Kako uz pomoć Powershella izlistati posebne sistemske foldere?

Kako uz pomoć Powershella montirati ISO / VHD datoteke?
Mount-DiskImage 'D:\ISO\file.iso' # ISO
Mount-DiskImage 'D:\VHD\file.vhd' # VHD

Kako uz pomoć Powershella provjeriti verziju instaliranog .Net Frameworka?

Kako uz pomoć Powershella provjeriti da li je instalirana .NET Framework 4.5 verzija?
(Get-ItemProperty -Path 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full' -EA 0).Version -like '4.5*'

Kako uz pomoć Powershella pokrenuti i zaustaviti transkript (da se stvori zapis o Windows PowerShell sjednica)?
Start-Transcript -Path 'C:\scripts\transcript.txt
Stop-Transcript

Kako uz pomoć Powershella promijeniti trenutni direktorij u određenu lokaciju?
Set-Location -Path 'C:\scripts'

Kako uz pomoć Powershella očistiti ekran?
Clear-Host
cls # Alias

Kako promijeniti rezoluciju ekrana sa PowerShell?
Set-DisplayResolution -Width 1280 -Height 1024 -Force # Windows 2012

Kako uz pomoć Powershella prozor postaviti preko cijelog ekrana?
mode.com 300

Kako uz pomoć Powershella dobiti dimenzije (širina i visina) slike?

Kako uz pomoć Powershella dobiti Windows aktivacijski ključ?

Perfmon

Kako uz pomoć Powershella prikazati trenutne “% procesorksog vremena” (prosjek) u posljednjih 5 sekundi (10 puta)?
(Get-Counter '\Processor(_total)\% Processor Time' -SampleInterval 5 -MaxSamples 10).CounterSamples.CookedValue

Assemblies

Kako uz pomoć Powershella učitati sklopove?

Kako uz pomoć Powershella provjeriti trenutno učitane .NET sklopove?

Kako uz pomoć Powershella pronaći GAC (Global Assembly Cache) putanju?

Clipboard

Kako uz pomoć Powershella kopirati rezultate u clipboard?

Kako uz pomoć Powershella dobiti sadržak clipboarda?
Add-Type -AssemblyName PresentationCore
[Windows.Clipboard]::GetText()

Hotfixes

Kako uz pomoć Powershella prikazati instalirane hitne ispravke?
Get-HotFix -ComputerName $computer

Kako uz pomoć Powershella dobiti hitne ispravke instaliran prije / nakon određenog datuma?
Get-HotFix | Where-Object -FilterScript { $_.InstalledOn -lt ([DateTime]'01/01/2015') } # Before 01/01/2015
Get-HotFix | Where-Object -FilterScript {$_.InstalledOn -gt ([DateTime]'01/01/2015')} # After 01/01/2015

Kako uz pomoć Powershella provjeriti da li je instalirana hitna ispravka?
Get-HotFix -Id KB2965142

Kako uz pomoć Powershella dobiti hitne ispravke instalirane na udaljenom računaru?
Get-HotFix -ComputerName $computer

Pagefile

Kako uz pomoć Powershella dobiti Pagefile informacije?
Get-WmiObject -Class Win32_PageFileusage | Select-Object -Property Name, CurrentUsage, AllocatedBaseSize, PeakUsage, InstallDate

Kako uz pomoć Powershella dobiti preporučenu veličinu (MB) za Pagefile?
[Math]::Truncate(((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory) / 1MB) * 1.5

Kako uz pomoć Powershella stvoriti Pagefile (4096 MB) na (D 🙂 disku?

Kako uz pomoć Powershella izbrisati Pagefile na (C 🙂 disku?

Maintenance

Kako uz pomoć Powershella provjeriti fragmentacije diska?

Kako uz pomoć Powershella provjeriti memoriju diskova?

Up


Files

Kako uz pomoć Powershella otvoriti datoteku?
Invoke-Item -Path 'C:\scripts\file.txt'
.'C:\scripts\file.txt'

Kako uz pomoć Powershella čitati datoteku?
Get-Content -Path 'C:\scripts\file.txt'
gc "C:\scripts\file.txt" # Alias

Kako uz pomoć Powershella napisati izlaz u datoteku?
'Line1', 'Line2', 'Line3' | Out-File -FilePath 'C:\scripts\file.txt'
'Line1', 'Line2', 'Line3' | Add-Content -Path file.txt

Kako uz pomoć Powershella dobiti puni naziv trenutne skripte?
$MyInvocation.MyCommand.Path

Kako uz pomoć Powershella kompresovati / zipovati datoteke?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory($folder,$fileZIP)

Kako uz pomoć Powershella dekompresovati / odzipovati datoteke?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::ExtractToDirectory($fileZIP, $folder)

Kako uz pomoć Powershella smjestiti datoteke u ZIP arhivu?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::OpenRead($fileZIP)

Kako uz pomoć Powershella prikazati veličinu datoteke u KB?
(Get-ChildItem -Path .\winsrv.dll).Length /1KB
(Get-ChildItem -Path .\winsrv.dll).Length /1MB
(Get-ChildItem -Path .\winsrv.dll).Length /1GB

Kako uz pomoć Powershella pronaći datoteke veće ili manje od 1 GB?

Kako uz pomoć Powershella prikazati naziv datoteke bez ekstenzija?
[System.IO.Path]::GetFileNameWithoutExtension('C:\Windows\system32\calc.exe') # Return calc

Kako uz pomoć Powershella prikazati ekstenzije datoteke?
[System.IO.Path]::GetExtension('C:\scripts\file.txt') # Return .txt

Kako uz pomoć Powershella dobiti verziju datoteke?

Kako uz pomoć Powershella dobiti hash datoteke?
(Get-FileHash $file).Hash

Kako uz pomoć Powershella dobiti MD5 / SHA1 checksum datoteke?
Get-FileHash $file -Algorithm MD5
Get-FileHash $file -Algorithm SHA1

Kako uz pomoć Powershella prikazati skrivene datoteke?

Kako uz pomoć Powershella provjeriti da li datoteka ima ekstenziju?

Kako uz pomoć Powershella postaviti datoteku kao “Samo za čitanje”?
Set-ItemProperty -Path .\file.txt -Name IsReadOnly -Value $true

Kako uz pomoć Powershella promijeniti “Zadnjiputuređeno” atribut na prošle sedmice?
Set-ItemProperty -Path .\file.txt -Name LastWriteTime -Value ((Get-Date).AddDays(-7))
If not working, use Nirsoft tool: BulkFileChanger.

Kako uz pomoć Powershella stvoriti novu datoteku?
New-Item -ItemType File -Path 'C:\scripts\file.txt' -Value 'FirstLine'

Kako uz pomoć Powershella preimenovati?
Rename-Item -Path 'C:\scripts\file.txt' -NewName 'C:\scripts\powershellguru2.txt'

Kako uz pomoć Powershella preimenovati više datoteka?
Get-ChildItem -Path C:\scripts\txt | Rename-Item -NewName { $_.Name -replace ' ', '_' }

Kako uz pomoć Powershella izbrisati datoteku?
Remove-Item -Path 'C:\scripts\file.txt'

Kako uz pomoć Powershella prikazati 10 najnovijih linija datoteke?
Get-Content -Path 'C:\scripts\log.txt' -Tail 10

Kako uz pomoć Powershella deblokirati nekoliko datoteka u folderu?
Get-ChildItem -Path 'C:\scripts\Modules' | Unblock-File

Kako uz pomoć Powershella ukloniti prazne linije iz datoteke?
(Get-Content -Path file.txt) | Where-Object -FilterScript {$_.Trim() -ne '' } | Set-Content -Path file.txt

Kako uz pomoć Powershella provjeriti da li datoteka postoji?

Kako uz pomoć Powershella najnovije / najstarije kreirana datoteka u folderu?

Kako uz pomoć Powershella ukloniti duple linije iz datoteke?

Kako uz pomoć Powershella prikazati datoteke u folderu stvorene prije ili unazad mjesec dana?

Kako uz pomoć Powershella prikazati datoteke u folderu stvorene prije ili unazad 1 godinu?

Kako uz pomoć Powershella izvesti vrijednost varijable u datoteku?
Set-Content -Path file.txt -Value $variable

Kako uz pomoć Powershella izbrojati broj datoteka (* .txt) u folderu?

Kako uz pomoć Powershella pretraživati ​​scenarij unutar višestrukih datoteka?
Select-String -Path 'C:\*.txt' -Pattern 'Test'

Kako uz pomoć Powershella prikazati prvi / zadnji red datoteke?

Kako uz pomoć Powershella prikazati određeni broj linije datoteke?

Kako uz pomoć Powershella izračunati broj linija datoteke?

Kako uz pomoć Powershella izračunati broj znakova i riječi datoteke?

Kako uz pomoć Powershella skinuti datoteku?
Invoke-WebRequest -Uri 'http://www.nirsoft.net/utils/searchmyfiles.zip' -OutFile 'C:\tools\searchmyfiles.zip'

Kako uz pomoć Powershella prikazati putanju datoteke?
Resolve-Path -Path .\script.ps1 # Return C:\Scripts\script.ps1

Copy

Kako uz pomoć Powershella kopirati jednu datoteku u folder?
Copy-Item -Path 'C:\source\file.txt' -Destination 'C:\destination'

Kako uz pomoć Powershella kopirati jednu datoteku u više foldera?

Kako uz pomoć Powershella kopirati više datoteka u jedan folder?
Get-ChildItem -Path 'C:\source' -Filter *.txt | Copy-Item -Destination 'C:\destination'

Up


Active Directory

Domain & Forest

Computers

Groups

Organizational Unit (OU)

Users

Domain & Forest

Kako uz pomoć Powershella pronaći Global Catalog server u Active Directory?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs

Kako uz pomoć Powershella pronaći mjesta u Active Directory?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites

Kako uz pomoć Powershella pronaći trenutni kontroler domene?
(Get-ADDomainController).HostName

Kako uz pomoć Powershella pronaći sve kontrolera domena u domeni?

Kako uz pomoć Powershella pronaći AD prikaz grešaka?
Get-ADReplicationFailure dc02.domain.com # Windows 8 and 2012

Kako uz pomoć Powershella pronaći vijek spomenika za lokacije u Active Directory?

Kako dobiti podatke o lokacijama / domenama u Active Directory?

Kako uz pomoć Powershella dobiti putanju “obrisani objekti” kontejnera u Active Directory?
(Get-ADDomain).DeletedObjectsContainer

Kako uz pomoć Powershella omogućiti AD Recycle Bin funkciju u Active Directory?

Kako uz pomoć Powershella vratiti AD račun iz Recycle Bina u Active Directory?
Get-ADObject -Filter 'samaccountname -eq "powershellguru"' -IncludeDeletedObjects | Restore-ADObject

Kako uz pomoć Powershella pronaći FSMO uloge?

Kako se uz pomoć Powershella povezati na određeni kontroler domene?
Get-ADUser -Identity $user -Server 'serverDC01'

Kako uz pomoć Powershella dobiti trenutni logon server?

Kako uz pomoć Powershella izvršiti “gpupdate” na računaru?
Invoke-GPUpdate -Computer $computer -Force -RandomDelayInMinutes 0 # Windows 2012

Groups

Kako uz pomoć Powershella stvoriti novu grupu u Active Directory?

Kako uz pomoć Powershella ukloniti grupe u Active Directory?
Remove-ADGroup -Identity 'PowershellGuru'

Kako uz pomoć Powershella dodati korisnika u grupu u Active Directory?
Add-ADGroupMember "Powershell Guru" -Members powershellguru

Kako uz pomoć Powershella ukloniti korisnika iz grupe u Active Directory?
Remove-ADGroupMember 'Powershell Guru' -Members powershellguru

Kako uz pomoć Powershella pronaći prazne grupe (bez članova) u Active Directory?
Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}

Kako uz pomoć Powershella izbrojati prazne grupe (bez članova) u Active Directory?
(Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}).Count

Kako uz pomoć Powershella pristupiti članovima grupe u Active Directory?

Kako uz pomoć Powershella prikazati članove grupe sa ponavljajujućim članovima u Active Directory?

Kako uz pomoć Powershella izbrojati članove grupe sa / bez ponavljajućih članova u Active Directory?

Users

Kako uz pomoć Powershella koristiti wildcard u filteru “Get-ADUser” u Active Directory?

Kako uz pomoć Powershella premjestiti korisnik na drugi OU u Active Directory?
Move-ADObject -Identity $dn -TargetPath 'OU=myOU,DC=domain,DC=com'

Kako uz pomoć Powershella pronaći sve članove koji su (Ugnijezdeni) za korisnika?
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($dn))"

Kako uz pomoć Powershella prikazati članove (skraćeni naziv / krnji) za korisnika?
(Get-ADUser $user -Properties MemberOf).MemberOf | ForEach-Object -Process {($_ -split ',')[0].Substring(3)} | Sort-Object

Kako uz pomoć Powershella preimenovati Ime (Puno ime), (Prikazano ime), dato ime (Prvo ime), i prezime (prezime) za korisnički račun u Active Directory?

Kako uz pomoć Powershella promijeniti opis, ured, i broj telefona za korisnički račun u Active Directory?
Set-ADUser $samAccountName -Description 'IT Consultant' -Office 'Building B' -OfficePhone '12345'

Kako uz pomoć Powershella postaviti datum isteka na “31/12/2015” ili “nikad” za korisnički račun u Active Directory?

Kako uz pomoć Powershella otključati korisnički račun u Active Directory?
Unlock-ADAccount $samAccountName

Kako uz pomoć Powershella omogućiti / onemogućiti korisnički račun u Active Directory?

Kako uz pomoć Powershella ukloniti korisnički račun u Active Directory?
Remove-ADUser $samAccountName

Kako uz pomoć Powershella resetirati lozinku za jedan korisnički račun u Active Directory?

Kako uz pomoć Powershella resetirati lozinku za više korisničkih računa (bulk) u Active Directory?

Kako uz pomoć Powershella pronaći vlasnika datoteke u Active Directory?

Kako uz pomoć Powershella pronaći OU (Organizacijska jedinica) za korisnika u Active Directory?
[regex]::match("$((Get-ADUser $user -Properties DistinguishedName).DistinguishedName)",'(?=OU=)(.*\n?)').value

Kako uz pomoć Powershella pronaći nevažeće račune korisnika u Active Directory?

Kako uz pomoć Powershella pronaći istekle račune korisnika u Active Directory?
Search-ADAccount -AccountExpired

Kako uz pomoć Powershella pronaći zaključane račune korisnika u Active Directory?
Search-ADAccount -LockedOut

Kako uz pomoć Powershella pronaći SID jednog korisničkog računa u Active Directory?
(Get-ADUser $user -Properties SID).SID.Value

Kako uz pomoć Powershella pretvoriti korisničko ime u SID u Active Directory?

Kako uz pomoć Powershella pretvoriti SID u korisničko ime u Active Directory?

Kako uz pomoć Powershella podijeliti razlikovno ime korisničkog računa u Active Directory?

Kako uz pomoć Powershella pronaći datum kreiranja / modifikacije korisničkog računa u Active Directory?
Get-ADUser -Identity $user -Properties whenChanged, whenCreated | Format-List -Property whenChanged, whenCreated

Kako uz pomoć Powershella prikazati opcionalna i obavezna svojstva za klasu “Korisnik” u Active Directory?

Kako uz pomoć Powershella dobiti LDAP putanju za korisnika u Active Directory?

Kako uz pomoć Powershella promijeniti CN (Canonical Name) za korisnika u Active Directory?
Rename-ADObject $((Get-ADUser $user -Properties DistinguishedName).DistinguishedName) -NewName 'Test Powershell'

Kako uz pomoć Powershella prikazati organizacione jedinice (OU) korisnika u Active Directory?

Kako uz pomoć Powershella prikazati vlasnika korisnika (koji je stvorio račun) u Active Directory?

Kako uz pomoć Powershella pretvoriti PwdLastSet atribut za korisnika u Active Directory?

Computers

Kako uz pomoć Powershella ispitati siguran kanal između lokalnog računara i domene?
Test-ComputerSecureChannel

Kako uz pomoć Powershella popraviti siguran kanal između lokalnog računara i domene?
Test-ComputerSecureChannel -Repair

Kako uz pomoć Powershella onemogućiti račun u Active Directory?
Disable-ADAccount $computer

Kako uz pomoć Powershella pronaći računare sa specifičnim operativnim sistemima u Active Directory?

Organizational Unit (OU)

Kako uz pomoć Powershella stvoriti organizacione jedinice (OU) u Active Directory?
New-ADOrganizationalUnit -Name 'TEST' -Path 'DC=domain,DC=com'

Kako uz pomoć Powershella prikazati detalje Organizacijskih jedinica (OU) u Active Directory?
Get-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -Properties *

Kako uz pomoć Powershella promijeniti opis organizacione jedinice (OU) u Active Directory?
Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -Description 'My description'

Kako uz pomoć Powershella omogućiti / onemogućiti organizacione jedinica (OU) od slučajnog brisanja u Active Directory?

Kako uz pomoć Powershella omogućiti slučajno brisanje za sve organizacione jedinice (OU) u Active Directory?

Kako uz pomoć Powershella izbrisati organizacione jedinice (OU) zaštićene od slučajnog brisanja u Active Directory?

Kako uz pomoć Powershella pretvoriti DistinguishedName organizacione jedinice (OJ) u CanonicalName u Active Directory?

Kako uz pomoć Powershella izlistati prazne organizacione jedinice (OJ)?

Kako uz pomoć Powershella doći do upravitelja grupe?
(Get-ADGroup $dn -Properties Managedby).Managedby

Up


Regex (Regular Expression)

Kako uz pomoć Powershella izvući IP adresu V4 (80.80.228.8) s Regeksom?
$example = 'The IP address is 80.80.228.8'
$ip = [regex]::match($example,'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b').value

Kako uz pomoć Powershella izvući MAC adresa (C0-D9-62-39-61-2D) sa separatorom “-” s Regeksom?
$example = 'The MAC address is C0-D9-62-39-61-2D'
$mac = [regex]::match($example,'([0-9A-F]{2}[-]){5}([0-9A-F]{2})').value

Kako uz pomoć Powershella izvući MAC adresa (C0: D9: 62: 39: 61: 2D) sa separatorom “:” S Regeksom?
$example = 'The MAC address is C0:D9:62:39:61:2D'
$mac = [regex]::match($example,'((\d|([a-f]|[A-F])){2}:){5}(\d|([a-f]|[A-F])){2}').value

Kako uz pomoć Powershella izvući datum (2015/10/02) sa Regeksom?
$example = 'The date is 10/02/2015'
$date = [regex]::match($example,'(\d{2}\/\d{2}\/\d{4})').value

Kako uz pomoć Powershella izvući URL (www.powershell-guru.com) sa Regeksom?
$example = 'The URL is www.powershell-guru.com'
$url = [regex]::match($example,'[a-z]+[:.].*?(?=\s)').value

Kako uz pomoć Powershella izvući email (user@domain.com) sa Regeksom?
$example = 'The email is user@domain.com'
$email = [regex]::match($example,'(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b').value

Kako uz pomoć Powershella izvući “guru” iz niza primjera sa Regeksa?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?=.com)').value

Kako uz pomoć Powershella izvući “guru.com” iz niza primjera sa Regeksom?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?<=.)').value

Kako uz pomoć Powershella izvući “powershell-guru.com” iz niza primjera sa Regeksom?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=www.)(.*\n?)').value

Kako uz pomoć Powershella izvući “123” iz niza primjera sa Regeksom?
$example = 'Powershell123'
[regex]::match($example,'(\d+)').value

Kako uz pomoć Powershella izvući “$” (dolar znak) iz niza primjer sa Regeksom?
$example = 'Powershell`$123'
[regex]::match($example,'(\$)').value

Kako uz pomoć Powershella zamijeniti znak (* .com) s drugim (* .fr) u nizu sa Regeksom?
$example = 'www.powershell-guru.com'
[regex]::Replace($example, '.com','.fr')

Kako uz pomoć Powershella izbjeći niz s Regeksom?
[regex]::Escape('\\server\share')

Up


Memory

Kako uz pomoć Powershella prisiliti sakupljača smeća na prikupljanje memorije?
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()

Kako uz pomoć Powershella do veličine RAM-a računara?

Up


Date

Kako uz pomoć Powershella do trenutnog datum?
Get-Date
[Datetime]::Now

Kako uz pomoć Powershella prikazati datuma u različitim formatima?

Kako uz pomoć Powershella pretvoriti datum (datum) u datum (niz)?
$datetimeToString = '{0:dd/MM/yy}' -f (Get-Date 30/01/2015)
$datetimeToString = (Get-Date 31/01/2015).ToShortDateString()

Kako uz pomoć Powershella pretvoriti datum (niz) u datuma (datumvrijeme)?
$stringToDatetime = [Datetime]::ParseExact('30/01/2015', 'dd/MM/yyyy', $null)

Kako uz pomoć Powershella izračunati razliku (broj dana, sati, minute ili sekunde) između dva datuma?
(New-TimeSpan -Start $dateStart -End $dateEnd).Days
(New-TimeSpan -Start $dateStart -End $dateEnd).Hours
(New-TimeSpan -Start $dateStart -End $dateEnd).Minutes
(New-TimeSpan -Start $dateStart -End $dateEnd).Seconds

Kako uz pomoć Powershella usporediti dva datuma?
(Get-Date 2015-01-01) -lt (Get-Date 2015-01-30) # True
(Get-Date 2015-01-01) -gt (Get-Date 2015-01-30) # False

Kako uz pomoć Powershella sortirati niz datuma kao “datumvrijeme”?
$arrayDate | Sort-Object -Property {$_ -as [Datetime]}

Kako uz pomoć Powershella pokrenuti i zaustaviti štoperica?
$chrono = [Diagnostics.Stopwatch]::StartNew()
$chrono.Stop()
$chrono

Kako uz pomoć Powershella do trenutnog dana u sedmici?
(Get-Date).DayOfWeek #Sunday

Kako uz pomoć Powershella do jučerašnjeg dana?
(Get-Date).AddDays(-1)

Kako uz pomoć Powershella dobiti broj dana u mjesecu (u februaru 2015. godine)?
[DateTime]::DaysInMonth(2015, 2)

Kako uz pomoć Powershella saznati kada je prijestupna godina?
[DateTime]::IsLeapYear(2015)

Kako uz pomoć Powershella izlistati vremenske zone?
[System.TimeZoneInfo]::GetSystemTimeZones()

Up


Networking

Kako uz pomoć Powershella kodirati (u ASCII formatu) i dekodirati URL?

Kako uz pomoć Powershella odrediti šta su ekvivalenti domaćih mrežnih komandi?

Kako uz pomoć Powershella do IP adrese?
Get-NetIPAddress # Windows 8.1 & Windows 2012
Get-NetIPConfiguration # Windows 8.1 & Windows 2012

Kako uz pomoć Powershella onemogućiti IP adresu V6 (IPv6)?

Kako uz pomoć Powershella provjeriti IP adresu V4 (IPv4)?
if([ipaddress]'10.0.0.1'){'validated'}

Kako uz pomoć Powershella pronaći eksternu IP adresu?

Kako uz pomoć Powershella pronaći Hostname iz IP adrese?
([System.Net.Dns]::GetHostEntry($IP)).Hostname

Kako uz pomoć Powershella pronaći IP adresu na osnovu hostname-a?
([System.Net.Dns]::GetHostAddresses($computer)).IPAddressToString

Kako uz pomoć Powershella pronaći FQDN iz hostname-a?
[System.Net.Dns]::GetHostByName($computer).HostName

Kako uz pomoć Powershella pronaći konfiguraciju mreže (IP, Subnet, Gateway i DNS)?

Kako uz pomoć Powershella pronaći MAC adresu?
Get-CimInstance win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress
Get-WmiObject -Class win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress

Kako uz pomoć Powershella uraditi ping računara?

Kako uz pomoć Powershella provjeriti da li je računar povezan na internet?

Kako uz pomoć Powershella izvesti “whois” pretragu za web stranicu?
$whois = New-WebServiceProxy 'http://www.webservicex.net/whois.asmx?WSDL'
$whois.GetWhoIs('powershell-guru.com')

Kako uz pomoć Powershella dobiti podatke o javnoj IP adresi (Geolociranje)?

Kako uz pomoć Powershella provjeriti da li je port otvoren / zatvoren?
New-Object -TypeName Net.Sockets.TcpClient -ArgumentList $computer, 135

Kako uz pomoć Powershella obaviti “tracert”?
Test-NetConnection www.google.com -TraceRoute

Kako uz pomoć Powershella popraviti profil kućne mreže?
Get-NetAdapter | Format-Table -Property Name, InterfaceDescription, ifIndex -AutoSize # Windows 8.1
Set-NetConnectionProfile -InterfaceIndex 6 -NetworkCategory Private

Kako uz pomoć Powershella pokazati TCP port veze?
netstat.exe -ano
Get-NetTCPConnection #Windows 8 and 2012

Kako uz pomoć Powershella skratiti dug URL u maleni URL?
$url = 'www.powershell-guru.com'
$tiny = Invoke-RestMethod -Uri "http://tinyurl.com/api-create.php?url=$url"

Kako uz pomoć Powershella do proxy postavki?
Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"

DNS

Kako uz pomoć Powershella provjeriti DNS cache na lokalnom računaru?
ipconfig.exe /displaydns
Get-DnsClientCache #Windows 8 and 2012

Kako uz pomoć Powershella očistiti DNS cache na lokalnom računaru?
ipconfig.exe /flushdns
Start-Process -FilePath ipconfig -ArgumentList /flushdns -WindowStyle Hidden
Clear-DnsClientCache #Windows 8 and 2012

Kako uz pomoć Powershella očistiti DNS cache na udaljenim računarima?
Invoke-Command -ScriptBlock {Clear-DnsClientCache} -ComputerName computer01, computer02

Kako uz pomoć Powershella čitati hosts datoteku?
Get-Content -Path 'C:\Windows\system32\drivers\etc\hosts'

Up


Password

Kako uz pomoć Powershella generirati slučajnu lozinku?
[Reflection.Assembly]::LoadWithPartialName('System.Web')
[System.Web.Security.Membership]::GeneratePassword(30,2)

Kako uz pomoć Powershella promijeniti lokalnu lozinku za administratora na udaljenom serveru?
$admin = [ADSI]('WinNT://server01/administrator,user')
$admin.SetPassword($password)
$admin.SetInfo()

Kako uz pomoć Powershella pronaći datum isteka lozinke računa u Active Directory?

Up


Printers

Kako uz pomoć Powershella izlistati sve printere za određeni server?
Get-WmiObject -Query 'Select * From Win32_Printer' -ComputerName $computer

Kako uz pomoć Powershella izlistati sve portove za određeni server?
Get-WmiObject -Class Win32_TCPIPPrinterPort -Namespace 'root\CIMV2' -ComputerName $computer

Kako uz pomoć Powershella promijeniti komentar / lokaciju printera?

Kako uz pomoć Powershella očistiti (otkazati sve poslove) printera?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.CancelAllJobs()

Kako uz pomoć Powershella isprintatti probnu stranicu na printeru?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.PrintTestPage()

Kako uz pomoć Powershella dobiti print redove?

Up


Regedit

Read

Kako uz pomoć Powershella izlistati registre košnica?
Get-ChildItem -Path Registry::

Kako uz pomoć Powershella do registra vrijednosti i tipa vrijednosti?

Kako uz pomoć Powershella izlistati ključ registra potključeva?

Kako uz pomoć Powershella izlistati ključ registra potključevima na ponavljajući način?
Get-ChildItem -Path 'HKLM:\SYSTEM' -Recurse -ErrorAction SilentlyContinue

Kako uz pomoć Powershella pronaći potključeve sa specifičnim imenima?
Get-ChildItem -Path 'HKLM:\SOFTWARE' -Include *Plugin* -Recurse -ErrorAction SilentlyContinue

Kako uz pomoć Powershella vratiti samo ime registra potključeva?
(Get-ChildItem -Path 'HKLM:\SYSTEM').Name # Return HKEY_LOCAL_MACHINE\SYSTEM\ControlSet
Get-ChildItem -Path 'HKLM:\SYSTEM' -Name # Return ControlSet

Kako uz pomoć Powershella izlistati vrijednosti registra?
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'

Kako uz pomoć Powershella čitati određenu vrijednost registra?
(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ProductName

Kako uz pomoć Powershella čitati određenu vrijednost registra na udaljenom računaru?

Write

Kako uz pomoć Powershella stvoriti novi ključ registra?
New-Item -Path 'HKCU:\Software\MyApplication'

Kako uz pomoć Powershella stvoriti vrijednosti registra?
New-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '1.0'

Kako uz pomoć Powershella promijeniti postojeću vrijednost registra?
Set-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '2.0'

Delete

Kako uz pomoć Powershella izbrisati vrijednost registra?
Remove-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version'

Kako uz pomoć Powershella izbrisati ključ registra?
Remove-Item -Path 'HKCU:\Software\MyApplication' -Force

Test

Kako uz pomoć Powershella ispitati da li ključ registra postoji?
Test-Path -Path 'HKCU:\Software\MyApplication'

Kako uz pomoć Powershella ispitati da li vrijednost registra postoji?
(Get-Item -Path 'HKCU:\Software\MyApplication').GetValueNames() -contains 'Version'

Up


Strings

Kako uz pomoć Powershella ukloniti bijeli-prostor znakove od početka niza?
$string = ' PowershellGuru'
$string = $string.TrimStart()

Kako uz pomoć Powershella ukloniti bijeli-prostor znakove sa kraja niza?
$string = 'PowershellGuru '
$string = $string.TrimEnd()

Kako uz pomoć Powershella ukloniti bijeli-prostor znakove (početak i završetak) niza?
$string = ' PowershellGuru '
$string = $string.Trim()

Kako uz pomoć Powershella niz pretvoriti u velika slova?
$string = 'powershellguru'
$string = $string.ToUpper()

Kako uz pomoć Powershella niz pretvoriti u mala slova?
$string = 'POWERSHELLGURU'
$string = $string.ToLower()

Kako uz pomoć Powershella odabrati podniz “PowerShell” niza “PowerShellGuru”?
$string.Substring(0,10)

Kako uz pomoć Powershella odabrati podniz “Guru” niza “PowerShellGuru”?
$string.Substring(10)

Kako uz pomoć Powershella odabrati broj “123” za “PowerShell123Guru”?
$string = 'Powershell123Guru'
[regex]::match($string,'(\d+)').value

Kako uz pomoć Powershella dobiti nula-bazni indeks “Guru” niza “PowerShellGuru”?
$string.IndexOf('Guru') # 10

Kako uz pomoć Powershella provjeriti da li je string nulti ili prazan?
$string = $null
$string = ''
[string]::IsNullOrEmpty($string)

Kako uz pomoć Powershella provjeriti da li je niz nulti, prazan, ili se sastoji samo od bijelih prostornih znakova?
$string = $null
$string = ''
$string = ' '
[string]::IsNullOrWhiteSpace($string)

Kakouz pomoć Powershella provjeriti da li niz sadrži specifično slovo?
$string = 'PowershellGuru'
$string.Contains('s')
[regex]::match($string,'s').Success

Kako uz pomoć Powershella vratiti dužinu niza?
$string.Length

Kako uz pomoć Powershella povezati dva niza?

Kako uz pomoć Powershella upariti jednu ili više velikih zagrada”[]” u nizu?
$string = '[PowershellGuru]'
$string -match '\[' # Only 1
$string -match '\[(.*)\]' # Several

Kako uz pomoć Powershella upariti jednu ili više malih zagrada”()” u nizu?
$string = '(PowershellGuru)'
$string -match '\(' # Only 1
$string -match '\((.*)\)' # Several

Kako uz pomoć Powershella upariti za jednu ili više srednjih zagrada “{}” u nizu?
$string = '{PowershellGuru}'
$string -match '\{' # Only 1
$string -match '\{(.*)\}' # Several

Kako uz pomoć Powershella upariti jednu ili više kutnih zagrada “& lt; & gt;” u nizu?
$string = ''
$string -match '\<' # Only 1
$string -match "\<(.*)\>" # Several

Kako uz pomoć Powershella upariti bilo koja mala slova (abc) u nizu?
$string = 'POWERSHELLGURU'
$string -cmatch "^[a-z]*$" #False

Kako uz pomoć Powershella upariti bilo koja velika slova (ABC) u nizu?
$string = 'powershellguru'
$string -cmatch "^[A-Z]*$" #False

Kako uz pomoć Powershella upariti “[p” (p malo slovo) u nizu?
$string = '[powershellGuru]'
$string -cmatch '\[[a-z]\w+' #True

Kako uz pomoć Powershella upariti “[P” (P veliko slovo) u nizu?
$string = '[PowershellGuru]'
$string -cmatch '\[[A-Z]\w+' #True

Kako uz pomoć Powershella zamijeniti liniju s drugom linijom?
$a = 'Line A'
$b = 'Line B'
$a = $a -replace $a, $b

Kako uz pomoć Powershella pretvoriti divizijsku operaciju u niz (postotak)?
(1/2).ToString('P')

Kako uz pomoć Powershella sortirati nizove koji sadrže brojeve?

Kako uz pomoć Powershella odabrati posljednu riječ u rečenici?
$sentence = 'My name is Test Powershell'
$sentence.Split(' ')[-1] # Returns Powershell

Kako uz pomoć Powershella prikazati najveću riječ u rečenici?
$sentence = 'My name is Test Powershell'
$sentence.Split(' ') | Sort-Object -Property Length | Select-Object -Last 1 # Returns Powershell

Kako uz pomoć Powershella izbrojati koliko puta se niz pojavljuje u rečenicu?
$sentence = 'test test test Powershell'
[regex]::Matches($sentence, 'test').Count # Returns 3

Kako uz pomoć Powershella kopirati svaki znak u nizu u red znakova znakova?

Kako uz pomoć Powershella pretvoriti prvo slovo niza u velika slovo stringa?

Kako uz pomoć Powershella padirati (lijevo ili desno) niz?

Kako uz pomoć Powershella kodirati i dekodirati niz u base64?

Kako uz pomoć Powershella pretvoriti broj (u i iz) binarni/binarnog?

Kako uz pomoć Powershella vratiti samo posljednji nadfolder u putanji?

Kako uz pomoć Powershella vratiti samo posljednje stavku iz putanje?

Up


Math

Kako uz pomoć Powershella izlistati metode klase System.Math?
[System.Math] | Get-Member -Static -MemberType Method

Kako uz pomoć Powershella vratiti apsolutnu vrijednost?
[Math]::Abs(-12) #Returns 12
[Math]::Abs(-12.5) # Returns 12.5

Kako uz pomoć Powershella vratiti ugao čiji je sinus određeni broj?
[Math]::ASin(1) #Returns 1,5707963267949

Kako uz pomoć Powershella vratiti najvišu vrijednost?
[Math]::Ceiling(1.4) #Returns 2
[Math]::Ceiling(1.9) #Returns 2

Kako uz pomoć Powershella vratiti najnižu vrijednost?
[Math]::Floor(1.4) #Returns 1
[Math]::Floor(1.9) #Returns 1

Kako uz pomoć Powershella vratiti prirodnu (bazu e) logaritma određenog broja?
[Math]::Log(4) #Returns 1,38629436111989

Kako uz pomoć Powershella ratiti bazu 10 logaritam određenog broja?
[Math]::Log10(4) #Returns 0,602059991327962

Kako uz pomoć Powershella vratiti maksimalne dvije vrijednosti?
[Math]::Max(2,4) #Returns 4
[Math]::Max(-2,-4) #Returns -2

Kako uz pomoć Powershella vratiti minimalne dvije vrijednosti?
[Math]::Min(2,4) #Returns 2
[Math]::Max(-2,-4) #Returns -4

Kako uz pomoć Powershella vratiti broj podignut na određen stepen?
[Math]::Pow(2,4) #Returns 16

Kako uz pomoć Powershella vratiti decimalnu vrijednost do najbliže integralne vrijednosti?
[Math]::Round(3.111,2) #Returns 3,11
[Math]::Round(3.999,2) #Returns 4

Kako uz pomoć Powershella vratiti integralni dio određenog decimalnog broja?
[Math]::Truncate(3.111) #Returns 3
[Math]::Truncate(3.999) #Returns 3

Kako uz pomoć Powershella vratiti kvadratni korijen od određenog broja?
[Math]::Sqrt(16) #Returns 4

Kako uz pomoć Powershella vratiti PI konstantu?
[Math]::Pi #Returns 3,14159265358979

Kako uz pomoć Powershella vratiti prirodnu logaritamsku bazu (konstanta e)?
[Math]::E #Returns 2,71828182845905

Kako uz pomoć Powershella provjeriti je li broj paran ili neparan?
[bool]($number%2)

Up


Hashtables

Kako uz pomoć Powershella stvoriti prazan Hashtable?
$hashtable = @{}
$hashtable = New-Object -TypeName System.Collections.Hashtable

Kako uz pomoć Powershella stvoriti Hashtable sa stavkama?

Kako uz pomoć Powershella stvoriti Hashtable poredan po ključu / Ime (poredan po abecednom redu) sa stavkama?

Kako uz pomoć Powershella dodati stavke (ključ-vrijednost par) u hash tablicu?
$hashtable.Add('Key3', 'Value3')

Kako uz pomoć Powershella dobiti određenu vrijednost nekog Hashtable-a?
$hashtable.Key1
$hashtable.Get_Item('Key1')

Kako uz pomoć Powershella dobiti minimalnu vrijednost jedne Hashtable?

Kako uz pomoć Powershella dobiti maksimalnu vrijednost za Hashtable?

Kako uz pomoć Powershella promijeniti stavke u Hashtable?
$hashtable.Set_Item('Key1', 'Value1Updated')

Kako uz pomoć Powershella ukloniti stavke u Hashtable?
$hashtable.Remove('Key1')

Kako uz pomoć Powershella očistiti jedan Hashtable?
$hashtable.Clear()

Kako uz pomoć Powershella provjeriti prisustvo određenog ključa / vrijednosti u Hashtable-u?
$hashtable.ContainsKey('Key3')
$hashtable.ContainsValue('Value3')

Kako uz pomoć Powershella sortirati ključ / vrijednost u Hashtable-u?
$hashtable.GetEnumerator() | Sort-Object -Property Name
$hashtable.GetEnumerator() | Sort-Object -Property Value -Descending

Up


Arrays

Kako uz pomoć Powershella stvoriti prazan red?
$array = @()
$array = [System.Collections.ArrayList]@()

Kako uz pomoć Powershella stvoriti red sa stavkama?
$array = @('A', 'B', 'C')
$array = 'A', 'B', 'C'
$array = 'a,b,c'.Split(',')
$array = .{$args} a b c
$array = echo a b c

Kako uz pomoć Powershella dodati stavke u red?
$array += 'D'
[void]$array.Add('D')

Kako uz pomoć Powershella promijeniti stavku u redu?
$array[0] = 'Z' # 1st item[0]

Kako uz pomoć Powershella provjeriti veličinu reda?
$array = 'A', 'B', 'C'
$array.Length # Returns 3

Kako uz pomoć Powershella vratiti jednu stavku / nekoliko / sve stavke u redu?
$array = @('A', 'B', 'C')
$array[0] # One item (A)
$array[0] + $array[2] # Several items (A,C)
$array # All items (A,B,C)

Kako ukloniti prazna stavki u nizu s PowerShell?
$array = @('A', 'B', 'C', '')
$array = $array.Split('',[System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object # A,B,C

Kako uz pomoć Powershella provjeriti da li postoji stavka u redu?
$array = @('A', 'B', 'C')
'A' | ForEach-Object -Process {$array.Contains($_)} # Returns True
'D' | ForEach-Object -Process {$array.Contains($_)} # Returns False

Kako uz pomoć Powershella pronaći indeksni broj stavke u redu?
$array = @('A', 'B', 'C')
[array]::IndexOf($array,'A') # Returns 0

Kako uz pomoć Powershella preokrenuti redoslijed stavki u redu?
$array = @('A', 'B', 'C')
[array]::Reverse($array) # C,B,A

Kako uz pomoć Powershella generirati slučajnu stavku iz reda?
$array | Get-Random

Kako uz pomoć Powershella sortirati red u rastućem / padajućem nizu?
$array = @('A', 'B', 'C')
$array | Sort-Object # A,B,C
$array | Sort-Object -Descending # C,B,A

Kako uz pomoć Powershella izbrojati broj stavki u redu?
$array.Count

Kako uz pomoć Powershella dodati red u drugi?
$array1 = 'A', 'B', 'C'
$array2 = 'D', 'E', 'F'
$array3 = $array1 + $array2 # A,B,C,D,E,F

Kako uz pomoć Powershella pronaći duplikate iz reda?
$array = 'A', 'B', 'C', 'C'
($array | Group-Object | Where-Object -FilterScript {$_.Count -gt 1}).Values # Returns C

Kako uz pomoć Powershella ukloniti duplikate iz reda ?
$array = 'A', 'B', 'C', 'C'
$array = $array | Select-Object -Unique
$array # Returns A,B,C

Kako uz pomoć Powershella stvoriti red sa stavkama koje počinju s prefiksom (“korisnik01”, “korisnik02”, … “korisnik10”)?
$array = 1..10 | ForEach-Object -Process { "user$_" }

Up


ACL

Kako uz pomoć Powershella izlistati ACL od AD korisnika?
(Get-Acl -Path "AD:\$dn").Access

Kako uz pomoć Powershella izlistati ACL foldera?
(Get-Acl -Path C:\scripts).Access

Kako uz pomoć Powershella izlistati specifične unose ACL dozvola (korisnike ili grupe) od AD korisnika?

Up


Variables

Koje su najčešće vrste podataka s PowerShellom?

Kako uz pomoć Powershella pronaći minimalne i maksimalne vrijednosti za neke vrste varijabli?

Kako uz pomoć Powershella ispitati tip podataka?

Kako uz pomoć Powershella stvoriti Ovdje-String varijable?