FAQ POWERSHELL KU ZULU

By | May 18, 2015


beta-v2-0


Umcabango : Njalo kunazo ukubuzwa mayelana Powershell.

Ungasebenzisa lolu hlu ngezindlela ezahlukene :

  • Ukukopisha / nokunamathisela imiyalo ibe umbhalo
  • Ukuze ubone ngokushesha syntax sa umyalo oqondile
  • Ukuze uthuthukise ulwazi lwakho lobuchwepheshe
  • Ukuthola imiyalo emisha
  • Ukuze kulungiswe ukuxoxa naye umsebenzi

Kubuyekeziwe
July 02, 2015
Umbhali Steve Renard
Umthombo zulu.powershell-guru.com
Isigaba
75
Imibuzo
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

Indlela ukuze ukunquma okufushane yami ye PowerShell?

Indlela ukuze ukugijima PowerShell kwenye ukuhumushela kungasebenziswa okudala?
powershell.exe -Version 2.0

Indlela zidinga PowerShell ukuhumushela sakugcina (3.0 futhi ephakeme) ku umbhalo nge PowerShell?
#Requires -Version 3.0

Indlela zidinga amalungelo nolokuphatha umbhalo nge PowerShell?

Indlela ukuhlola kwemigomo umbhalo nge PowerShell?
help -Name .\Get-ExchangeEnvironmentReport.ps1 -Full

Indlela ukuze uthole ulwazi lomsebenzisi zamanje nge PowerShell?
[Security.Principal.WindowsIdentity]::GetCurrent()

Indlela ukudala, uhlele, bese ulayisha kabusha iphrofayela PowerShell?

Indlela ukwenza kwakuke kumiwe imizuzwana 5 / imizuzu in umbhalo nge PowerShell?
Start-Sleep -Seconds 5
Start-Sleep -Seconds 300 # 5 minutes

Indlela uthole lokugcina ebhuthini isikhathi nge PowerShell?
(Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime

Indlela uthole hlobo namafutha nge PowerShell?

Indlela uhlu izinhlelo sokuqalisa nge PowerShell?

Indlela khipha isicelo PowerShell?

Indlela ukuthatha skrini wonke bekhompuyutha noma i kwewindi esebenzayo kanye PowerShell?
Take-ScreenShot -Screen -File 'C:\scripts\screenshot.png' -Imagetype JPEG
Repository : Take-ScreenShot

Indlela ukuze uthole umlayezo ukubala MSMQ emigqeni nge PowerShell?

Indlela ukusetha inqubomgomo ukwenza nge PowerShell?

Indlela ukwakha ishothikhathi nge PowerShell?

Indlela athunge noma iphini uhlelo the yendawo yemisebenzi nge PowerShell?

Indlela ukuvula Iwindi Wamazwe nge PowerShell?
[Diagnostics.Process]::Start('explorer.exe')
Invoke-Item -Path C:\Windows\explorer.exe

Indlela zibhale idivayisi abashayeli PowerShell?
Get-WmiObject -Class Win32_PnPSignedDriver
Get-WindowsDriver -Online -All
driverquery.exe

Indlela ukwakha GUID nge PowerShell?

Indlela uthole indawo lwemibhalo yesikhashana umsebenzisi lwamanje nalo PowerShell?
[System.IO.Path]::GetTempPath()

Indlela ujoyine endleleni kanye endleleni ingane ibe enye indlela eyodwa nge PowerShell?
Join-Path -Path C:\ -ChildPath \windows

Indlela bhala yonke cmdlets “ngi-” PowerShell?
Get-Command -Verb Get

Indlela zibhale ekhethekile uhlelo amafolda PowerShell?

Indlela ukukhweza ISO / VHD amafayela PowerShell?
Mount-DiskImage 'D:\ISO\file.iso' # ISO
Mount-DiskImage 'D:\VHD\file.vhd' # VHD

Indlela ukuhlola .NET Framework izinguqulo efakwe PowerShell?

Indlela ukuhlola uma .NET Framework ukuhumushela 4.5 efakwe nge PowerShell?
(Get-ItemProperty -Path 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full' -EA 0).Version -like '4.5*'

Indlela ukuqala futhi bayeke a okulotshiweyo (ukwakha irekhodi esimisweni Iwindi Amandla-Igobongo) nge PowerShell?
Start-Transcript -Path 'C:\scripts\transcript.txt
Stop-Transcript

Indlela ukushintsha lwemibhalo yamanje endaweni ethize nge PowerShell?
Set-Location -Path 'C:\scripts'

Indlela ukusula izibuko nge PowerShell?
Clear-Host
cls # Alias

Indlela ukushintsha isibonisi zwi lesinqumo PowerShell?
Set-DisplayResolution -Width 1280 -Height 1024 -Force # Windows 2012

Indlela ukusetha “isihenqo esigcwele” ifasitela PowerShell?
mode.com 300

Indlela uthole Ubukhulu (nobubanzi nokuphakama kwawo) sa isithombe nge PowerShell?

Indlela uthole Windows umkhiqizo isihluthulelo nge PowerShell?

Perfmon

Indlela uthole wamanje “% Inqubo Isikhathi” (isilinganiso) in the last 5 imizuzwana (izikhathi 10) nge PowerShell?
(Get-Counter '\Processor(_total)\% Processor Time' -SampleInterval 5 -MaxSamples 10).CounterSamples.CookedValue

Assemblies

Indlela ukulayisha yesifunda PowerShell?

Indlela hlola samanje .NET emincane nemikhulu, zithwesiwe PowerShell?

Indlela ukuthola GAC ​​(Umhlangano okuyimbulunga Yemibhalo Yehhovisi) dlela PowerShell?

Clipboard

Indlela ukukopisha imiphumela ebhodini lokunamathisela nge PowerShell?

Indlela uthole okuqukethwe yokunamathisela nge PowerShell?
Add-Type -AssemblyName PresentationCore
[Windows.Clipboard]::GetText()

Hotfixes

Indlela uthole hotfixes efakwe PowerShell?
Get-HotFix -ComputerName $computer

Indlela uthole hotfixes efakwe ngaphambi / ngemuva kosuku oluthile nge PowerShell?
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

Indlela ukuhlola uma hotfix efakwe nge PowerShell?
Get-HotFix -Id KB2965142

Indlela uthole hotfixes efakwe ikhompuyutha kanye PowerShell?
Get-HotFix -ComputerName $computer

Pagefile

Indlela ukuze uthole ulwazi eliyikhasi nge PowerShell?
Get-WmiObject -Class Win32_PageFileusage | Select-Object -Property Name, CurrentUsage, AllocatedBaseSize, PeakUsage, InstallDate

Indlela uthole ubukhulu watusa (MB) ngoba eliyikhasi nge PowerShell?
[Math]::Truncate(((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory) / 1MB) * 1.5

Indlela ukwakha eliyikhasi (4096 MB) phezu kwa (D 🙂 ukushayela PowerShell?

Indlela Ukususa ifayela kwi (C 🙂 ukushayela PowerShell?

Maintenance

Indlela ukuhlola nokwehlukaniswa oshayelayonge PowerShell?

Indlela ukuhlola isikhala indingilizi eyisicaba oshayelayo nge PowerShell?

Up


Files

Indlela ukuvula ifayela PowerShell?
Invoke-Item -Path 'C:\scripts\file.txt'
.'C:\scripts\file.txt'

Indlela ukufunda ifayela PowerShell?
Get-Content -Path 'C:\scripts\file.txt'
gc "C:\scripts\file.txt" # Alias

Indlela lubhale okukhiphayo ifayela PowerShell?
'Line1', 'Line2', 'Line3' | Out-File -FilePath 'C:\scripts\file.txt'
'Line1', 'Line2', 'Line3' | Add-Content -Path file.txt

Indlela uthole igama eligcwele lwamanje umbhalo ifayela PowerShell?
$MyInvocation.MyCommand.Path

Indlela cindezela / zip amafayela PowerShell?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory($folder,$fileZIP)

Indlela hhayi cindezela / amafayela HhayiZip nge PowerShell?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::ExtractToDirectory($fileZIP, $folder)

Indlela ukubona amafayela in a archive ZIP nge PowerShell?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::OpenRead($fileZIP)

Indlela ukubonisa ubukhulu ifayela ka KB nge PowerShell?
(Get-ChildItem -Path .\winsrv.dll).Length /1KB
(Get-ChildItem -Path .\winsrv.dll).Length /1MB
(Get-ChildItem -Path .\winsrv.dll).Length /1GB

Indlela yokuthola amafayela ezinkulu noma esingaphansi 1 GB nge PowerShell?

Indlela ibonise igama ifayela ngaphandle ukwelula nge PowerShell?
[System.IO.Path]::GetFileNameWithoutExtension('C:\Windows\system32\calc.exe') # Return calc

Indlela babonise ukwelulwa ifayela nge PowerShell?
[System.IO.Path]::GetExtension('C:\scripts\file.txt') # Return .txt

Indlela uthole ukuhumushela ifayela ye ifayela nge PowerShell?

Indlela uthole hashi ifayela nge PowerShell?
(Get-FileHash $file).Hash

Indlela uthole MD5 / SHA1 hlolasum ifayela nge PowerShell?
Get-FileHash $file -Algorithm MD5
Get-FileHash $file -Algorithm SHA1

Indlela ukubonisa amafayela ethukusiwe nge PowerShell?

Indlela ukuhlola uma ifayela ine ukwelulwa nge PowerShell?

Indlela ukusetha ifayela ngokuthi “Funda Kudivayisi kuphela” nge PowerShell?
Set-ItemProperty -Path .\file.txt -Name IsReadOnly -Value $true

Indlela ukushintsha “OkokugcinaBhalaIsikhathi” imfanelo ukuze ngesonto eledlule nge PowerShell?
Set-ItemProperty -Path .\file.txt -Name LastWriteTime -Value ((Get-Date).AddDays(-7))
If not working, use Nirsoft tool: BulkFileChanger.

Indlela ukwakha ifayela entsha nge PowerShell?
New-Item -ItemType File -Path 'C:\scripts\file.txt' -Value 'FirstLine'

Indlela kabusha ifayela PowerShell?
Rename-Item -Path 'C:\scripts\file.txt' -NewName 'C:\scripts\powershellguru2.txt'

Indlela ngobuningi / batch ukuqamba kabusha amafayela amaningi kanye PowerShell?
Get-ChildItem -Path C:\scripts\txt | Rename-Item -NewName { $_.Name -replace ' ', '_' }

Indlela ukususa ifayela nge PowerShell?
Remove-Item -Path 'C:\scripts\file.txt'

Indlela ukubonisa imizila 10 yakamuva ye ifayela nge PowerShell?
Get-Content -Path 'C:\scripts\log.txt' -Tail 10

Indlela ukuvinjwa amafayela eziningana kwifolda nge PowerShell?
Get-ChildItem -Path 'C:\scripts\Modules' | Unblock-File

Indlela ukususa imigqa engenalutho kusukela ifayela nge PowerShell?
(Get-Content -Path file.txt) | Where-Object -FilterScript {$_.Trim() -ne '' } | Set-Content -Path file.txt

Indlela ukuhlola uma ifayela likhona nge PowerShell?

Indlela uthole entsha / ifayela endala wadala kwifolda nge PowerShell?

Indlela ukususa ngeduplikhethi olayini ifayela nge PowerShell?

Indlela uthole amafayela wadala ngaphezulu noma inyanga esingaphansi 1 kwifolda nge PowerShell?

Indlela uthole amafayela wadala ngaphezulu noma unyaka esingaphansi 1 kwifolda nge PowerShell?

Indlela okuthekelisa ukubaluleka a variable ukuba ifayela nge PowerShell?
Set-Content -Path file.txt -Value $variable

Indlela babala amafayela (* .txt) kwifolda nge PowerShell?

Indlela ukucinga intambo ngaphakathi amafayela amaningi kanye nge PowerShell?
Select-String -Path 'C:\*.txt' -Pattern 'Steve'

Indlela babonise / umugqa wokuqala lokugcina ifayela nge PowerShell?

Indlela ukubonisa umugqa isibalo esithile ifayela nge PowerShell?

Indlela ukubala inani imizila ifayela nge PowerShell?

Indlela ukubala inani abalingiswa kanye amazwi ifayela nge PowerShell?

Indlela ukulanda ifayela nge PowerShell?
Invoke-WebRequest -Uri 'http://www.nirsoft.net/utils/searchmyfiles.zip' -OutFile 'C:\tools\searchmyfiles.zip'

Indlela ukubonisa indlela egcwele ifayela nge PowerShell?
Resolve-Path -Path .\script.ps1 # Return C:\Scripts\script.ps1

Copy

Indlela ukukopisha ifayela eyodwa kwifolda nge PowerShell?
Copy-Item -Path 'C:\source\file.txt' -Destination 'C:\destination'

Indlela ukukopisha ifayela eyodwa amafolda amaningi kanye nge PowerShell?

Indlela ukukopisha amafayela amaningi ukuba kwifolda eyodwa nge PowerShell?
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

Indlela yokuthola Global Catalog kumaseva umumo nge PowerShell?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs

Indlela ukuthola amasayithi umumo nge PowerShell?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites

Indlela yokuthola wamanje domain isilawuli nge PowerShell?
(Get-ADDomainController).HostName

Indlela yokuthola zonke abalawula ka domain nge PowerShell?

Indlela ukuthola ukwehluleka AD ukufanisana nge PowerShell?
Get-ADReplicationFailure dc02.domain.com # Windows 8 and 2012

Indlela ukuthola esaphila itshe lethuna for the ehlathini Active Directory nge PowerShell?

Indlela uthole imininingwane yehlathi / domain ka Isiqondisi Asebenzayo nge PowerShell?

Indlela uthole indlela “Izinto Ukususa” isitsha umumo nge PowerShell?
(Get-ADDomain).DeletedObjectsContainer

Indlela ikwazi AD Ubhini Wokulahla Udoti sici Isiqondisi Asebenzayo nge PowerShell?

Indlela abuyisele akhawunti AD kusukela Ubhini Wokulahla Udoti Isiqondisi Asebenzayo nge PowerShell?
Get-ADObject -Filter 'samaccountname -eq "powershellguru"' -IncludeDeletedObjects | Restore-ADObject

Indlela ukuthola izindima FSMO nge PowerShell?

Indlela ukuxhuma domain isilawuli othize kanye nge PowerShell?
Get-ADUser -Identity $user -Server 'serverDC01'

Indlela uthole Logon iseva lwamanje nalo nge PowerShell?

Indlela ukwenza “gpupdate” kwikhompyutha nge PowerShell?
Invoke-GPUpdate -Computer $computer -Force -RandomDelayInMinutes 0 # Windows 2012

Groups

Indlela ukwakha iqembu elisha ngo Isiqondisi Asebenzayo nge PowerShell?

Indlela ukususa iqembu Isiqondisi Asebenzayo nge PowerShell?
Remove-ADGroup -Identity 'PowershellGuru'

Indlela ukwengeza umsebenzisi Isiqondisi Asebenzayo nge PowerShell?
Add-ADGroupMember "Powershell Guru" -Members powershellguru

Indlela ukususa umsebenzisi kusukela Isiqondisi Asebenzayo nge PowerShell?
Remove-ADGroupMember 'Powershell Guru' -Members powershellguru

Indlela yokuthola amaqembu ezingenalutho (kungabikho amalungu) ka Isiqondisi Asebenzayo nge PowerShell?
Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}

Indlela ukubala amaqembu ezingenalutho (kungabikho amalungu) ka Isiqondisi Asebenzayo nge PowerShell?
(Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}).Count

Indlela uthole amalungu eqembu ka Isiqondisi Asebenzayo nge PowerShell?

Indlela uthole amalungu eqembu kanye namalungu recursive Isiqondisi Asebenzayo nge PowerShell?

Indlela ukubala inani amalungu eqembu nge / ngaphandle kwamalungu recursive Isiqondisi Asebenzayo nge PowerShell?

Users

Indlela ukusebenzisa isikhethi in the lemifanekiso “Thola-ADUser” Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuhambisa umsebenzisi kwenye OU Isiqondisi Asebenzayo nge PowerShell?
Move-ADObject -Identity $dn -TargetPath 'OU=myOU,DC=domain,DC=com'

Indlela yokuthola onke amaLunga ukuthi kukhona (Isidleke) ngoba umsebenzisi PowerShell?
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($dn))"

Indlela uthole Amalungu (igama dlala idemo / uncishisiwe) ka umsebenzisi PowerShell?
(Get-ADUser $user -Properties MemberOf).MemberOf | ForEach-Object -Process {($_ -split ',')[0].Substring(3)} | Sort-Object

Indlela kabusha Igama (IgamaEligcwele), (BonisaIgama), IgamaElinikeziwe (IgamaKuqala), ne Sibongo (GcinayoIgama)-akhawunti yomsebenzisi ku umumo nge PowerShell?

Indlela ukushintsha incazelo, Ihhovisi, futhi nenombolo yocingo-akhawunti yomsebenzisi ku umumo nge PowerShell?
Set-ADUser $samAccountName -Description 'IT Consultant' -Office 'Building B' -OfficePhone '12345'

Indlela ukusetha okungapheli ukuba “31/12/2015” noma “Ungalokothi ‘i-akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuvula i-akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
Unlock-ADAccount $samAccountName

Indlela sikwazi / ukukhubaza akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukususa akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
Remove-ADUser $samAccountName

Indlela kabusha iphasiwedi ye-akhawunti eyodwa umsebenzisi Isiqondisi Asebenzayo nge PowerShell?

Indlela kabusha iphasiwedi akhawunti ambalwa umsebenzisi (ubukhulu) ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuthola umnikazi ifayela ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuthola OU (Okukodwa kwenhlangano) for umsebenzisi Isiqondisi Asebenzayo nge PowerShell?
[regex]::match("$((Get-ADUser $user -Properties DistinguishedName).DistinguishedName)",'(?=OU=)(.*\n?)').value

Indlela yokuthola abakhubazekile akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela yokuthola osekudlulelwe akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
Search-ADAccount -AccountExpired

Indlela yokuthola PUK akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
Search-ADAccount -LockedOut

Indlela ukuthola SID akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
(Get-ADUser $user -Properties SID).SID.Value

Indlela ukuguqula igama lomsebenzisi ukuze SID ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuguqula SID lomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuqhekeza Igama Tihambi akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela yokuthola usuku kwendalo / ukuguqulwa akhawunti yomsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
Get-ADUser -Identity $user -Properties whenChanged, whenCreated | Format-List -Property whenChanged, whenCreated

Indlela babonise izindawo ozikhethela naletibekiwe ngoba isigaba “Umsebenzisi” ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuze uthole indlela uHlelo for umsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukushintsha CN (EBhayibheli Igama) ngoba umsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?
Rename-ADObject $((Get-ADUser $user -Properties DistinguishedName).DistinguishedName) -NewName 'Steve Renard'

Indlela uthole Unit kwenhlangano (OU) umzali umsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Indlela uthole umnikazi umsebenzisi (owadala akhawunti) ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuguqula ngemfanelo PwdLastSet for umsebenzisi ku Isiqondisi Asebenzayo nge PowerShell?

Computers

Indlela ukuhlola ishaneli okuphephile phakathi ikhompyutha wendawo kanye domain PowerShell?
Test-ComputerSecureChannel

Indlela yokulungisa umzila ephephile phakathi ikhompyutha wendawo kanye domain PowerShell?
Test-ComputerSecureChannel -Repair

Indlela ukukhubaza akhawunti ikhompyutha Isiqondisi Asebenzayo nge PowerShell?
Disable-ADAccount $computer

Indlela yokuthola amakhompyutha kanye ezithile Operating Systems in Isiqondisi Asebenzayo nge PowerShell?

Organizational Unit (OU)

Indlela ukudala i Okukodwa kwenhlangano (OU) ku Isiqondisi Asebenzayo nge PowerShell?
New-ADOrganizationalUnit -Name 'STEVE' -Path 'DC=domain,DC=com'

Indlela uthole Okukodwa kwenhlangano (OU) imininingwane ku Isiqondisi Asebenzayo nge PowerShell?
Get-ADOrganizationalUnit 'OU=STEVE,DC=domain,DC=com' -Properties *

Indlela ukushintsha incazelo i Okukodwa kwenhlangano (OU) ku Isiqondisi Asebenzayo nge PowerShell?
Set-ADOrganizationalUnit 'OU=STEVE,DC=domain,DC=com' -Description 'My description'

Indlela sikwazi / ukukhubaza i Okukodwa kwenhlangano (OU) kusukela ekususeni ngephutha ku Isiqondisi Asebenzayo nge PowerShell?

Indlela sikwazi ukususwa ngephutha for zonke Okukodwa kwenhlangano (OU) ku Isiqondisi Asebenzayo nge PowerShell?

Indlela ukususa Okukodwa kwenhlangano (OU) avikelekile umumo kusukela Isiqondisi Asebenzayo nge PowerShell?

Indlela ukuguqula Igama Ukuhlukanisa i Okukodwa kwenhlangano (OU) ukuba EBhayibheli Igama Isiqondisi Asebenzayonge PowerShell?

Indlela zibhale Okukodwa yenhlangano ezingenalutho (hlukahlukene) nge PowerShell?

Indlela ukuze uthole imenenja yeqembu nge PowerShell?
(Get-ADGroup $dn -Properties Managedby).Managedby

Up


Regex (Regular Expression)

Indlela kukhishwe i v4 ikheli lasesizindeni se-intanethi (80.80.228.8) nge Regex nge PowerShell?
$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

Indlela ukukhipha ikheli MAC (C0-D9-62-39-61-2D) nge wokucwenga “-” with Regex nge PowerShell?
$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

Indlela ukukhipha ikheli le-MAC (C0: D9: 62: 39: 61: 2D) with wokucwenga “:” with Regex nge PowerShell?
$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

Indlela ukukhipha usuku (10/02/2015) nge Regex nge PowerShell?
$example = 'The date is 10/02/2015'
$date = [regex]::match($example,'(\d{2}\/\d{2}\/\d{4})').value

Indlela ukukhipha URL (www.powershell-guru.com) nge Regex nge PowerShell?
$example = 'The URL is www.powershell-guru.com'
$url = [regex]::match($example,'[a-z]+[:.].*?(?=\s)').value

Indlela kukhishwe i-imeyli (user@domain.com) nge Regex nge PowerShell?
$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

Ungawukhipha kanjani umucwana “guru” esibonelweni intambo nge Regex nge PowerShell?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?=.com)').value

Ungawukhipha kanjani umucwana “guru.com” esibonelweni string nge Regex nge PowerShell?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?<=.)').value

Ungawukhipha kanjani umucwana “powershell-guru.com” esibonelweni intambo nge Regex nge PowerShell?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=www.)(.*\n?)').value

Ungawukhipha kanjani umucwana “123” esibonelweni intambo nge Regex nge PowerShell?
$example = 'Powershell123'
[regex]::match($example,'(\d+)').value

Ungawukhipha kanjani umucwana “$” (dollar uphawu) esibonelweni intambo nge Regex nge PowerShell?
$example = 'Powershell`$123'
[regex]::match($example,'(\$)').value

Indlela esikhundleni uhlamvu (* .com) nomunye (* .fr) ngendlela intambo nge Regex nge Amandla-Igobongo?
$example = 'www.powershell-guru.com'
[regex]::Replace($example, '.com','.fr')

Indlela ukubaleka intambo nge Regex nge Amandla-Igobongo?
[regex]::Escape('\\server\share')

Up


Memory

Indlela ukuphoqa iqoqo inkumbulo by the ngalendoda udoti nge Amandla-Igobongo?
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()

Indlela uthole ubukhulu RAM-computer nge Amandla-Igobongo?

Up


Date

Indlela ukuze uthole usuku lwamanje nalo nge Amandla-Igobongo?
Get-Date
[Datetime]::Now

Indlela ukubonisa usuku ngetakhiwo letehlukene kanye nge Amandla-Igobongo?

Indlela ukuguqula usuku (UsukuNesikhathi) osukwini (Intambo) nge Amandla-Igobongo?
$datetimeToString = '{0:dd/MM/yy}' -f (Get-Date 30/01/2015)
$datetimeToString = (Get-Date 31/01/2015).ToShortDateString()

Indlela ukuguqula usuku (Intambo) osukwini (UsukuNesikhathi) nge Amandla-Igobongo?
$stringToDatetime = [Datetime]::ParseExact('30/01/2015', 'dd/MM/yyyy', $null)

Indlela ukubala umehluko (inombolo Wezinsuku, amahora, imizuzu, noma Seconds) phakathi izinsuku ezimbili nge Amandla-Igobongo?
(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

Indlela qhathanisa izinsuku ezimbili nge Amandla-Igobongo?
(Get-Date 2015-01-01) -lt (Get-Date 2015-01-30) # True
(Get-Date 2015-01-01) -gt (Get-Date 2015-01-30) # False

Indlela uhlunge uxhaxha izinsuku ngokuthi “UsukuNesikhathi” nge Amandla-Igobongo?
$arrayDate | Sort-Object -Property {$_ -as [Datetime]}

Indlela ukuqala futhi bayeke a isitophuwashi nge Amandla-Igobongo?
$chrono = [Diagnostics.Stopwatch]::StartNew()
$chrono.Stop()
$chrono

Indlela ukuze uthole usuku wamanje we ngesonto Amandla-Igobongo?
(Get-Date).DayOfWeek #Sunday

Indlela uthole usuku lwayizolo nge Amandla-Igobongo?
(Get-Date).AddDays(-1)

Indlela ukuze uthole inani lezinsuku ngenyanga (ku February 2015) nge Amandla-Igobongo?
[DateTime]::DaysInMonth(2015, 2)

Indlela ukwazi unyaka eqa nge Amandla-Igobongo?
[DateTime]::IsLeapYear(2015)

Indlela zibhale zezikhathi nge Amandla-Igobongo?
[System.TimeZoneInfo]::GetSystemTimeZones()

Up


Networking

Indlela encode (to ASCII isimo) kanye ukuqopha i-URL Amandla-Igobongo?

Yiziphi anomqondo bomdabu inethiwekhi imiyalo nge Amandla-Igobongo?

Indlela uthole amakheli IP nge Amandla-Igobongo?
Get-NetIPAddress # Windows 8.1 & Windows 2012
Get-NetIPConfiguration # Windows 8.1 & Windows 2012

Indlela ukukhubaza IP address v6 (IPv6) nge Amandla-Igobongo?

Indlela ukuqinisekisa i v4 ikheli lasesizindeni se-intanethi (IPv4) nge Amandla-Igobongo?
if([ipaddress]'10.0.0.1'){'validated'}

Indlela ukuthola yangaphandle ikheli le-IP Amandla-Igobongo?

Indlela ukuthola Igama lomethuleli kusukela ikheli le-IP nge Amandla-Igobongo?
([System.Net.Dns]::GetHostEntry($IP)).Hostname

Indlela yokuthola ikheli le-IP kusuka Igama lomethuleli nge Amandla-Igobongo?
([System.Net.Dns]::GetHostAddresses($computer)).IPAddressToString

Indlela ukuthola FQDN kusukela Igama lomethuleli nge Amandla-Igobongo?
[System.Net.Dns]::GetHostByName($computer).HostName

Indlela ukuthola ukumiswa kwenethiwekhi (Ip, subnet, Gateway, futhi DNS) nge Amandla-Igobongo?

Indlela yokuthola ikheli MAC nge Amandla-Igobongo?
Get-CimInstance win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress
Get-WmiObject -Class win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress

Indlela Ping kwikhompyutha nge Amandla-Igobongo?

Indlela ukuhlola uma ikhompyutha ixhunyiwe ku-inthanethi nge Amandla-Igobongo?

Indlela enze ‘whois’ Ukubheka ngoba a website nge Amandla-Igobongo?
$whois = New-WebServiceProxy 'http://www.webservicex.net/whois.asmx?WSDL'
$whois.GetWhoIs('powershell-guru.com')

Indlela uthole imininingwane a IP yomphakathi (Geolocation) nge Amandla-Igobongo?

Indlela ukuhlola uma port ivuliwe / avalwa Amandla-Igobongo?
New-Object -TypeName Net.Sockets.TcpClient -ArgumentList $computer, 135

Indlela ukwenza “tracert” with Amandla-Igobongo?
Test-NetConnection www.google.com -TraceRoute

Indlela ukulungisa kunethiwekhi ekhaya iphrofayili uxhumano nge Amandla-Igobongo?
Get-NetAdapter | Format-Table -Property Name, InterfaceDescription, ifIndex -AutoSize # Windows 8.1
Set-NetConnectionProfile -InterfaceIndex 6 -NetworkCategory Private

Indlela ukukhombisa ukuxhumana TCP echwebeni nge Amandla-Igobongo?
netstat.exe -ano
Get-NetTCPConnection #Windows 8 and 2012

Indlela unciphise URL eside ibe URL esincane Amandla-Igobongo?
$url = 'www.powershell-guru.com'
$tiny = Invoke-RestMethod -Uri "http://tinyurl.com/api-create.php?url=$url"

Indlela uthole izilungiselelo proxy nge Amandla-Igobongo?
Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"

DNS

Indlela ukuhlola isilondolozi DNS kwikhompyutha wendawo nge Amandla-Igobongo?
ipconfig.exe /displaydns
Get-DnsClientCache #Windows 8 and 2012

Indlela ukususa isilondolozi DNS kwikhompyutha wendawo nge Amandla-Igobongo?
ipconfig.exe /flushdns
Start-Process -FilePath ipconfig -ArgumentList /flushdns -WindowStyle Hidden
Clear-DnsClientCache #Windows 8 and 2012

Indlela ukususa isilondolozi DNS kumakhompyutha ezikude Amandla-Igobongo?
Invoke-Command -ScriptBlock {Clear-DnsClientCache} -ComputerName computer01, computer02

Indlela ukufunda Sebawoti ifayela nge Amandla-Igobongo?
Get-Content -Path 'C:\Windows\system32\drivers\etc\hosts'

Up


Password

Indlela ukukhiqiza iphasiwedi okungahleliwe Amandla-Igobongo?
[Reflection.Assembly]::LoadWithPartialName('System.Web')
[System.Web.Security.Membership]::GeneratePassword(30,2)

Indlela ukushintsha iphasiwedi wendawo for an umlawuli on server ezikude Amandla-Igobongo?
$admin = [ADSI]('WinNT://server01/administrator,user')
$admin.SetPassword($password)
$admin.SetInfo()

Indlela yokuthola iphasiwedi usuku lokuphelelwa isikhathi akhawunti in umumo nge Amandla-Igobongo?

Up


Printers

Indlela bhala yonke abanyathelisi ngoba iseva oluthile nge PowerShell?
Get-WmiObject -Query 'Select * From Win32_Printer' -ComputerName $computer

Indlela bhala yonke emachwebeni ngoba iseva oluthile nge PowerShell?
Get-WmiObject -Class Win32_TCPIPPrinterPort -Namespace 'root\CIMV2' -ComputerName $computer

Indlela ukushintsha umbono / indawo yokunyathelisa nge PowerShell?

Indlela ukuhlambulula (ukukhansela yonke imisebenzi) kwiphrinta nge PowerShell?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.CancelAllJobs()

Indlela ukuphrinta ikhasi ukuhlola ngoba kwiphrinta nge PowerShell?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.PrintTestPage()

Indlela uthole ukuphrinta emigqeni abanyathelisi nge PowerShell?

Up


Regedit

Read

Indlela zibhale ebhukwini isifuba nge PowerShell?
Get-ChildItem -Path Registry::

Indlela uthole ebhukwini amagugu nokubaluleka izinhlobo nge PowerShell?

Indlela zibhale ebhukwini key subkeys nge PowerShell?

Indlela zibhale ukhiye lokubhalisa subkeys ngendlela recursive nge PowerShell?
Get-ChildItem -Path 'HKLM:\SYSTEM' -Recurse -ErrorAction SilentlyContinue

Indlela yokuthola subkeys igama ethize nge PowerShell?
Get-ChildItem -Path 'HKLM:\SOFTWARE' -Include *Plugin* -Recurse -ErrorAction SilentlyContinue

Indlela ukubuyela kuphela igama subkeys ebhukwini nge PowerShell?
(Get-ChildItem -Path 'HKLM:\SYSTEM').Name # Return HKEY_LOCAL_MACHINE\SYSTEM\ControlSet
Get-ChildItem -Path 'HKLM:\SYSTEM' -Name # Return ControlSet

Indlela zibhale ebhukwini amagugu nge PowerShell?
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'

Indlela ukufunda eqondiwe ebhukwini ubugugu nge PowerShell?
(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ProductName

Indlela ukufunda letsite ebhukwini ubugugu on ikhompuyutha kanye PowerShell?

Write

Indlela ukwakha entsha ebhukwini isihluthulelo nge PowerShell?
New-Item -Path 'HKCU:\Software\MyApplication'

Indlela ukwakha ubugugu ebhukwini nge PowerShell?
New-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '1.0'

Indlela ukushintsha i ebhukwini ubugugu ezikhona PowerShell?
Set-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '2.0'

Delete

Indlela ukususa ubugugu ebhukwini nge PowerShell?
Remove-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version'

Indlela ukususa ukhiye ebhukwini nge PowerShell?
Remove-Item -Path 'HKCU:\Software\MyApplication' -Force

Test

Indlela ukuhlola uma ukhiye ebhukwini likhona PowerShell?
Test-Path -Path 'HKCU:\Software\MyApplication'

Indlela ukuhlola uma ubugugu ebhukwini likhona PowerShell?
(Get-Item -Path 'HKCU:\Software\MyApplication').GetValueNames() -contains 'Version'

Up


Strings

Indlela ukususa okumhlophe-isikhala izinhlamvu kusukela ekuqaleni a string nge PowerShell?
$string = ' PowershellGuru'
$string = $string.TrimStart()

Indlela ukususa okumhlophe-isikhala izinhlamvu kusukela ekupheleni a string nge PowerShell?
$string = 'PowershellGuru '
$string = $string.TrimEnd()

Indlela ukususa okumhlophe-isikhala izinhlamvu (ukuqala nesiphetho) of a string nge PowerShell?
$string = ' PowershellGuru '
$string = $string.Trim()

Indlela ukuguqula entanjeni icala eliphezulu PowerShell?
$string = 'powershellguru'
$string = $string.ToUpper()

Indlela ukuguqula intambo ukwehlisa kunjalo PowerShell?
$string = 'POWERSHELLGURU'
$string = $string.ToLower()

Indlela ukukhetha substring “PowerShell” ngoba intambo “PowerShellGuru” with PowerShell?
$string.Substring(0,10)

Indlela ukukhetha substring “Guru” ngoba intambo “PowerShellGuru” with PowerShell?
$string.Substring(10)

Indlela ukukhetha inamba “123” of “PowerShell123Guru” with PowerShell?
$string = 'Powershell123Guru'
[regex]::match($string,'(\d+)').value

Indlela uthole index zero-based of “Guru” ngoba intambo “PowerShellGuru” with PowerShell?
$string.IndexOf('Guru') # 10

Indlela ukuhlola uma intambo kuba nalutho nge PowerShell?
$string = $null
$string = ''
[string]::IsNullOrEmpty($string)

Indlela ukuhlola uma intambo kuba null, ezingenalutho, noma siqukethe kuphela okumhlophe-isikhala izinhlamvu nge PowerShell?
$string = $null
$string = ''
$string = ' '
[string]::IsNullOrWhiteSpace($string)

Indlela ukuhlola uma intambo iqukethe incwadi oluthile nge PowerShell?
$string = 'PowershellGuru'
$string.Contains('s')
[regex]::match($string,'s').Success

Indlela ukubuyela ubude intambo nge PowerShell?
$string.Length

Indlela concatenate intambo ezimbili kanye PowerShell?

Indlela ukufanisa owodwa noma kubakaki eziningana “[]” ngo intambo nge PowerShell?
$string = '[PowershellGuru]'
$string -match '\[' # Only 1
$string -match '\[(.*)\]' # Several

Indlela ukufanisa owodwa noma parentheses amaningana “()” ku intambo nge PowerShell?
$string = '(PowershellGuru)'
$string -match '\(' # Only 1
$string -match '\((.*)\)' # Several

Indlela ukufanisa owodwa noma kubakaki eziningana abacaphuni “{} ‘ku intambo nge PowerShell?
$string = '{PowershellGuru}'
$string -match '\{' # Only 1
$string -match '\{(.*)\}' # Several

Indlela ukufanisa owodwa noma kubakaki eziningana angle “<>” ku intambo nge PowerShell?
$string = ''
$string -match '\<' # Only 1
$string -match "\<(.*)\>" # Several

Indlela ukufanisa yimuphi izinhlamvu ezincane (ABC) ku intambo nge PowerShell?
$string = 'POWERSHELLGURU'
$string -cmatch "^[a-z]*$" #False

Indlela ukufanisa yimuphi upperletters (ABC) ku intambo nge PowerShell?
$string = 'powershellguru'
$string -cmatch "^[A-Z]*$" #False

Indlela ukufanisa “[p” (p icala aphansi) ngendlela intambo nge PowerShell?
$string = '[powershellGuru]'
$string -cmatch '\[[a-z]\w+' #True

Indlela ukufanisa “[P” (P icala eliphezulu) ngendlela intambo nge PowerShell?
$string = '[PowershellGuru]'
$string -cmatch '\[[A-Z]\w+' #True

Indlela esikhundleni umugqa nomunye ngokuvumelana PowerShell?
$a = 'Line A'
$b = 'Line B'
$a = $a -replace $a, $b

Indlela ukuguqula umsebenzi division ukuba intambo (iphesenti) nge PowerShell?
(1/2).ToString('P')

Indlela uhlunge strings aqukethe izinombolo nge PowerShell?

Indlela ukhetha igama lokugcina umusho PowerShell?
$sentence = 'My name is Steve Renard'
$sentence.Split(' ')[-1] # Returns Renard

Indlela uthole izwi elikhulu kunawo wonke umusho PowerShell?
$sentence = 'My name is Steve Renard'
$sentence.Split(' ') | Sort-Object -Property Length | Select-Object -Last 1 # Returns Renard

Indlela ukubala izikhathi intambo elikhona ngaphakathi umusho PowerShell?
$sentence = 'steve steve steve renard'
[regex]::Matches($sentence, 'steve').Count # Returns 3

Indlela ukukopisha umlingisi ngamunye ngentambo uxhaxha uhlamvu nge PowerShell?

Indlela ukuguqula incwadi yokuqala ukuba usonhlamvukazi ngoba intambo nge PowerShell?

Indlela pad (kwesobunxele noma kwesokudla) intambo nge PowerShell?

Indlela encode futhi ukunquma entanjeni Base64 nge PowerShell?

Indlela ukuguqula inamba (kuya nokusuka) kanambambili nge PowerShell?

Indlela ukubuyela ifolda umzali kuphela wokugcina in a dlela PowerShell?

Indlela ukubuyela kuphela yinto yokugcina in a dlela PowerShell?

Up


Math

Indlela uhlu izindlela ekilasini System.Math nge PowerShell?
[System.Math] | Get-Member -Static -MemberType Method

Indlela ukubuyela ukubaluleka ngokuphelele nge PowerShell?
[Math]::Abs(-12) #Returns 12
[Math]::Abs(-12.5) # Returns 12.5

Indlela ukubuyela engela ogama sine inombolo esibekiwe nge PowerShell?
[Math]::ASin(1) #Returns 1,5707963267949

Indlela ukubuyela ukubaluleka ophahleni kanye PowerShell?
[Math]::Ceiling(1.4) #Returns 2
[Math]::Ceiling(1.9) #Returns 2

Indlela ukubuyela ukubaluleka phansi PowerShell?
[Math]::Floor(1.4) #Returns 1
[Math]::Floor(1.9) #Returns 1

Indlela babuyisele yemvelo (base e) logarithm ngoba isibalo esibekiwe nge PowerShell?
[Math]::Log(4) #Returns 1,38629436111989

Indlela babuyisele base 10 logarithm ngoba isibalo esibekiwe nge PowerShell?
[Math]::Log10(4) #Returns 0,602059991327962

Indlela ukubuyela kufike amanani amabili kanye PowerShell?
[Math]::Max(2,4) #Returns 4
[Math]::Max(-2,-4) #Returns -2

Indlela babuyisele okungenani amanani amabili kanye PowerShell?
[Math]::Min(2,4) #Returns 2
[Math]::Max(-2,-4) #Returns -4

Indlela ukubuyela inombolo wavuselwa amandla ecacisiwe nge PowerShell?
[Math]::Pow(2,4) #Returns 16

Indlela ukubuyela value lokweshumi ukubaluleka eliseduze ebalulekile nge PowerShell?
[Math]::Round(3.111,2) #Returns 3,11
[Math]::Round(3.999,2) #Returns 4

Indlela ukubuyela ingxenye ebalulekile inombolo wezinombolo esibekiwe nge PowerShell?
[Math]::Truncate(3.111) #Returns 3
[Math]::Truncate(3.999) #Returns 3

Indlela ukubuyela impande skwele a isibalo esibekiwe nge PowerShell?
[Math]::Sqrt(16) #Returns 4

Indlela ukubuyela njalo PI nge PowerShell?
[Math]::Pi #Returns 3,14159265358979

Indlela babuyisele base logarithmic yemvelo (e njalo) nge PowerShell?
[Math]::E #Returns 2,71828182845905

Indlela ukuhlola uma inombolo ngisho noma okuthile nge PowerShell?
[bool]($number%2)

Up


Hashtables

Indlela ukudala i ithebulahashi ezingenalutho PowerShell?
$hashtable = @{}
$hashtable = New-Object -TypeName System.Collections.Hashtable

Indlela ukwakha ithebulahashi nge izinto PowerShell?

Indlela ukwakha ithebulahashi ihlelwa key / ngegama (isichazamazwi wayala) nge izinto PowerShell?

Indlela ukwengeza izinto (key-value pair) ukuba a ithebulahashi nge PowerShell?
$hashtable.Add('Key3', 'Value3')

Indlela uthole value eqondile ithebulahashi nge PowerShell?
$hashtable.Key1
$hashtable.Get_Item('Key1')

Indlela uthole value okungenani a ithebulahashi nge PowerShell?

Indlela uthole seqiwe of a ithebulahashi nge PowerShell?

Indlela ukushintsha izinto ngendlela ithebulahashi nge PowerShell?
$hashtable.Set_Item('Key1', 'Value1Updated')

Indlela ukususa izinto ngendlela ithebulahashi nge PowerShell?
$hashtable.Remove('Key1')

Indlela ukususa ithebulahashi nge PowerShell?
$hashtable.Clear()

Indlela ukuhlola khona key / value lemcoka ithebulahashi nge PowerShell?
$hashtable.ContainsKey('Key3')
$hashtable.ContainsValue('Value3')

Indlela ukuhlunga key / value ngota ithebulahashi nge PowerShell?
$hashtable.GetEnumerator() | Sort-Object -Property Name
$hashtable.GetEnumerator() | Sort-Object -Property Value -Descending

Up


Arrays

Indlela ukwakha uxhaxha ezingenalutho PowerShell?
$array = @()
$array = [System.Collections.ArrayList]@()

Indlela ukudala uxhaxha nge izinto PowerShell?
$array = @('A', 'B', 'C')
$array = 'A', 'B', 'C'
$array = 'a,b,c'.Split(',')
$array = .{$args} a b c
$array = echo a b c

Indlela ukwengeza izinto uxhaxha nge PowerShell?
$array += 'D'
[void]$array.Add('D')

Indlela ukushintsha into uxhaxha nge PowerShell?
$array[0] = 'Z' # 1st item[0]

Indlela ukuhlola ubukhulu uxhaxha nge PowerShell?
$array = 'A', 'B', 'C'
$array.Length # Returns 3

Indlela ukubuyisa into eyodwa / eziningana / zonke izinto uxhaxha nge PowerShell?
$array = @('A', 'B', 'C')
$array[0] # One item (A)
$array[0] + $array[2] # Several items (A,C)
$array # All items (A,B,C)

Indlela ukususa izinto angenalutho uxhaxha nge PowerShell?
$array = @('A', 'B', 'C', '')
$array = $array.Split('',[System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object # A,B,C

Indlela ukuhlola uma into ekhona e uxhaxha nge PowerShell?
$array = @('A', 'B', 'C')
'A' | ForEach-Object -Process {$array.Contains($_)} # Returns True
'D' | ForEach-Object -Process {$array.Contains($_)} # Returns False

Indlela ukuthola inombolo uhlu into uxhaxha nge PowerShell?
$array = @('A', 'B', 'C')
[array]::IndexOf($array,'A') # Returns 0

Indlela ukuhlanekezela oda izinto in uxhaxha nge PowerShell?
$array = @('A', 'B', 'C')
[array]::Reverse($array) # C,B,A

Indlela ukukhiqiza into okungahleliwe kusukela uxhaxha nge PowerShell?
$array | Get-Random

Indlela uhlunge uxhaxha in an inyuka / zehla indlela PowerShell?
$array = @('A', 'B', 'C')
$array | Sort-Object # A,B,C
$array | Sort-Object -Descending # C,B,A

Indlela ukubala izinto uxhaxha nge PowerShell?
$array.Count

Indlela ukwengeza uxhaxha kwenye nge PowerShell?
$array1 = 'A', 'B', 'C'
$array2 = 'D', 'E', 'F'
$array3 = $array1 + $array2 # A,B,C,D,E,F

Indlela yokuthola okuphindiwe kusukela uxhaxha nge PowerShell?
$array = 'A', 'B', 'C', 'C'
($array | Group-Object | Where-Object -FilterScript {$_.Count -gt 1}).Values # Returns C

Indlela ukususa okuphindiwe kusukela uxhaxha nge PowerShell?
$array = 'A', 'B', 'C', 'C'
$array = $array | Select-Object -Unique
$array # Returns A,B,C

Indlela ukudala uxhaxha lwezinto uthome sicalo (“user01”, “user02”, … “user10”) kanye PowerShell?
$array = 1..10 | ForEach-Object -Process { "user$_" }

Up


ACL

Indlela zibhale ACL of an umsebenzisi AD nge PowerShell?
(Get-Acl -Path "AD:\$dn").Access

Indlela zibhale ACL of a ifolda nge PowerShell?
(Get-Acl -Path C:\scripts).Access

Indlela zibhale ezithile ACL imvume entries (abasebenzisi noma amaqembu) umsebenzisi AD nge PowerShell?

Up


Variables

Yiziphi idatha lwezinhlobo ezivame kakhulu nge PowerShell?

Indlela ukuthola okungenani kanye namagugu esiphezulu ngoba abanye eziguquguqukayo hlobo PowerShell?

Indlela ukuhlola datatype nge PowerShell?

Indlela ukwakha Lapha-Intambo ngafani nge PowerShell?

Indlela ukwakha ngafani nge PowerShell?
$powershellGuru = 'Hello'

Indlela ukwakha ngafani njalo PowerShell?
Set-Variable -Name powershellGuru -Value 2015 -Option Constant

Indlela ukwakha ngafani global nge PowerShell?
$Global:powershellGuru = 'Hello'

Indlela ukufunda ngafani nge PowerShell?
$powershellGuru = 'Hello' # Create
$powershellGuru # Read
Get-Variable -Name powershellGuru -ValueOnly # Read

Indlela ukuhlola uhlobo ngafani nge PowerShell?
$powershellGuru.GetType()

Indlela ukuthola eziguquguqukayo in the kwenkululeko global nge PowerShell?
Get-Variable -Scope Global

Indlela uthole eziguquguqukayo ethize ngegama nge PowerShell?
Get-Variable -Include *Preference -Exclude W*

Indlela ukwabela eqondiwe idatha uhlobo ngafani nge PowerShell?
[int64]$variable = 100
[string]$variable = 'PowershellGuru'

Indlela ukuqalisa eziguquguqukayo amaningi ukubaluleka efanayo nge PowerShell?
$a = $b = $c = $d = $e = 0

Siyini alias ngoba ngafani “$ _” nge PowerShell?
Get-Process | Where-Object -FilterScript {$_.Handles -gt 1000} # Using $_
Get-Process | Where-Object -FilterScript {$PSItem.Handles -gt 1000} # Using $PSItem (since version 3)

Indlela ukususa eziguquguqukayo igama eziqala “ubale” nge PowerShell?
Remove-Variable -Name count*

Indlela uthole imvelo eziguquguqukayo wendawo nge PowerShell?
Get-ChildItem -Path Env:

Indlela uthole Indlela umudwa Kwemvelo eliguqukayo ngaze ngokuvumelana PowerShell?
($env:Path) -replace(';', "`n")
[Environment]::GetEnvironmentVariable('Path') -replace(';', "`n")

Indlela ukwengeza entsha endleleni (ex C:. \ SysinternalsSuite) kuya Indlela eliguqukayo Eliguqukayo nge PowerShell?
$env:Path += ';C:\SysinternalsSuite'
$env:Path = $env:Path + ';C:\SysinternalsSuite'

Indlela concatenate eziguquguqukayo nge PowerShell?
$a = 'Powershell'
$b = '- Guru'
$c = $a + $b

Indlela yokusebenzisa Iphutha Ngafani nge PowerShell?
Get-ChildItem -Path 'C:\PerfLogs' -ErrorAction SilentlyContinue -ErrorVariable AccessDenied
$AccessDenied | ForEach-Object -Process {$_.Exception}
$AccessDenied | ForEach-Object -Process {$_.TargetObject}

Indlela sikwazi / ukuvimbela okulingana “Option Explicit” (VBScript: idinga ukuthi ngafani kuthiwe) nge PowerShell?

Up


Static .NET Methods

Indlela uthole amalungu bethela nge PowerShell?
[DateTime] | Get-Member -Static

Up


Sounds

Idlalwa kanjani i-“Beep” umsindo PowerShell?
[System.Console]::Beep()

Idlalwa kanjani i-“asterisk” umsindo PowerShell?
[System.Media.SystemSounds]::Asterisk.Play()

Idlalwa kanjani i-“esithi” umsindo PowerShell?
[System.Media.SystemSounds]::Exclamation.Play()

Indlela uthole umsindo itholakala nge PowerShell?
[System.Media.SystemSounds] | Get-Member -Static

Idlalwa kanjani “WAV” imisindo PowerShell?
$soundPlayer = New-Object -TypeName System.Media.SoundPlayer -ArgumentList "$env:windir\Media\Ringout.wav"
$soundPlayer.Play()
noma
$soundPlayer.PlayLooping()
$soundPlayer.Stop()

Indlela kusebenze inkulumo ebhaliwe ngezithombe PowerShell?
Add-Type -AssemblyName System.Speech
$speech = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$speech.Speak('Hello PowershellGuru')

Up


XML

Indlela ukufunda ifayela XML nge PowerShell?
[xml]$sitemap = Get-Content -Path .\sitemap.xml
$sitemap.urlset.url

Indlela ukuthekelisa idatha njengoba ifayela XML nge PowerShell?
Get-Process | Export-Clixml -Path C:\scripts\processes.xml

Indlela ukungenisa idatha kusuka ifayela CLIXML nge PowerShell?
$importProcesses = Import-Clixml -Path C:\scripts\processes.xml

Up


GUI

Indlela ukwakha GUI eyisisekelo (Ifomu window) nge PowerShell?

Up


Characters

Indlela ukuguqula ukubaluleka ASCII umlingisi nge PowerShell?
[char]64

Indlela ukuguqula uhlamvu ukubaluleka ASCII nge PowerShell?
[int][char]'@'

Indlela ukukhiqiza zamagama English nge PowerShell?
[char[]](97..122)

Up


Compare

Indlela qhathanisa amaqoqo amaningi ezimbili kanye PowerShell?

Indlela qhathanisa izinqubo ezimbili kanye PowerShell?

Up


Microsoft Exchange

Indlela ukubuyisa uhlu kumadivayisi eselula ezazihambisana sebhokisi abasebenzisi ‘nge PowerShell?
Get-ActiveSyncDeviceStatistics

Indlela ukwengeza “Okugcwele Ukufinyelela ‘izimvume ibhokisi leposi for a umsebenzisi PowerShell?
Add-MailboxPermission -Identity $dn -User 'DOMAIN\powershellguru' -AccessRights 'FullAccess'

Indlela ukususa “Okugcwele Ukufinyelela ‘izimvume ibhokisi leposi for a umsebenzisi PowerShell?
Remove-MailboxPermission -Identity $dn -User 'DOMAIN\powershellguru' -AccessRights 'FullAccess' -InheritanceType 'All'

Indlela ukwengeza “Thumela Njengoba ‘izimvume ibhokisi leposi for a umsebenzisi PowerShell?
Add-ADPermission -Identity $dn -User 'DOMAIN\powershellguru' -ExtendedRights 'Send-As'

Indlela ukususa “Thumela Njengoba ‘izimvume ibhokisi leposi for a umsebenzisi PowerShell?

Indlela ukuthola imithetho ebhokisini lengenayo kusukela ibhokisi leposi kanye PowerShell?
Get-InboxRule -Mailbox 'Powershell.Guru'

Indlela uthole ikheli SMTP for abasebenzisi Owa (Outlook Web Access) anikwe amandla PowerShell?
Get-CASMailbox -Filter{OWAEnabled -eq $true} | Select-Object -Property Name, PrimarySMTPAddress

Exchange 2007

Indlela ukufaka zidinga ngoba iseva Ukushintsha Iseva 2007 Hub Transport, kwibhokisi lemeyili (MBX), kanye iKlayenti Access Server (CAS) nge PowerShell?

Exchange 2010

Indlela ukufaka zidinga ngoba iseva Ukushintsha Iseva 2010 Hub Transport, kwibhokisi lemeyili (MBX), kanye iKlayenti Access Server (CAS) nge PowerShell?

Exchange 2013

Indlela ukufaka zidinga ngoba kwibhokisi lemeyili ngoba iseva Ukushintsha Iseva 2013 (MBX) kanye Client Access Server (CAS) nge PowerShell?

Indlela ukufaka zidinga ngoba iseva Ukushintsha Iseva 2013 Iklayenti Access Server (CAS) kuphela nge PowerShell?