ሃሳብ ፓወር ሼል ላይ የሚጠየቁ በጣም በተደጋጋሚ ጥያቄዎች
እነዚህን መዘርዝሮች በተለያየ መንገድ መጠቀም ይቻላል
- ማዘዣዎችን ስክሪፕት ላይ ለመቅዳት/ለመለጠፍ
- በአፋጣኝ የአንድን ልዩ ማዘዣ አፃፃፍ ለማየት
- ቴክኒካል እውቀትን ለማጎልበት
- አዲስ ማዘዣን ለማሰስ
- ለስራ ቃለ መጠይቅ ለመዘጋጀት
ተሻሽሎአል |
2015/28/06
|
ጸሃፊ | powershell-guru.com |
ምንጭ | amharic.powershell-guru.com |
ምድብ |
75
|
ጥያቄዎች |
610
|
System
የኔን ፓወር ሼል እትም እንዴት ማወቅ እችላለሁ?
1 2 3 4 5 6 7 8 9 |
# via Powershell $PSVersionTable.PSVersion.Major # via Registry (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine').PowerShellVersion # Versions 1 and 2 (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine').PowerShellVersion # Versions 3 and 4 # via Remote Invoke-Command -ComputerName $computer -ScriptBlock { $PSVersionTable.PSVersion.Major } |
ፓወር ሼልን በሌላኛው እትም እንዴት ማሮጥ እችላለሁ ከኋለኛው ጋር እንዲዛመድ?
powershell.exe -Version 2.0
ትንሹን የፓወር ሼል እትም እንዴት መጠየቅ እችላለሁ (3.0 ወይም ከዛ በላይ) ከፓወር ሼል እስክሪፕት?
#Requires -Version 3.0
ከፓወር ሼል ለእስክሪፕት እንዴት አድርጌ የአስተዳደር ፍቃድ መጠየቅ እችላለሁ?
1 2 3 4 5 |
# Solution 1 #Requires -RunAsAdministrator # Solution 2 [bool]((whoami.exe /all) -match 'S-1-16-12288') |
ከፓወር ሼል የስክሪፕት ፓራሜትሮች ትክክል መሆኑን እንዴት አረጋግጣለሁ?
help -Name .\Get-ExchangeEnvironmentReport.ps1 -Full
ከፓወር ሼል አሁን ስላለው ተጠቃሚ መረጃ ማግኘት እንዴት እችላለሁ?
[Security.Principal.WindowsIdentity]::GetCurrent()
ከፓወር ሼል እንዴት ገፅታን መፍጠር ማስተካከል እና ድጋሚ መሙላት እችላለሁ?
1 2 3 4 5 6 7 8 9 |
# Create New-Item -Type file -Force $profile # Edit notepad.exe $profile # Reload (without restarting Powershell) & $profile .$profile |
ከፓወር ሼል እስክሪፕት 5ሴኮንድ በ ደቂቃ እንዴት ማቆም እችላለሁ?
Start-Sleep -Seconds 5
Start-Sleep -Seconds 300 # 5 minutes
ከፓወር ሼል መጨረሻ የተነሳበትን ሰዐት እንዴት ማወቅ እችላለሁ ?
(Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime
ከፓወር ሼል የታይፕ ማፍጠኛ እንዴት ማግኘት እችላለሁ?
1 |
[PSObject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get.GetEnumerator() | Select-Object -Property @{Name='Key'; Expression={$_.Key}},@{name='Value'; Expression={$_.Value}} | Sort-Object -Property Key | Format-Table -AutoSize |
ከፓወር ሼል የመጀመሪያ ፕሮግራሞችን እንዴት መዘርዘር እችላለሁ?
1 |
Get-WmiObject -Class Win32_StartupCommand | Sort-Object -Property Caption | Format-Table -Property Caption, Command, User -AutoSize |
ከፓወር ሼል አፕሊኬሽኖችን እንዴት ማስወገድ እችላለሁ?
1 2 |
$application = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name LIKE 'HP Recovery Manager'" $application.Uninstall() |
ከፓወር ሼል እየታየ ያለውን መስኮት ምስል እንዴት ማንሳት እችላለሁ?
Take-ScreenShot -Screen -File 'C:\scripts\screenshot.png' -Imagetype JPEG
Repository : Take-ScreenShot
ከፓወር ሼል ለMSMQ ወረፋ የመልዕክት ብዛት እንዴት ማግኘት እችላለሁ?
1 |
Get-WmiObject -Class Win32_PerfRawData_MSMQ_MSMQQueue -ComputerName $computer | Format-Table -Property Name, MessagesInQueue -AutoSize |
ከፓወር ሼል እንዴት በስራ ላይ የማዋል ፖሊሲ ማስቀመጥ እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 |
# Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode. Set-ExecutionPolicy -ExecutionPolicy Restricted # AllSigned - Only scripts signed by a trusted publisher can be run. Set-ExecutionPolicy -ExecutionPolicy AllSigned # RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # Unrestricted - No restrictions - All Windows PowerShell scripts can be run. Set-ExecutionPolicy -ExecutionPolicy Unrestricted |
1 2 3 4 |
$shell = New-Object -ComObject WScript.Shell $shortcut = $shell.Createshortcut("$HOME\Desktop\Procexp.lnk") $shortcut.TargetPath = 'C:\SysinternalsSuite\procexp.exe' $shortcut.Save() |
ከፓወር ሼል ታስክ ባር ላይ ፕሮግራሞችን እንዴት ፒን ማረግ ወይም አለማረግ እችላለሁ?
1 2 3 4 |
$shell = New-Object -ComObject shell.application $program = $shell.Namespace($env:windir).Parsename('notepad.exe') $program.Invokeverb('TaskbarPin') $program.Invokeverb('TaskbarUnpin') |
ከፓወር ሼል እንዴት የዊንዶውን መክፈቻ መክፈት እችላለሁ?
[Diagnostics.Process]::Start('explorer.exe')
Invoke-Item -Path C:\Windows\explorer.exe
ከፓወር ሼል የመሳሪያዎችን ድራይቨር እንዴት መዘርዘር እችላለሁ?
Get-WmiObject -Class Win32_PnPSignedDriver
Get-WindowsDriver -Online -All
driverquery.exe
1 2 3 4 5 6 7 8 9 10 11 |
# Empty GUID $guid = [GUID]::Empty # New GUID (lower case by default) $guid = [GUID]::NewGuid() # New GUID (upper case) $guid = ([GUID]::NewGuid()).ToString().ToUpper() # New GUID with a specific value $guid = [GUID]('bc4ad3d3-d704-4bd0-843f-d607fbbc4cd7') |
ከፓወር ሼል አሁን ላለው ተጠቃሚ ጊዜያዊ የስም ማውጫ አድራሻ እንዴት ማግኘት እችላለሁ?
[System.IO.Path]::GetTempPath()
ከፓወር ሼል ዋናውን መገኛና የሱን ተከታይ መገኛ እንዴት ወደ አንድ መገኛ ማገናኘት እችላለሁ?
Join-Path -Path C:\ -ChildPath \windows
ከፓወር ሼል እንዴት ሁሉንም cmdlets “Get-*” መዘርዘር እችላለሁ?
Get-Command -Verb Get
ከፓወር ሼል የሲስተሙን ልዩ ፎልደሮች እንዴት መዘርዘር እችላለሁ?
1 |
[System.Enum]::GetNames([System.Environment+SpecialFolder]) | ForEach-Object -Process { $_ + " [System.Environment]::GetFolderPath($_)" } |
ከፓወር ሼል የISO/VHD ፋይሎችን እንዴት ማውጣት እችላለሁ?
Mount-DiskImage 'D:\ISO\file.iso' # ISO
Mount-DiskImage 'D:\VHD\file.vhd' # VHD
ከፓወር ሼል የ.NET ፍሬምወርክ እትሞችን እንዴት ማረጋገጥ እችላለሁ?
1 |
Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version -EA 0 | Where-Object -FilterScript { $_.PSChildName -match '^(?!S)\p{L}' } | Select-Object -Property PSChildName, Version |
ከፓወር ሼል የ.NET ፍሬምወርክ እትም 4.5 እንዴት እንዳለ ማወቅ እችላለሁ?
(Get-ItemProperty -Path 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full' -EA 0).Version -like '4.5*'
ከፓወር ሼል ትራንስክሪፕት እንዴት ማስጀመርና ማቆም እችላለሁ()?
Start-Transcript -Path 'C:\scripts\transcript.txt
Stop-Transcript
ከፓወር ሼል ይህንን የስም ማውጫ ወደ ሌላ ስፍራ መለወጥ እንዴት እችላለሁ?
Set-Location -Path 'C:\scripts'
ከፓወር ሼል ስክሪኑን ማፅዳት እንዴት እችላለሁ?
Clear-Host
cls # Alias
ከፓወር ሼል የዲስፕሌይ ሪሶልሽኑን እንዴት መቀየር እችላለሁ?
Set-DisplayResolution -Width 1280 -Height 1024 -Force # Windows 2012
ከፓወር ሼል ሙሉ መስኮት እንዴት ማየት እችላለሁ?
mode.com 300
ከፓወር ሼል የምስልን (ወርድ እና ቁመት) እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 |
$picture = New-Object -ComObject Wia.ImageFile $picture.LoadFile('C:\screenshot.jpg') [PSCustomObject] @{ Width = $picture.Width Height = $picture.Height } |
ከፓወር ሼል የዊንዶውን የምርት መክፈቻ ቁልፍ እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
function Get-WindowsKey { ## function to retrieve the Windows Product Key from any PC ## by Jakob Bindslet (jakob@bindslet.dk) param ($targets = '.') $hklm = 2147483650 $regPath = 'Software\Microsoft\Windows NT\CurrentVersion' $regValue = 'DigitalProductId' Foreach ($target in $targets) { $productKey = $null $win32os = $null $wmi = [WMIClass]"\\$target\root\default:stdRegProv" $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue) $binArray = ($data.uValue)[52..66] $charsArray = 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9' ## decrypt base24 encoded binary data For ($i = 24; $i -ge 0; $i--) { $k = 0 For ($j = 14; $j -ge 0; $j--) { $k = $k * 256 -bxor $binArray[$j] $binArray[$j] = [math]::truncate($k / 24) $k = $k % 24 } $productKey = $charsArray[$k] + $productKey If (($i % 5 -eq 0) -and ($i -ne 0)) { $productKey = '-' + $productKey } } $win32os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $target $obj = New-Object -TypeName Object $obj | Add-Member -MemberType Noteproperty -Name Computer -Value $target $obj | Add-Member -MemberType Noteproperty -Name Caption -Value $win32os.Caption $obj | Add-Member -MemberType Noteproperty -Name CSDVersion -Value $win32os.CSDVersion $obj | Add-Member -MemberType Noteproperty -Name OSArch -Value $win32os.OSArchitecture $obj | Add-Member -MemberType Noteproperty -Name BuildNumber -Value $win32os.BuildNumber $obj | Add-Member -MemberType Noteproperty -Name RegisteredTo -Value $win32os.RegisteredUser $obj | Add-Member -MemberType Noteproperty -Name ProductID -Value $win32os.SerialNumber $obj | Add-Member -MemberType Noteproperty -Name ProductKey -Value $productKey $obj } } |
Perfmon
ከፓወር ሼል ያሁኑን “%የፕሮሰስ ጊዜ” (በአማካይ) ላልፉት 5 ሴኮንዶች (ለ10 ጊዜ) እንዴት ማግኘት እችላለሁ?
(Get-Counter '\Processor(_total)\% Processor Time' -SampleInterval 5 -MaxSamples 10).CounterSamples.CookedValue
Assemblies
ከፓወር ሼል አሴምብሊስ እንዴት መጫን እችላለሁ?
1 2 3 4 5 6 |
Add-Type -AssemblyName 'System.Windows.Forms' Add-Type -Path 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll' # Deprecated [System.Reflection.Assembly]::LoadFrom('C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll') |
ከፓወር ሼል ያሁኑ .NETአሴምብሊ እንደተጫነ እንዴት ማረጋገጥ እችላለሁ?
1 2 3 4 5 |
# Check All [System.AppDomain]::CurrentDomain.GetAssemblies() # Check specific one [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object -FilterScript { $_.FullName -like '*forms*' } |
ከፓወር ሼል የGAC(ግሎባል አሴምብሊ ካሽ) መገኛ እንዴት መፈለግ እችላለሁ?
1 |
(New-Object -TypeName Regex -ArgumentList '(?<=file:///)(.*)(?=\/GAC)', 'IgnoreCase').Match(([PSObject].Assembly.Evidence | Where-Object -FilterScript { $_.Value -ne $null }).Value).Value -replace '/', '\' |
Clipboard
ከፓወር ሼል ውጤቶችን ወደ ክሊፕ ቦርድ እንዴት መቅዳት እችላለሁ?
1 |
Get-Process | clip.exe |
ከፓወር ሼል የክሊፕ ቦርዱን ይዘት እንዴት ማግኘት እችላለሁ?
Add-Type -AssemblyName PresentationCore
[Windows.Clipboard]::GetText()
Hotfixes
ከፓወር ሼል የተጫኑ ሆትፊክሶችን እንዴት ማግኘት እችላለሁ?
Get-HotFix -ComputerName $computer
ከፓወር ሼል የተጫኑ ሆትፊክሶችን እንዴት ከተወሰነ ቀን በፊት/በኋላ ማግኘት እችላለሁ?
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
ከፓወር ሼል ሆትፊክስ እንደተጫነ እንዴት ማረጋገጥ እችላለሁ?
Get-HotFix -Id KB2965142
ከፓወር ሼል በሌላ ኮምፒውተር የተጫን ሆትፊክስ እንዴት ማግኘት እችላለሁ?
Get-HotFix -ComputerName $computer
Pagefile
ከፓወር ሼል የፔጅ ፋይል መረጃ እንዴት ማግኘት እችላለሁ?
Get-WmiObject -Class Win32_PageFileusage | Select-Object -Property Name, CurrentUsage, AllocatedBaseSize, PeakUsage, InstallDate
ከፓወር ሼል የሚመከረውን የፔጅ ፋይል መጠን በ(ሜ.ባ)እንዴት ማግኘት እችላለሁ?
[Math]::Truncate(((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory) / 1MB) * 1.5
ከፓወር ሼል (4096ሜ.ባ) የፔጅ ፋይል (D:) ድራይቭ ውስጥ እንዴት መፍጠር እችላለሁ?
1 2 3 4 5 |
Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{ Name = 'D:\pagefile.sys' InitialSize = 4096 MaximumSize = 4096 } |
ከፓወር ሼል (C:) ውስጥ ያለን የፔጅ ፋይል እንዴት ማጥፋት እችላለሁ?
1 2 3 4 5 |
$privileges = Get-WmiObject -Class Win32_computersystem -EnableAllPrivileges $privileges.AutomaticManagedPagefile = $false $privileges.Put() $pagefile = Get-WmiObject -Query "select * from Win32_PageFileSetting where name='c:\\pagefile.sys'" $pagefile.Delete() # Reboot required |
Maintenance
በፓወር የድራይቭን ፍራግመንቴሽን እንዴት ማረጋገጥ እችላለሁ?
1 |
$drive = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = 'c:'" $defragReport = $drive.DefragAnalysis() $defragReport.DefragAnalysis |
ከፓወር ሼል የሁሉንም ድራይቭ ይዘት እንዴት ማረጋገጥ እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Get-WmiObject -Class Win32_logicaldisk | Format-Table -Property @{ Name = 'Drive' Expression = {$_.DeviceID} }, @{ Name = 'Total size (GB)' Expression = {[decimal]('{0:N0}' -f($_.Size/1gb))} }, @{ Name = 'Free space(GB)' Expression = {[decimal]('{0:N0}'-f($_.Freespace/1gb))} }, @{ Name = 'Free (%)' Expression = {'{0,6:P0}' -f(($_.Freespace/1gb) / ($_.size/1gb))} } -AutoSize |
Files
ከፓወር ሼል እንዴት ፋይል መክፈት እችላለሁ?
Invoke-Item -Path 'C:\scripts\file.txt'
.'C:\scripts\file.txt'
ከፓወር ሼል እንዴት ፋይል ማንበብ እችላለሁ?
Get-Content -Path 'C:\scripts\file.txt'
gc "C:\scripts\file.txt" # Alias
ከፓወር ሼል እንዴት ፋይል ላይ መጻፍ እችላለሁ?
'Line1', 'Line2', 'Line3' | Out-File -FilePath 'C:\scripts\file.txt'
'Line1', 'Line2', 'Line3' | Add-Content -Path file.txt
ከፓወር ሼል ያሁኑን ስክሪፕት ፋይል ሙሉ ስም እንዴት ማግኘት እችላለሁ?
$MyInvocation.MyCommand.Path
ከፓወር ሼል እንዴት ፋይሎችን መጭመቅ እችላለሁ?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory($folder,$fileZIP)
ከፓወር ሼል እንዴት የተጨመቁ ፋይሎችን መፍታት እችላለሁ?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::ExtractToDirectory($fileZIP, $folder)
ከፓወር ሼል ZIP የሆኑ ፋይሎችን እንዴት ማየት እችላለሁ?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::OpenRead($fileZIP)
ከፓወር ሼል የፋይል መጠንን በኪ.ባ እንዴት ማሳየት እችላለሁ?
(Get-ChildItem -Path .\winsrv.dll).Length /1KB
(Get-ChildItem -Path .\winsrv.dll).Length /1MB
(Get-ChildItem -Path .\winsrv.dll).Length /1GB
ከፓወር ሼል የፋይል ይዘት መጠናቸው ከ1 ጊ.ባ የሚያንሱትን እንዴት መፈለግ እችላለሁ?
1 2 3 4 5 |
# Larger than 1 GB Get-ChildItem -Path C:\ -Recurse -ErrorVariable $errorsSearch | Where-Object -FilterScript {$_.Length -gt 1GB} # Less than 1 GB Get-ChildItem -Path C:\ -Recurse -ErrorVariable $errorsSearch | Where-Object -FilterScript {$_.Length -lt 1GB} |
ከፓወር ሼል የፋይል ስማቸውን ያለቅጥያቸው እንዴት ማሳየት እችላለሁ?
[System.IO.Path]::GetFileNameWithoutExtension('C:\Windows\system32\calc.exe') # Return calc
ከፓወር ሼል የፋይል ስማቸው ከነቅጥያቸው እንዴት ማሳየት እችላለሁ?
[System.IO.Path]::GetExtension('C:\scripts\file.txt') # Return .txt
ከፓወር ሼል የፋይልን የፋይል እትም እንዴት ማግኘት እችላለሁ?
1 2 |
(Get-Item -Path C:\Windows\System32\calc.exe).VersionInfo.FileVersion [System.Diagnostics.FileVersionInfo]::GetVersionInfo('C:\Windows\system32\calc.exe').FileVersion |
ከፓወር ሼል የፋይልን ሃሽ እንዴት ማግኘት እችላለሁ?
(Get-FileHash $file).Hash
ከፓወር ሼል የፋይልን MD5/SHA1 ቅንብር እንዴት እችላለሁ?
Get-FileHash $file -Algorithm MD5
Get-FileHash $file -Algorithm SHA1
ከፓወር ሼል የተሰወሩ ፋይሎችን እንዴት ማሳየት እችላለሁ?
1 2 3 4 5 |
# Display only hidden files Get-ChildItem -Hidden -File # Display all files (including hidden files) Get-ChildItem -Force -File |
ከፓወር ሼል አንድ ፋይል ቅጥያ እንዳለው እንዴት ማረጋገጥ እችላለሁ?
1 |
[System.IO.Path]::HasExtension('C:\hiberfil.sys') |
ከፓወር ሼል ፋይል “Read Only” እንዴት ማድረግ እችላለሁ?
Set-ItemProperty -Path .\file.txt -Name IsReadOnly -Value $true
ከፓወር ሼል ለፋይል የ”LastWriteTime”ን ወደ ያለፈው ሳምንት እንዴት መለወጥ እችላለሁ?
Set-ItemProperty -Path .\file.txt -Name LastWriteTime -Value ((Get-Date).AddDays(-7))
If not working, use Nirsoft tool: BulkFileChanger.
ከፓወር ሼል እንዴት አዲስ ፋይል መፍጠር እችላለሁ?
New-Item -ItemType File -Path 'C:\scripts\file.txt' -Value 'FirstLine'
ከፓወር ሼል እንዴት የፋይልን ስም መቀየር እችላለሁ?
Rename-Item -Path 'C:\scripts\file.txt' -NewName 'C:\scripts\powershellguru2.txt'
ከፓወር ሼል የብዙ ፋይሎችን ስም እንዴት አንድላይ መቀየር እችላለሁ?
Get-ChildItem -Path C:\scripts\txt | Rename-Item -NewName { $_.Name -replace ' ', '_' }
ከፓወር ሼል ፋይል እንዴት ማጥፋት እችላለሁ?
Remove-Item -Path 'C:\scripts\file.txt'
ከፓወር ሼል የቅርብ 10 መስመሮችን ከፋይል እንዴት ማሳየት እችላለሁ?
Get-Content -Path 'C:\scripts\log.txt' -Tail 10
ከፓወር ሼል በዛ ያሉ ፋይሎችን እንዴት ብሎክ አለማረግ እችላለሁ?
Get-ChildItem -Path 'C:\scripts\Modules' | Unblock-File
ከፓወር ሼል ባዶ መስመሮችን ከፋይል እንዴት ማጥፋት እችላለሁ?
(Get-Content -Path file.txt) | Where-Object -FilterScript {$_.Trim() -ne '' } | Set-Content -Path file.txt
ከፓወር ሼል አንድ ፋይል እንዳለ እንዴት ማረጋገጥ እችላለሁ?
1 |
Test-Path -Path 'C:\Windows\notepad.exe' # Return True |
ከፓወር ሼል ከተፈጠረ ቅርብ/የቆየ ፋይል እንዴት ማግኘት እችላለሁ?
1 2 |
Get-ChildItem | Sort-Object -Property CreationTime | Select-Object -Last 1 # Newest Get-ChildItem | Sort-Object -Property CreationTime | Select-Object -First 1 # Oldest |
ከፓወር ሼል የተደጋገሙ መስመሮችን ከፋይል እንዴት ማጥፋት እችላለሁ?
1 2 |
Get-Content -Path .\file.txt | Select-Object -Unique # Display Get-Content -Path .\file.txt | Select-Object -Unique | Set-Content -Path .\testing.txt # Save |
ከፓወር ሼል ከተፈጠሩ 1ወር ወይም ከዛ በላይ የሆናችውን ፋይሎች እንዴት ማግኘት እችላለሁ?
1 2 3 |
$1MonthAgo = (Get-Date).AddMonths(-1) Get-ChildItem | ?{$_.LastWriteTime -lt $1MonthAgo} | Select-Object LastWriteTime,Name,DirectoryName # More Get-ChildItem | ?{$_.LastWriteTime -gt $1MonthAgo} | Select-Object LastWriteTime,Name,DirectoryName # Less |
ከፓወር ሼል ከተፈጠሩ 1ዓመት ወይም ከዛ በላይ የሆናችውን ፋይሎች እንዴት ማግኘት እችላለሁ?
1 2 3 |
$1YearAgo = (Get-Date).AddYears(-1) Get-ChildItem | ?{$_.LastWriteTime -lt $1YearAgo} | Select-Object LastWriteTime,Name,DirectoryName # More Get-ChildItem | ?{$_.LastWriteTime -gt $1YearAgo} | Select-Object LastWriteTime,Name,DirectoryName # Less |
ከፓወር ሼል የቫርያብል ዋጋን እንዴት ወደ ፋይል ማውጣት እችላለሁ?
Set-Content -Path file.txt -Value $variable
ከፓወር ሼል በፎልደር ውስጥ ያሉ የ(*.txt) ፋይሎችን እንዴት ቁጥራቸውን ማወቅ እችላለሁ?
1 2 3 |
[System.IO.Directory]::GetFiles('C:\scripts', '*.txt').Count (Get-ChildItem -Path 'C:\scripts' -Filter *.txt).Count (Get-ChildItem -Path 'C:\scripts' -Filter *.txt -Recurse).Count # Recursive |
ከፓወር ሼል ብዙ ፋይል ውስጥ ያለን ቃል እንዴት መፈለግ እችላለሁ?
Select-String -Path 'C:\*.txt' -Pattern 'Test'
ከፓወር ሼል የአንድን ፋይል የመጀመሪያ ወይም መጨረሻ እንዴት ማሳየት እችላለሁ?
1 2 3 4 5 6 7 8 9 |
'Line1', 'Line2', 'Line3' | Out-File -FilePath file.txt # First Line Get-Content -Path .\file.txt | Select-Object -First 1 # Returns Line1 (Get-Content -Path .\file.txt)[0] # Returns Line1 # Last Line Get-Content -Path .\file.txt | Select-Object -Last 1 # Returns Line3 (Get-Content -Path .\file.txt)[-1] # Returns Line3 |
ከፓወር ሼል የአንድን ፋይል የተለየ የመስመር ቁጥር እንዴት ማሳየት እችላለሁ?
1 2 3 |
'Line1', 'Line2', 'Line3' | Out-File -FilePath file.txt Get-Content -Path .\file.txt | Select-Object -Index 0 # Returns Line1 Get-Content -Path .\file.txt | Select-Object -Index 2 # Returns Line3 |
ከፓወር ሼል የአንድን ፋይል መስመር እንዴት መቁጠር እችላለሁ?
1 2 |
'Line1', 'Line2', 'Line3' | Out-File -FilePath file.txt (Get-Content -Path .\file.txt | Measure-Object -Line).Lines # Returns 3 |
ከፓወር ሼል የአንድን ፋይልን የቃልና የፊደል ብዛት እንዴት መቁጠር እችላለሁ?
1 2 3 4 5 6 7 8 9 10 |
'Test', 'Powershell', 'Test Powershell' | Out-File -FilePath file.txt # Words (Return 4) (Get-Content -Path .\file.txt | Measure-Object -Word).Words # Characters (Return 23) (Get-Content -Path .\file.txt | Measure-Object -Character).Characters # Characters and ignore whitespaces (Return 22) (Get-Content -Path .\file.txt | Measure-Object -Character -IgnoreWhiteSpace).Characters |
ከፓወር ሼል እንዴት ፋይል ማውረድ እችላለሁ?
Invoke-WebRequest -Uri 'http://www.nirsoft.net/utils/searchmyfiles.zip' -OutFile 'C:\tools\searchmyfiles.zip'
ከፓወር ሼል የአንድን ፋይል መገኛ ሙሉ መንገድ እንዴት ማሳየት እችላለሁ?
Resolve-Path -Path .\script.ps1 # Return C:\Scripts\script.ps1
Copy
ከፓወር ሼል አንድን ፋይል ወደ ፎልደር እንዴት ኮፒ ማድረግ እችላለሁ?
Copy-Item -Path 'C:\source\file.txt' -Destination 'C:\destination'
ከፓወር ሼል አንድን ፋይል ወደ ብዙ ፎልደሮች እንዴት ኮፒ ማድረግ እችላለሁ?
1 2 |
$destination = 'C:\destination\Folder1', 'C:\destination\Folder2' $destination | Copy-Item -Path 'C:\source\file.txt' -Recurse -Destination {$_} |
ከፓወር ብዙ ፋይሎችን ወደ አንድ ፎልደር እንዴት ኮፒ ማድረግ እችላለሁ?
Get-ChildItem -Path 'C:\source' -Filter *.txt | Copy-Item -Destination 'C:\destination'
Active Directory
Domain & Forest
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለ ግሎባል ካታሎግ አገልጋይን እንዴት ማግኘት እችላለሁ?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለ ሳይት እንዴት ማግኘት እችላለሁ?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
ከፓወር ሼል ይህንን ዶሜን መቆጣጠሪያ እንዴት ማግኘት እችላለሁ?
(Get-ADDomainController).HostName
ከፓወር ሼል ሁሉንም በዶሜን መቆጣጠሪያ ያለ ዶሜንን እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 |
# Solution 1 Get-ADDomainController -Filter * | ForEach-Object -Process {$_.Name} # Solution 2 Get-ADGroupMember 'Domain Controllers' | ForEach-Object -Process {$_.Name} # Solution 3 Get-ADComputer -LDAPFilter '(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))' | ForEach-Object -Process {$_.Name} # Solution 4 [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | ForEach-Object -Process {$_.DomainControllers} | ForEach-Object -Process {$_.Name} |
ከፓወር ሼል የAD ማባዣ ችግሮችን እንዴት ማግኘት እችላለሁ?
Get-ADReplicationFailure dc02.domain.com # Windows 8 and 2012
ከፓወር ሼል በንቁ አክቲቭ ዳይሬክተሪ ያለን ቶምብስቶን የፎሬስት የቆይታ ጊዜ እንዴት ማግኘት እችላለሁ?
1 |
(Get-ADObject -Identity "cn=Directory Service,cn=Windows NT,cn=Services,$(([adsi]('LDAP://RootDSE')).configurationNamingContext)" -Properties tombstonelifetime).tombstonelifetime |
ከፓወር ሼል የፎሬስት/ዶሜን እንዴት መቀበል እችላለሁ?
1 2 |
Get-ADDomain domain.com Get-ADForest domain.com |
ከፓወር ሼል የ”Deleted Objects” ኮንቴነር መገኛ ከአክቲቭ ዳይሬክቶሪ ውስጥ እንዴት መቀበል እችላለሁ?
(Get-ADDomain).DeletedObjectsContainer
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ያለን የAD የቆሻሻ ማጠራቀሚያ አገልግሎት እንዴት ማስቻል እችላለሁ?
1 |
Enable-ADOptionalFeature -Identity 'CN=Recycle Bin Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=domain,DC=com' -Scope ForestOrConfigurationSet -Target 'domain.com' |
ከፓወር ሼል በቆሻሻ ማጠራቀሚያ ውስጥ ያለን የAD አካውንት እንዴት መመለስ እችላለሁ?
Get-ADObject -Filter 'samaccountname -eq "powershellguru"' -IncludeDeletedObjects | Restore-ADObject
ከፓወር ሼል የFSMO ሚና እንዴት መፈለግ እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Solution 1 Get-ADForest | Format-List -Property SchemaMaster, DomainNamingMaster Get-ADDomain | Format-List -Property PDCEmulator, RIDMaster, InfrastructureMaster # Solution 2 netdom query fsmo # Solution 3 [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().SchemaRoleOwner [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().NamingRoleOwner [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().InfrastructureRoleOwner [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().PdcRoleOwner [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().RidRoleOwner |
ከፓወር ሼል የተወሰነ ዶሜን ተቆጣጣሪ ጋር እንዴት ማገናኘት እችላለሁ?
Get-ADUser -Identity $user -Server 'serverDC01'
ከፓወር ሼል ያሁኑን ግልጋሎት ሰጪ እንዴት ማግኘት እችላለሁ?
1 2 |
($env:LOGONSERVER).Substring(2) ([System.Environment]::GetEnvironmentVariable('logonserver')).Substring(2) |
ከፓወር ሼል በኮምፒውተር የ”gpupdate” እንዴት መፈፀም እችላለሁ?
Invoke-GPUpdate -Computer $computer -Force -RandomDelayInMinutes 0 # Windows 2012
Groups
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ እንዴት አዲስ ግሩፕ መፍጠር እችላለሁ?
1 |
New-ADGroup -Name 'Powershell Guru' -SamAccountName powershellguru -GroupCategory Security -GroupScope Global -DisplayName 'Powershell Guru' -Path 'OU=MyOU,DC=domain,DC=com' -Description 'My account' |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ እንዴት ግሩፕ ማጥፋት እችላለሁ?
Remove-ADGroup -Identity 'PowershellGuru'
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ እንዴት የተጠቃሚ ግሩፕ መጨመር እችላለሁ?
Add-ADGroupMember "Powershell Guru" -Members powershellguru
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን እንዴት የተጠቃሚ ግሩፕ ማጥፋት እችላለሁ?
Remove-ADGroupMember 'Powershell Guru' -Members powershellguru
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያሉ ባዶ ግሩፖችን እንዴት መፈለግ እችላለሁ?
Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያሉ ባዶ ግሩፖችን እንዴት ቁጥራቸውን ማወቅ እችላለሁ?
(Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}).Count
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያሉ ግሩፖችን አባሎቻቸውን እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# Solution 1 Get-ADGroupMember 'Powershell Guru' | ForEach-Object -Process {$_.DistinguishedName} Get-ADGroupMember 'Powershell Guru' | ForEach-Object -Process {$_.Samaccountname} # Solution 2 Get-ADGroup 'Powershell Guru' -Properties Members | Select-Object -Property Members -ExpandProperty Members | Sort-Object # Solution 3 function Get-ADGroupMemberFast { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [string]$GroupName ) $de = New-Object -TypeName System.DirectoryServices.DirectoryEntry $ds = New-Object -TypeName System.DirectoryServices.DirectorySearcher $ds.SearchRoot = $de $ds.Filter = "(cn=$group)" $null = $ds.PropertiesToLoad.Add('member') $result = $ds.FindOne() if($result) { $account = $result.GetDirectoryEntry() $account.Properties['member'] | ForEach-Object -Process {$_} } } Get-ADGroupMemberFast -GroupName 'Powershell Guru' |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያሉ በስራቸው ሌላ አባል ያላቸውን የግሩፕ አባሎች እንዴት ማግኘት እችላለሁ?
1 2 |
Get-ADGroupMember 'Powershell Guru' -Recursive | ForEach-Object -Process {$_.DistinguishedName} Get-ADGroupMember 'Powershell Guru' -Recursive | ForEach-Object -Process {$_.SamAccountName} |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያሉ በስራቸው ሌላ አባል ያላቸው/የሌላቸው የግሩፕ አባሎች እንዴት ቁጥራቸውን ማወቅ እችላለሁ?
1 2 |
(Get-ADGroupMember 'Powershell Guru' | ForEach-Object -Process {$_.Samaccountname}).Count (Get-ADGroupMember 'Powershell Guru' -Recursive | ForEach-Object -Process {$_.Samaccountname}).Count |
Users
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ በ”Get-ADUser” ውስጥ ያለን ዋይልድ ካርድእንዴት መጠቀም እችላለሁ?
1 2 3 4 5 6 7 8 9 |
# Filter (Get-ADUser -SearchBase 'OU=myOU,DC=domain,DC=com' -Filter {name -like '*vip*'} -Properties Name).Name # LDAPFilter (Get-ADUser -SearchBase 'OU=myOU,DC=domain,DC=com' -LDAPFilter '(name=*vip*)' -Properties Name).Name # With a variable $user = '*vip*' (Get-ADUser -SearchBase 'OU=myOU,DC=domain,DC=com' -Filter {name -like $user} -Properties Name).Name |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ አንድን ተጠቃሚ ወደ ሌላ OU እንዴት ማሸጋገር እችላለሁ?
Move-ADObject -Identity $dn -TargetPath 'OU=myOU,DC=domain,DC=com'
ከፓወር ሼል እርስ በርስ የተሳሰሩ ሁሉንም አባላት እንዴት ማግኘት እችላለሁ?
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($dn))"
ከፓወር ሼል ለአንድ ተጠቃሚ(አጭር ስም/የተቆረጠ) ያላቸውን አባላት እንዴት ማግኘት እችላለሁ?
(Get-ADUser $user -Properties MemberOf).MemberOf | ForEach-Object -Process {($_ -split ',')[0].Substring(3)} | Sort-Object
1 2 |
Set-ADUser $samAccountName -DisplayName 'DisplayName' -GivenName 'Test' -Surname 'Powershell' -DisplayName 'Test Powershell' Rename-ADObject $dn -NewName 'Test Powershell' #FullName |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን አንድ የተጠቃሚ አካውንት ገለጻ,ቢሮ,እና ስልክ ቁጥር እንዴት መለወጥ እችላለሁ?
Set-ADUser $samAccountName -Description 'IT Consultant' -Office 'Building B' -OfficePhone '12345'
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን አንድ የተጠቃሚ ጊዜው የሚያብቃበትን ጊዜ “31/12/2015” ወይም “Never” እንዴት ማስቀመጥ እችላለሁ?
1 2 3 4 5 |
# 31/12/2015 Set-ADAccountExpiration $samAccountName -DateTime '01/01/2016' # Never Clear-ADAccountExpiration $samAccountName |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን አንድ አካውንት እንዴት እንዳይቆለፍ ማድረግ እችላለሁ?
Unlock-ADAccount $samAccountName
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን አንድ አካውንት እንዴት ማስራት/ማገድ እችላለሁ?
1 2 |
Disable-ADAccount $samAccountName Enable-ADAccount $samAccountName |
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን አንድ አካውንት እንዴት ማጥፋት እችላለሁ?
Remove-ADUser $samAccountName
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን አንድ አካውንት የይለፍ ቃል እንዴት መደምሰስ እችላለሁ?
1 2 3 4 5 6 7 |
# Solution 1 : ask password $password = Read-Host -Prompt 'New Password' -AsSecureString # Solution 2 : specify password $password = ConvertTo-SecureString -String 'Q>9xYMw<3?' -AsPlainText -Force Get-ADUser -Filter "samaccountname -like 'helpdeskagent*'" | Set-ADAccountPassword -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $true |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን ለብዙ ተጠቃሚ እንዴት የይለፍ ቃል መደምሰስ እችላለሁ?
1 2 3 4 5 6 7 |
# Solution 1 : ask password $password = Read-Host -Prompt 'New Password' -AsSecureString # Solution 2 : specify password $password = ConvertTo-SecureString -String 'Q>9xYMw<3?' -AsPlainText -Force Get-ADUser -Filter "samaccountname -like 'helpdeskagent*'" | Set-ADAccountPassword -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $true |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን የፋይል ባለቤት እንዴት ማግኘት እችላለሁ?
1 2 3 |
$user = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList (Get-Acl -Path 'userFile.txt').Owner $sid = $user.Translate([System.Security.Principal.SecurityIdentifier]).Value Get-ADUser $sid |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ላለ እንዴት OU (ድርጅታዊ ክፍል) ማግኘት እችላለሁ?
[regex]::match("$((Get-ADUser $user -Properties DistinguishedName).DistinguishedName)",'(?=OU=)(.*\n?)').value
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን ከስራ ውጭ የሆነ የተጠቃሚ አካውንት እንዴት ማግኘት እችላለሁ?
1 2 |
Search-ADAccount -AccountDisabled Get-ADUser -Filter {Enabled -ne $true} |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ጊዜ ያለፈበት የተጠቃሚ አካውንት እንዴት ማግኘት እችላለሁ?
Search-ADAccount -AccountExpired
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን የተቆለፈ የተጠቃሚ አካውንት እንዴት ማግኘት እችላለሁ?
Search-ADAccount -LockedOut
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን የተጠቃሚ አካውንት SID እንዴት ማግኘት እችላለሁ?
(Get-ADUser $user -Properties SID).SID.Value
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ የተጠቃሚ ስም ወደ SID እንዴት መቀየር እችላለሁ?
1 2 |
$user = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList ('DOMAIN', 'user') $SID = ($user.Translate([System.Security.Principal.SecurityIdentifier])).Value |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ SIDን ወደ የተጠቃሚ ስም እንዴት መቀየር እንዴት እችላለሁ?
1 2 |
$SID = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ('SID') $user = ($SID.Translate( [System.Security.Principal.NTAccount])).Value |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን የተጠቃሚ አካውንት የተለየ ስም እንዴት መከፋፈል እችላለሁ?
1 2 3 |
$dn = 'CN=Powershell Test,OU=TEST,DC=domain,DC=com' $dn.Split(',')[0] # Returns "CN=Powershell Test" $dn.Split(',')[0].Split('=')[1] # Returns "Powershell Test" |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን የተጠቃሚ አካውንት የተፈጠረበትን ቀን/የተስተካከለበትን እንዴት ማግኘት እችላለሁ?
Get-ADUser -Identity $user -Properties whenChanged, whenCreated | Format-List -Property whenChanged, whenCreated
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ላለ ክላስ “User” ግዴታ የሆነ ወይም ያልሆነ ጠባይ እንዴት ማሳየት እችላለሁ?
1 2 3 |
$schema = [DirectoryServices.ActiveDirectory.ActiveDirectorySchema]::GetCurrentSchema() $schema.FindClass('user').mandatoryproperties | Format-Table $schema.FindClass('user').optionalproperties | Format-Table |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ላለ ተጠቃሚ የLDAP መገኛ እንዴት እችላለሁ?
1 2 3 4 |
$searcher = New-Object -TypeName DirectoryServices.DirectorySearcher -ArgumentList ([ADSI]'') $searcher.Filter = "(&(objectClass=user)(sAMAccountName= $user))" $searcher = $searcher.FindOne() $pathLDAP = $searcher.Path |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ላለ ተጠቃሚ CN (ያጠረ ስም) እንዴት መለወጥ እችላለሁ?
Rename-ADObject $((Get-ADUser $user -Properties DistinguishedName).DistinguishedName) -NewName 'Test Powershell'
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ቀድሞ ያለውን ተጠቃሚ ድርጅታዊ ክፍል(OU) እንዴት ማግኘት እችላለሁ?
1 2 |
$dn = (Get-ADUser $user -Properties DistinguishedName).DistinguishedName $parent = $dn.Split(',',2)[1] |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ባለቤት ተጠቃሚን (አካውንቱን የፈጠረውን) እንዴት ማግኘት እችላለሁ?
1 2 |
$dn = (Get-ADUser $user -Properties DistinguishedName).DistinguishedName $owner = (Get-Acl -Path "AD:$dn").Owner |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ላለ ተጠቃሚ PwdLastSet ባህሪይ እንዴት መቀየር እችላለሁ?
1 2 3 4 5 |
# Solution 1 [DateTime]::FromFileTime((Get-ADUser $user -Properties pwdLastSet).pwdLastSet) # Solution 2 w32tm /ntte 130787549514737594 |
Computers
በፓወር ሼል በቅርብ ያለ ኮምፒውተርና በዶሜን መካከል ያለን ሚስጥራዊ መተላለፊያ እንዴት መሞከር እችላለሁ?
Test-ComputerSecureChannel
በፓወር ሼል በቅርብ ያለ ኮምፒውተርና በዶሜን መካከል ያለን ሚስጥራዊ መተላለፊያ እንዴት መጠገን እችላለሁ?
Test-ComputerSecureChannel -Repair
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን የኮምፒውተር አካውንት እንዴት ከስራ ውጭ ማድረግ እችላለሁ?
Disable-ADAccount $computer
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን ኮምፒውተር ልዩ ኦፕሬቲንግ ሲስተም እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Get-ADComputer -Filter 'OperatingSystem -eq "CentOS"' Get-ADComputer -Filter 'OperatingSystem -eq "GNU/Linux"' Get-ADComputer -Filter 'OperatingSystem -eq "Linux"' Get-ADComputer -Filter 'OperatingSystem -eq "Mac OS X"' Get-ADComputer -Filter 'OperatingSystem -eq "OnTap"' Get-ADComputer -Filter 'OperatingSystem -eq "Red Hat Enterprise Linux Server"' Get-ADComputer -Filter 'OperatingSystem -eq "redhat-linux-gnu"' Get-ADComputer -Filter 'OperatingSystem -eq "Samba"' Get-ADComputer -Filter 'OperatingSystem -eq "Ubuntu"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows NT"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 2000 Professional"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 2000 Server"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows XP Professional"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Server 2003"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Vista™ Business"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Vista™ Enterprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Vista™ Entreprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 7 Enterprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 7 Professional"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 7 Ultimate"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Server 2008 R2 Enterprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Server 2008 R2 Standard"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Server® 2008 Enterprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 8 Enterprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows 8.1 Enterprise"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Server 2012 R2 Standard"' Get-ADComputer -Filter 'OperatingSystem -eq "Windows Server 2012 Standard"' |
Organizational Unit (OU)
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ድርጅታዊ ክፍል(OU) እንዴት መፍጠር እችላለሁ?
New-ADOrganizationalUnit -Name 'TEST' -Path 'DC=domain,DC=com'
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን ድርጅታዊ ክፍል(OU) እንዴት ማግኘት እችላለሁ?
Get-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -Properties *
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለን ድርጅታዊ ክፍል(OU) መግለጫውን እንዴት መቀየር እችላለሁ?
Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -Description 'My description'
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ድርጅታዊ ክፍል(OU) በድንገት እንዳይጠፋ እንዴት ከስራ ውጪ ማድረግ/አለ ማድረግ እችላለሁ?
1 2 3 4 5 |
# Protection ON Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -ProtectedFromAccidentalDeletion $true # Protection OFF Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -ProtectedFromAccidentalDeletion $false |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ሁሉም ድርጅታዊ ክፍል(OU) በድንገት እንዳዲጠፋ እንዴት በስራ ላይ ማዋል እችላለሁ?
1 |
Get-ADOrganizationalUnit -Filter * -Property ProtectedFromAccidentalDeletion | Where-Object -FilterScript { $_.ProtectedFromAccidentalDeletion -eq $false } | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ ያለ እንዳይጠፋ የተጠበቀ ድርጅታዊ ክፍል(OU) በድንገት እንዴት ማጥፋት እችላለሁ?
1 2 |
Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -ProtectedFromAccidentalDeletion $false Remove-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' |
በፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ የተለየ ድርጅታዊ ክፍል(OU) ስም ወደ አጭር ስም እንዴት መለወጥ እችላለሁ?
1 2 |
$parent = $dn.Split(',',2)[1] $parent = (Get-ADOrganizationalUnit $parent -Properties CanonicalName).CanonicalName |
በፓወር ሼል ባዶ ድርጅታዊ ክፍሎችን(OUs) በድንገት እንዳዲጠፋ እንዴት መዘርዘር እችላለሁ?
1 2 3 4 5 |
# Solution 1 Get-ADOrganizationalUnit -Filter * -Property 'msDS-Approx-Immed-Subordinates' | Where-Object -FilterScript {$_.'msDS-Approx-Immed-Subordinates' -eq 0} # Solution 2 ([adsisearcher]'(objectclass=organizationalunit)').FindAll() | Where-Object -FilterScript { (([adsi]$_.Path).PSbase.Children | Measure-Object).Count -eq 0 } |
በፓወር ሼል የግሩፕ ማናጀሩን እንዴት ማግኘት እችላለሁ?
(Get-ADGroup $dn -Properties Managedby).Managedby
Regex (Regular Expression)
ከፓወር ሼል ከመደበኛ አገላለጽ IP አድራሻ v4 (80.80.228.8) እንዴት ማውጣት እችላለሁ?
$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
ከፓወር ሼል ከመደበኛ አገላለጽ የMAC አድራሻ (C0-D9-62-39-61-2D) ከ”-” መለያ ጋር እንዴት ማውጣት እችላለሁ?
$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
ከፓወር ሼል ከመደበኛ አገላለጽ የMAC አድራሻ (C0-D9-62-39-61-2D) ከ”:” መለያ ጋር እንዴት ማውጣት እችላለሁ?
$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
ከፓወር ሼል ከመደበኛ አገላለጽ ቀን(10/02/2015) እንዴት ማውጣት እችላለሁ?
$example = 'The date is 10/02/2015'
$date = [regex]::match($example,'(\d{2}\/\d{2}\/\d{4})').value
ከፓወር ሼል ከመደበኛ አገላለጽ URL(www.powershell-guru.com)ን እንዴት ማውጣት እችላለሁ?
$example = 'The URL is www.powershell-guru.com'
$url = [regex]::match($example,'[a-z]+[:.].*?(?=\s)').value
ከፓወር ሼል ከመደበኛ አገላለጽ ኢሜል(user@domain.com) እንዴት ማውጣት እችላለሁ?
$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
ከፓወር ሼል ከመደበኛ አገላለጽ የቃል ድርድር ምሳሌ እንዴት “guru”ን ማውጣት እችላለሁ?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?=.com)').value
ከፓወር ሼል ከመደበኛ አገላለጽ የቃል ድርድር ምሳሌ እንዴት “guru.com”ን ማውጣት እችላለሁ?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?<=.)').value
ከፓወር ሼል ከመደበኛ አገላለጽ የቃል ድርድር ምሳሌ እንዴት “powershell-guru.com”ን ማውጣት እችላለሁ?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=www.)(.*\n?)').value
ከፓወር ሼል ከመደበኛ አገላለጽ የቃል ድርድር ምሳሌ እንዴት “123”ን ማውጣት እችላለሁ?
$example = 'Powershell123'
[regex]::match($example,'(\d+)').value
ከፓወር ሼል ከመደበኛ አገላለጽ የቃል ድርድር ምሳሌ እንዴት “$”(የዶላር ምልክትን) ማውጣት እችላለሁ?
$example = 'Powershell`$123'
[regex]::match($example,'(\$)').value
ከፓወር ሼል ከመደበኛ አገላለጽ (*.com)ን ወደ ሌላ (*.fr) እንዴት መቀየር እችላለሁ?
$example = 'www.powershell-guru.com'
[regex]::Replace($example, '.com','.fr')
ከፓወር ሼል ከመደበኛ አገላለጽ የቃላት ድርድርን እንዴት መዝለል እችላለሁ?
[regex]::Escape('\\server\share')
Memory
ከፓወር ሼል ከመደበኛ አገላለጽ በውዳቂ ሰብሳቢ እንዴት የሜሞሪ ሰብሳቢ ማግኘት እችላለሁ?
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
ከፓወር ሼል የራም መጠንን እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 |
# Solution 1 Get-CimInstance -ClassName 'cim_physicalmemory' | ForEach-Object -Process {$_.Capacity /1GB} # Solution 2 (Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory /1GB # Solution 3 (systeminfo.exe | Select-String -Pattern 'Total Physical Memory:').ToString().Split(':')[1].Trim() |
Date
ከፓወር ሼል የዛሬዋን ቀን እንዴት ማግኘት እችላለሁ?
Get-Date
[Datetime]::Now
ከፓወር ሼል ቀንን በተለያዩ ፎርማቶች እንዴት ማሳየት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
### DATE ### Get-Date -Format d : 15/04/2015 Get-Date -Format D : 15 April 2015 Get-Date -Format f : 15 April 2015 14:57 Get-Date -Format F : 15 April 2015 14:57:34 Get-Date -Format g : 15/04/2015 14:57 Get-Date -Format G : 15/04/2015 14:57:34 Get-Date -Format yyyyMMdd : 20150415 Get-Date -UFormat '%d%m%Y' : 15042015 Get-Date -UFormat '%m%d%Y' : 04152015 Get-Date -UFormat '%Y%m%d' : 20150415 Get-Date -UFormat '%d%m%Y' : 15-04-2015 Get-Date -UFormat '%m%d%Y' : 04-15-2015 Get-Date -UFormat '%Y%m%d' : 2015-04-15 ### HOUR ### Get-Date -Format t : 15:31 Get-Date -Format T : 15:31:44 Get-Date -Format HH : 15 (Hour) Get-Date -Format mm : 57 (Minute) Get-Date -Format ss : 34 (Seconds) Get-Date -DisplayHint Time : 15:31:44 ### DAY ### Get-Date -Format dddd : Wednesday Get-Date -Format ddd : Wed Get-Date -Format dd : 15 ### MONTH ### Get-Date -Format MMMM : April Get-Date -Format MMM : Apr Get-Date -Format MM : 04 ### YEAR ### Get-Date -Format yyyy : 2015 |
ከፓወር ሼል ቀን(ቀንጊዜ) ወደ ቀን(የቃላት ድርድር) እንዴት መቀየር እችላለሁ?
$datetimeToString = '{0:dd/MM/yy}' -f (Get-Date 30/01/2015)
$datetimeToString = (Get-Date 31/01/2015).ToShortDateString()
ከፓወር ሼል ቀን(የቃላት ድርድር) ወደ ቀን(ቀንሰዓት) እንዴት መቀየር እችላለሁ?
$stringToDatetime = [Datetime]::ParseExact('30/01/2015', 'dd/MM/yyyy', $null)
ከፓወር ሼል በሁለት ቀናት መካከል ያለን (የቀን ብዛት,ሰዓት,ደቂቃ,ሰከንድ) እንዴት ማስላት እችላለሁ?
(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
ከፓወር ሼል ሁለት ቀናትን እንዴት ማነጻጸር እችላለሁ?
(Get-Date 2015-01-01) -lt (Get-Date 2015-01-30) # True
(Get-Date 2015-01-01) -gt (Get-Date 2015-01-30) # False
ከፓወር ሼል የቀናት ድርድርን እንደ”ቀንጊዜ” እንዴት መልቀም እችላለሁ?
$arrayDate | Sort-Object -Property {$_ -as [Datetime]}
ከፓወር ሼል የማስቆሚያ ሰዓት እንዴት ማስጀመርና ማስቆም እችላለሁ?
$chrono = [Diagnostics.Stopwatch]::StartNew()
$chrono.Stop()
$chrono
ከፓወር ሼል ከሳምንቱ እንዴት የዛሬዋን ቀን እንዴት ማግኘት እችላለሁ?
(Get-Date).DayOfWeek #Sunday
ከፓወር ሼል የትናንትናዋን ቀን እንዴት ማግኘት እችላለሁ?
(Get-Date).AddDays(-1)
ከፓወር ሼል በ(የካቲት 2015) የነበረውን የቀን ብዛት እንዴት ማግኘት እችላለሁ?
[DateTime]::DaysInMonth(2015, 2)
ከፓወር ሼል ሊፕ አመትን እንዴት ማወቅ እችላለሁ?
[DateTime]::IsLeapYear(2015)
ከፓወር ሼል የጊዜ ዞናትን እንዴት መዘርዘር እችላለሁ?
[System.TimeZoneInfo]::GetSystemTimeZones()
Networking
ከፓወር ሼል ወደ(ASCII ፎርማት)መመስጠር እና URLን ማጋለጥ እንዴት እችላለሁ?
1 2 3 4 5 6 7 8 9 |
# Encode $url = 'http://www.powershell-guru.com' $encoded = [System.Web.HttpUtility]::UrlEncode($url) # Decode $decoded = [System.Web.HttpUtility]::UrlDecode($encoded) # Encoded : http%3a%2f%2fwww.powershell-guru.com # Decoded : http://www.powershell-guru.com |
ከፓወር ሼል የተለመዱ ኔትወርክ ትዛዛት እኩያ እነማን ናቸው?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# ipconfig Get-NetIPConfiguration Get-NetIPAddress # ping Test-NetConnection # tracert Test-NetConnection -TraceRoute # route Get-NetRoute # nslookup Resolve-DnsName # Windows 8.1 & Windows 2012 ([System.Net.Dns]::GetHostEntry($IP)).Hostname # IP > PC ([System.Net.Dns]::GetHostAddresses($computer)).IPAddressToString # PC > IP |
ከፓወር ሼል እንዴት IP አድራሻ ማወቅ እችላለሁ?
Get-NetIPAddress # Windows 8.1 & Windows 2012
Get-NetIPConfiguration # Windows 8.1 & Windows 2012
ከፓወር ሼል የIP አድራሻ v6 (IPv6) እንዴት ከስራ ውጭ ማድረግ እችላለሁ?
1 |
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters' -Name 'DisabledComponents' -Value '0xFFFFFFFF' -PropertyType"DWORD" # Reboot required |
ከፓወር ሼል የIP አድራሻ v4 (IPv4) እንዴት ተቀባይነት እንዲኖረው ማድረግ እችላለሁ?
if([ipaddress]'10.0.0.1'){'validated'}
ከፓወር ሼል የውጭ IP አድራሻ እንዴት መፈለግ እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Solution 1 (Invoke-WebRequest -Uri 'myexternalip.com/raw').Content (iwr -Uri 'myexternalip.com/raw').Content # Alias # Solution 2 $webClient = New-Object -TypeName System.Net.WebClient $webClient.DownloadString('http://myexternalip.com/raw') # Solution 3 while ($true) { Write-Output -InputObject "$(Get-Date) - $((Invoke-WebRequest -Uri 'http://myexternalip.com/raw' -Method Get).Content)" Start-Sleep -Seconds 300 } |
ከፓወር ሼል የሆስት ስም ከIP አድራሻ እንዴት መፈለግ እችላለሁ?
([System.Net.Dns]::GetHostEntry($IP)).Hostname
ከፓወር ሼል ከIP አድራሻ የሆስት ስም እንዴት መፈለግ እችላለሁ?
([System.Net.Dns]::GetHostAddresses($computer)).IPAddressToString
ከፓወር ሼል FQDN ከሆስት ስም እንዴት መፈለግ እችላለሁ?
[System.Net.Dns]::GetHostByName($computer).HostName
ከፓወር ሼል የኔትወርክ ማስተካከያ(Ip, ንኡስኔት , መግቢያ, and DNS) እንዴት መፈለግ እችላለሁ?
1 |
Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Format-Table -Property Description, IpAddress, IPSubnet, DefaultIPGateway, DNSServerSearchOrder |
ከፓወር ሼል የMAC አድራሻ እንዴት መፈለግ እችላለሁ?
Get-CimInstance win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress
Get-WmiObject -Class win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress
ከፓወር ሼል ኮምፒውተርን ፒንግ ማድረግ እንዴት እችላለሁ?
1 2 3 4 5 6 |
# Solution 1 Test-Connection -ComputerName $computer -Quiet # Returns True / False # Solution 2 $ping = New-Object -TypeName System.Net.Networkinformation.Ping $ping.Send($computer) |
ከፓወር ሼል አንድ ኮምፒውተር ከኢንተርኔት ጋር እንደተገናኘ እንዴት ማወቅ እችላለሁ?
1 |
[Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet |
ከፓወር ሼል “whois” ማሳያ ለድህረገጽ እንዴት መፈጸም እችላለሁ?
$whois = New-WebServiceProxy 'http://www.webservicex.net/whois.asmx?WSDL'
$whois.GetWhoIs('powershell-guru.com')
ከፓወር ሼል የፐብሊክ IP እንዴት ዝርዝር መረጃ ማግኘት እችላለሁ?
1 2 |
$externalIP = (Invoke-WebRequest -Uri 'myexternalip.com/raw').Content $detailsIP = ([xml](Invoke-WebRequest -Uri "http://freegeoip.net/xml/$externalIP" -UseBasicParsing).Content).Response |
ከፓወር ሼል ፖርት እንደተከፈተ/እንደተዘጋ እንዴት ማረጋገጥ እችላለሁ?
New-Object -TypeName Net.Sockets.TcpClient -ArgumentList $computer, 135
ከፓወር ሼል “tracert” እንዴት መፈጸም እችላለሁ?
Test-NetConnection www.google.com -TraceRoute
ከፓወር ሼል የኔትወርክ ግንኙነት ፕሮፋይል እንዴት ማስተካከል እችላለሁ?
Get-NetAdapter | Format-Table -Property Name, InterfaceDescription, ifIndex -AutoSize # Windows 8.1
Set-NetConnectionProfile -InterfaceIndex 6 -NetworkCategory Private
ከፓወር ሼል የTCP ፖርት እንዴት ማሳየት እችላለሁ?
netstat.exe -ano
Get-NetTCPConnection #Windows 8 and 2012
ከፓወር ሼል ረጅም URLን ወደ አጭር URL እንዴት ማሳጠር እችላለሁ?
$url = 'www.powershell-guru.com'
$tiny = Invoke-RestMethod -Uri "http://tinyurl.com/api-create.php?url=$url"
ከፓወር ሼል የፕሮክዚ መቼቶችን እንዴት ማግኘት እችላለሁ?
Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
DNS
ከፓወር ሼል በሎካል ኮምፒውተር ላይ ያሉ የDNS ቅሪቶችን እንዴት ማረጋገጥ እችላለሁ?
ipconfig.exe /displaydns
Get-DnsClientCache #Windows 8 and 2012
ከፓወር ሼል በሎካል ኮምፒውተር ላይ ያሉ የDNS ቅሪቶችን እንዴት ማጽዳት እችላለሁ?
ipconfig.exe /flushdns
Start-Process -FilePath ipconfig -ArgumentList /flushdns -WindowStyle Hidden
Clear-DnsClientCache #Windows 8 and 2012
ከፓወር ሼል በሪሞት ኮምፒውተር ላይ ያሉ የDNS ቅሪቶችን እንዴት ማጽዳት እችላለሁ?
Invoke-Command -ScriptBlock {Clear-DnsClientCache} -ComputerName computer01, computer02
ከፓወር ሼል የሆስትን ፋይል እንዴት ማንበብ እችላለሁ?
Get-Content -Path 'C:\Windows\system32\drivers\etc\hosts'
Password
ከፓወር ሼል ያልታሰበ የይለፍ ቃል እንዴት መፍጠር እችላለሁ?
[Reflection.Assembly]::LoadWithPartialName('System.Web')
[System.Web.Security.Membership]::GeneratePassword(30,2)
ከፓወር ሼል የአስተዳደሩን የይለፍ ቃል በሌላ ቦታ ባለ አገልግሎት ሰጪ እንዴት መቀየር እችላለሁ?
$admin = [ADSI]('WinNT://server01/administrator,user')
$admin.SetPassword($password)
$admin.SetInfo()
ከፓወር ሼል በአክቲቭ ዳይሬክተሪ ውስጥ የይለፍ ቃሉ ጊዜው የሚያበቃበትን ቀን እንዴት መፈለግ እችላለሁ?
1 2 3 4 5 6 7 8 |
# Solution 1 [DateTime]::FromFileTime((Get-ADUser -Identity $user -Properties 'msDS-UserPasswordExpiryTimeComputed').'msDS-UserPasswordExpiryTimeComputed') # Solution 2 Get-Date -Date ((Get-ADUser $user -Properties 'msDS-UserPasswordExpiryTimeComputed' | Select-Object -Property @{ Name = 'ExpiryDate' Expression = {[DateTime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')} }).ExpiryDate)-Format 'F' |
Printers
ከፓወር ሼል አንድ አገልግሎት ሰጪ ላይ ያሉ ፕሪንተሮችን እንዴት መዘርዘር እችላለሁ?
Get-WmiObject -Query 'Select * From Win32_Printer' -ComputerName $computer
ከፓወር ሼል አንድ አገልግሎት ሰጪ ላይ ያሉ ፖርቶችን እንዴት መዘርዘር እችላለሁ?
Get-WmiObject -Class Win32_TCPIPPrinterPort -Namespace 'root\CIMV2' -ComputerName $computer
ከፓወር ሼል የፕሪንተርን አድራሻ እንዴት መቀየር እችላለሁ?
1 2 3 4 |
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'" $printer.Location = 'Germany' $printer.Comment = 'Printer - Test' $printer.Put() |
ከፓወር ሼል የማይፈልጉ ስራዎችን ማስወገድ(ማቋረጥ)እንዴት እችላለሁ?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.CancelAllJobs()
ከፓወር ሼል የሙከራ ወረቀት ማተም እንዴት እችላለሁ?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.PrintTestPage()
ከፓወር ሼል የፕሪንተርን ወረፋ እንዴት ማግኘት እችላለሁ?
1 2 3 4 |
Get-WmiObject -Class Win32_PerfFormattedData_Spooler_PrintQueue | Select-Object -Property Name, @{ Expression = {$_.jobs} Label = 'Current Jobs' } | Format-Table -AutoSize |
Regedit
Read
ከፓወር ሼል ሪጅስትሪ ላይ ያሉ እንከኖችን እንዴት መዘርዘር እችላለሁ?
Get-ChildItem -Path Registry::
ከፓወር ሼል የሪጅስትሪ ዋጋና አይነትን እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
function Get-RegistryValue { Param ( [Parameter(Mandatory = $true)] [string]$RegistryKey ) $key = Get-Item -Path "Registry::$RegistryKey" $key.GetValueNames() | Sort-Object | ForEach-Object -Process { $name = $_ $type = $key.GetValueKind($name) switch ($type) { 'String' {'REG_SZ'} 'Binary' {'REG_BINARY'} 'Dword' {'REG_DWORD'} 'Qword' {'REG_QWORD'} 'MultiString' {'REG_MULTI_SZ'} 'ExpandString'{'REG_EXPAND_SZ'} Default {$null} } [PSCustomObject]@{ Name = $name Type = $type Data = $key.GetValue($name) } } } |
ከፓወር ሼል የሪጅስትሪ ቁልፎችን ንዑስ ቁልፍ እንዴት መዘርዘር እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#HKEY_CLASSES_ROOT New-PSDrive -PSProvider Registry -Root HKEY_CLASSES_ROOT -Name HKCR Get-ChildItem -Path 'HKCR:\' #HKEY_CURRENT_USER Get-ChildItem -Path 'HKCU:\Software' Get-ChildItem -Path Registry::HKEY_CURRENT_USER #HKEY_LOCAL_MACHINE Get-ChildItem -Path 'HKLM:\SYSTEM' Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE #HKEY_USERS New-PSDrive -PSProvider Registry -Root HKEY_USERS -Name HKU Get-ChildItem -Path 'HKU:\' #HKEY_CURRENT_CONFIG New-PSDrive -PSProvider Registry -Root HKEY_CURRENT_CONFIG -Name HKCC Get-ChildItem -Path 'HKCC:\' |
ከፓወር ሼል የሪጅስትሪ ቁልፎችን ንዑስ ቁልፍ በተከታታይ እንዴት መዘርዘር እችላለሁ?
Get-ChildItem -Path 'HKLM:\SYSTEM' -Recurse -ErrorAction SilentlyContinue
ከፓወር ሼል የተወሰነ ስም ያላቸውን ንዑስ ቁልፎችን እንዴት መፈለግ እችላለሁ?
Get-ChildItem -Path 'HKLM:\SOFTWARE' -Include *Plugin* -Recurse -ErrorAction SilentlyContinue
ከፓወር ሼል የሪጅስትሪ ንዑስ ቁልፎችን ስም ብቻ እንዴት መመለስ እችላለሁ?
(Get-ChildItem -Path 'HKLM:\SYSTEM').Name # Return HKEY_LOCAL_MACHINE\SYSTEM\ControlSet
Get-ChildItem -Path 'HKLM:\SYSTEM' -Name # Return ControlSet
ከፓወር ሼል የሪጅስትሪ ዋጋዎችን እንዴት መዘርዘር እችላለሁ?
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
ከፓወር ሼል የተወሰኑ የሪጅስትሪ ዋጋዎችን እንዴት ማንበብ እችላለሁ?
(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ProductName
ከፓወር ሼል ሪሞት ኮምፒውተር ላይ ያሉ የተወሰኑ የሪጅስትሪ ዋጋዎችን እንዴት ማንበብ እችላለሁ?
1 2 3 4 5 |
$hostname = $computer $openRegedit = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $hostname) $openKey = $openRegedit.OpenSubKey('SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion') $keyValue = $openKey.GetValue('ProductName') $keyValue |
Write
ከፓወር ሼል አዲስ የሪጅስትሪ ቁልፍ እንዴት መፍጠር እችላለሁ?
New-Item -Path 'HKCU:\Software\MyApplication'
ከፓወር ሼል አዲስ የሪጅስትሪ ዋጋ እንዴት መፍጠር እችላለሁ?
New-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '1.0'
ከፓወር ሼል በፊት የነበረውን የሪጅስትሪ ዋጋ እንዴት ማስተካከል እችላለሁ?
Set-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '2.0'
Delete
ከፓወር ሼል የሪጅስትሪ ዋጋን እንዴት ማጥፋት እችላለሁ?
Remove-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version'
ከፓወር ሼል የሪጅስትሪ ቁልፍን እንዴት ማጥፋት እችላለሁ?
Remove-Item -Path 'HKCU:\Software\MyApplication' -Force
Test
ከፓወር ሼል የሪጅስትሪ ቁልፍ እንዳለ እንዴት መሞከር እችላለሁ?
Test-Path -Path 'HKCU:\Software\MyApplication'
ከፓወር ሼል የሪጅስትሪ ዋጋ እንዳለ እንዴት መሞከር እችላለሁ?
(Get-Item -Path 'HKCU:\Software\MyApplication').GetValueNames() -contains 'Version'
Strings
ከፓወር ሼል ከቃላት ድርድር በፊት ያለን ባዶ ቦታ እንዴት ማስወገድ እችላለሁ?
$string = ' PowershellGuru'
$string = $string.TrimStart()
ከፓወር ሼል ከቃላት ድርድር በኋላ ያለን ባዶ ቦታ እንዴት ማስወገድ እችላለሁ?
$string = 'PowershellGuru '
$string = $string.TrimEnd()
ከፓወር ሼል ከቃላት ድርድር (በፊት እና በኋላ) ያለን ባዶ ቦታ እንዴት ማስወገድ እችላለሁ?
$string = ' PowershellGuru '
$string = $string.Trim()
ከፓወር ሼል የቃላት ድርድርን ወደ አፐር ኬዝ እንዴት መለወጥ እችላለሁ?
$string = 'powershellguru'
$string = $string.ToUpper()
ከፓወር ሼል የቃላት ድርድርን ወደ ሎውር ኬዝ እንዴት መለወጥ እችላለሁ?
$string = 'POWERSHELLGURU'
$string = $string.ToLower()
ከፓወር ሼል ከቃላት ድርድር “PowerShellGuru” ንዑስ የቃላት ድርድር “PowerShell” እንዴት መምረጥ እችላለሁ?
$string.Substring(0,10)
ከፓወር ሼል ከቃላት ድርድር “PowerShellGuru” ንዑስ የቃላት ድርድር “Guru”ን እንዴት መምረጥ እችላለሁ?
$string.Substring(10)
ከፓወር ሼል “123”ን ከ “PowerShell123Guru” እንዴት መምረጥ እችላለሁ?
$string = 'Powershell123Guru'
[regex]::match($string,'(\d+)').value
ከፓወር ሼል ከቃላት ድርድር “PowerShellGuru” ዜሮን መሰረት ያደረገ የ”Guru” ማውጫ እንዴት ማግኘት እችላለሁ?
$string.IndexOf('Guru') # 10
ከፓወር ሼል የቃላት ድርድር ባዶ ወይም ምንም እንደሌለው እንዴት ማረጋገጥ እችላለሁ?
$string = $null
$string = ''
[string]::IsNullOrEmpty($string)
ከፓወር ሼል የቃላት ድርድር ምንም እንደሌለው ,ባዶ,ወይም ባዶ-ቦታ ብቻ እንደሆነ እንዴት ማረጋገጥ እችላለሁ?
$string = $null
$string = ''
$string = ' '
[string]::IsNullOrWhiteSpace($string)
ከፓወር ሼል የቃላት ድርድር የተወሰነ ፊደል እንደያዘ እንዴት ማረጋገጥ እችላለሁ?
$string = 'PowershellGuru'
$string.Contains('s')
[regex]::match($string,'s').Success
ከፓወር ሼል የቃላት ድርድርን ርዝመት እንዴት መመለስ እችላለሁ?
$string.Length
ከፓወር ሼል ሁለት የቃላት ድርድርን እንዴት ማጋጠም እችላለሁ?
1 2 3 4 5 6 7 |
# Solution 1 $string1 + $string2 # Solution 2 $string1 = 'Powershell' $string2 = 'Guru' [string]::Concat($string1,$string2) |
ከፓወር ሼል ከቃላት ድርድር አንድ ወይም ከዛ በላይ ብራኬቶችን “[ ]” እንዴት ማመሳሰል እችላለሁ?
$string = '[PowershellGuru]'
$string -match '\[' # Only 1
$string -match '\[(.*)\]' # Several
ከፓወር ሼል ከቃላት ድርድር አንድ ወይም ከዛ በላይ ቅንፎችን “( )” እንዴት ማመሳሰል እችላለሁ?
$string = '(PowershellGuru)'
$string -match '\(' # Only 1
$string -match '\((.*)\)' # Several
ከፓወር ሼል ከቃላት ድርድር አንድ ወይም ከዛ በላይ ከርሊ ብራኬቶችን “{ }” እንዴት ማመሳሰል እችላለሁ?
$string = '{PowershellGuru}'
$string -match '\{' # Only 1
$string -match '\{(.*)\}' # Several
ከፓወር ሼል ከቃላት ድርድር አንድ ወይም ከዛ በላይ አንግል ብራኬቶችን “< >” እንዴት ማመሳሰል እችላለሁ?
$string = ''
$string -match '\<' # Only 1
$string -match "\<(.*)\>" # Several
ከፓወር ሼል ከቃላት ድርድር ሎውር ኬዝ ፊደል (abc) እንዴት ማመሳሰል እችላለሁ?
$string = 'POWERSHELLGURU'
$string -cmatch "^[a-z]*$" #False
ከፓወር ሼል ከቃላት ድርድር አፐር ኬዝ ፊደል (ABC) እንዴት ማመሳሰል እችላለሁ?
$string = 'powershellguru'
$string -cmatch "^[A-Z]*$" #False
ከፓወር ሼል ከቃላት ድርድር ውስጥ “[p” (p ሎውር ኬዝ) እንዴት ማመሳሰል እችላለሁ?
$string = '[powershellGuru]'
$string -cmatch '\[[a-z]\w+' #True
ከፓወር ሼል ከቃላት ድርድር ውስጥ “[P” (P አፐር ኬዝ) እንዴት ማመሳሰል እችላለሁ?
$string = '[PowershellGuru]'
$string -cmatch '\[[A-Z]\w+' #True
ከፓወር ሼል አንድን መስመር በሌላ መስመር እንዴት መተካት እችላለሁ?
$a = 'Line A'
$b = 'Line B'
$a = $a -replace $a, $b
ከፓወር ሼል የማካፈል ኦፕሬሽንን ወደ (ፐርሰንታይል) እንዴት መለወጥ እችላለሁ?
(1/2).ToString('P')
ከፓወር ሼል ቁጥር ያላቸውን የቃላት ድርድር እንዴት መልቀም እችላለሁ?
1 |
'string-10', 'string-2', 'string-23', 'string-30' | Sort-Object -Property {$_ -replace '[\d]'}, {$_ -replace '[a-zA-Z\p{P}]'-as [int]} |
ከፓወር ሼል የዓረፍተ ነገርን የመጨረሻ ቃል እንዴት መምረጥእችላለሁ?
$sentence = 'My name is Test Powershell'
$sentence.Split(' ')[-1] # Returns Powershell
ከፓወር ሼል ከዓረፍተ ነገር ውስጥ ረጅሙን ቃል እንዴት ማግኘት እችላለሁ?
$sentence = 'My name is Test Powershell'
$sentence.Split(' ') | Sort-Object -Property Length | Select-Object -Last 1 # Returns Powershell
ከፓወር ሼል የቃላት ድርድር ስንት ጊዜ ዓረፍተ ነገር ውስጥ እንዳለ እንዴት መቁጠር እችላለሁ?
$sentence = 'test test test Powershell'
[regex]::Matches($sentence, 'test').Count # Returns 3
ከፓወር ሼል በቃላት ድርድር ውስጥ ያለን እያንዳንዱን ፊደል ወደ ፊደል ድርድር እንዴት ኮፒ ማድረግ እችላለሁ?
1 2 3 4 5 6 7 |
$name = 'test' $name.ToCharArray() s t e v e |
ከፓወር ሼል የቃላት ድርድር የመጀመሪያ ፊደል ወደ አፐር ኬዝ እንዴት መለወጥ እችላለሁ?
1 2 |
$name = 'test' $name.Substring(0,1).ToUpper() + $name.Substring(1) |
ከፓወር ሼል የቃላት ድርድርን ወደ (ግራ ወይም ቀኝ) እንዴት ማጠጋጋት እችላለሁ?
1 2 3 4 5 6 7 |
# With whitespaces $padRight = 'test'.PadRight(25) $padLeft = 'test'.PadLeft(25) # With characters $padRight = 'test'.PadRight(25,'.') # Return test.................... $padLeft = 'test'.PadLeft(25,'.') # Return ....................test |
ከፓወር ሼል የቃላት ድርድርን ወደ መደብ 64 ኢንኮድ እና ዲኮድ እንዴት ማድረግ እችላለሁ?
1 2 3 4 5 6 7 8 9 10 |
# Encode $string = [System.Text.Encoding]::UTF8.GetBytes('test') $encoded = [System.Convert]::ToBase64String($string) # Decode $string = [System.Convert]::FromBase64String($encoded) $decoded = [System.Text.Encoding]::UTF8.GetString($string) # Encoded : c3RldmU= # Decoded : test |
ከፓወር ሼል ቁጥርን ወደ ባይነሪ እንዴት መለወጥ እችላለሁ?
1 2 3 4 5 |
# Base 10 to Base 2 [System.Convert]::ToString(255,2) # Base 2 to Base 10 [System.Convert]::ToInt32('11111111',2) |
ከፓወር ሼል የመጨረሻውን ፓረንት ፎልደር መገኛ እንዴት መመለስ እችላለሁ?
1 2 |
$path = 'C:\Folder1\Folder2\Folder3\file.txt' Split-Path -Path (Split-Path -Path $path -Parent) -Leaf # Return Folder3 |
ከፓወር ሼል ከመገኛ የመጨረሻውን ነገር ብቻ እንዴት መመለስ እችላለሁ?
1 2 |
$path = 'C:\Folder1\Folder2\Folder3\file.txt' Split-Path -Path $path -Leaf # Return file.txt |
Math
ከፓወር ሼል የ System.Math ክላሶች እንዴት መዘርዘር እችላለሁ?
[System.Math] | Get-Member -Static -MemberType Method
ከፓወር ሼል የአብሶሉት ዋጋ እንዴት መመለስ እችላለሁ?
[Math]::Abs(-12) #Returns 12
[Math]::Abs(-12.5) # Returns 12.5
ከፓወር ሼል ሳይኑ የተወሰነ የሆነን አንግልን እንዴት መመለስ እችላለሁ?
[Math]::ASin(1) #Returns 1,5707963267949
ከፓወር ሼል ወደ ላይኛው የተጠጋጋ ዋጋን እንዴት መመለስ እችላለሁ?
[Math]::Ceiling(1.4) #Returns 2
[Math]::Ceiling(1.9) #Returns 2
ከፓወር ሼል ወደ ታችኛው የተጠጋጋ ዋጋን እንዴት መመለስ እችላለሁ?
[Math]::Floor(1.4) #Returns 1
[Math]::Floor(1.9) #Returns 1
ከፓወር ሼል የተወሰነ ቁጥርን ናቹራል(base e) ሎጋሪዝም እንዴት መመለስ እችላለሁ?
[Math]::Log(4) #Returns 1,38629436111989
ከፓወር ሼል የተወሰነ ቁጥርን ቤዝ 10 ሎጋሪዝም እንዴት መመለስ እችላለሁ?
[Math]::Log10(4) #Returns 0,602059991327962
ከፓወር ሼል ከሁለት ዋጋዎች ትልቁን እንዴት መመለስ እችላለሁ?
[Math]::Max(2,4) #Returns 4
[Math]::Max(-2,-4) #Returns -2
ከፓወር ሼል ከሁለት ዋጋዎች ትንሹን እንዴት መመለስ እችላለሁ?
[Math]::Min(2,4) #Returns 2
[Math]::Max(-2,-4) #Returns -4
ከፓወር ሼል የአንድን ቁጥር በተወሰነ ፓወር እንዴት መመለስ እችላለሁ?
[Math]::Pow(2,4) #Returns 16
ከፓወር ሼል የዴሲማል ዋጋን ወደ ቅርብ ኢንትግራል ዋጋ እንዴት መመለስ እችላለሁ?
[Math]::Round(3.111,2) #Returns 3,11
[Math]::Round(3.999,2) #Returns 4
ከፓወር ሼል የተወሰነ ኢንትግራል ዋጋን ወደ ዴሲማል ቁጥር እንዴት መመለስ እችላለሁ?
[Math]::Truncate(3.111) #Returns 3
[Math]::Truncate(3.999) #Returns 3
ከፓወር ሼል የተወሰነ ቁጥርን ስኩዬር ሩት እንዴት መመለስ እችላለሁ?
[Math]::Sqrt(16) #Returns 4
ከፓወር ሼል የPIን የማይለዋወጥ እንዴት መመለስ እችላለሁ?
[Math]::Pi #Returns 3,14159265358979
ከፓወር ሼል የናቹራል ሎጋሪዝም ቤዝ(የማይለዋወጥ e) እንዴት መመለስ እችላለሁ?
[Math]::E #Returns 2,71828182845905
ከፓወር ሼል አንድ ቁጥር ሙሉ ወይም ጎደሎ መሆኑን እንዴት ማረጋገጥ እችላለሁ?
[bool]($number%2)
Hashtables
ከፓወር ሼል ባዶ ሃሽቴብል እንዴት መፍጠር እችላለሁ?
$hashtable = @{}
$hashtable = New-Object -TypeName System.Collections.Hashtable
ከፓወር ሼል ነገሮች ያሉበት ሃሽቴብል እንዴት መፍጠር እችላለሁ?
1 2 3 4 5 |
$hashtable = @{ 'Key1' = 'Value1' 'Key2' = 'Value2' 'Key3' = 'Value3' } |
ከፓወር ሼል በቁልፍ/በስም የሚለቀም ሃሽቴብል(ስርዐትየጠበቀ ዲክሽነሪ) እንዴት መፍጠር እችላለሁ?
1 2 3 4 5 6 7 |
$hashtable = [ordered]@{ 'Key1' = 'Value1' 'Key2' = 'Value2' 'Key3' = 'Value3' } $hashtable | Get-Member # System.Collections.Specialized.OrderedDictionary |
ከፓወር ሼል ነገሮችን (ቁልፍ-ስም ጥንድ)ወደ ሃሽቴብል እንዴት መጨመር እችላለሁ?
$hashtable.Add('Key3', 'Value3')
ከፓወር ሼል የተወሰነ የሃሽቴብል ዋጋን እንዴት ማግኘት እችላለሁ?
$hashtable.Key1
$hashtable.Get_Item('Key1')
ከፓወር ሼል የሃሽቴብልን ትንሹን ዋጋ እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 |
$hashtable = @{ 'Key1' = '1' 'Key2' = '2' 'Key3' = '3' } $hashtable.GetEnumerator() | Sort-Object -Property Value | Select-Object -First 1 $hashtable.GetEnumerator() | Sort-Object -Property Value -Descending | Select-Object -Last 1 |
ከፓወር ሼል የሃሽቴብልን ትልቁን ዋጋ እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 |
$hashtable = @{ 'Key1' = '1' 'Key2' = '2' 'Key3' = '3' } $hashtable.GetEnumerator() | Sort-Object -Property Value -Descending | Select-Object -First 1 $hashtable.GetEnumerator() | Sort-Object -Property Value | Select-Object -Last 1 |
ከፓወር ሼል ሃሽቴብል ውስጥ ያሉ ነገሮችን እንዴት ማስተካከል እችላለሁ?
$hashtable.Set_Item('Key1', 'Value1Updated')
ከፓወር ሼል ነገሮችን ከሃሽቴብል ውስጥ እንዴት ማስወገድ እችላለሁ?
$hashtable.Remove('Key1')
ከፓወር ሼል ሃሽቴብልን እንዴት ማፅዳት እችላለሁ?
$hashtable.Clear()
ከፓወር ሼል ከሃሽቴብል ውስጥ የተወሰነ ቁልፍ/ዋጋን መገኘት እንዴት ማረጋገጥ እችላለሁ?
$hashtable.ContainsKey('Key3')
$hashtable.ContainsValue('Value3')
ከፓወር ሼል ከሃሽቴብል ውስጥ ቁልፍ/ዋጋ እንዴት መልቀም እችላለሁ?
$hashtable.GetEnumerator() | Sort-Object -Property Name
$hashtable.GetEnumerator() | Sort-Object -Property Value -Descending
Arrays
ከፓወር ሼል ባዶ አሬይ እንዴት መፍጠር እችላለሁ?
$array = @()
$array = [System.Collections.ArrayList]@()
ከፓወር ሼል ነገሮች ያሉበት አሬይ እንዴት መፍጠር እችላለሁ?
$array = @('A', 'B', 'C')
$array = 'A', 'B', 'C'
$array = 'a,b,c'.Split(',')
$array = .{$args} a b c
$array = echo a b c
ከፓወር ሼል ነገሮችን ወደ አሬይ እንዴት መጨመር እችላለሁ?
$array += 'D'
[void]$array.Add('D')
ከፓወር ሼል አሬይ ውስጥ ያለን ነገር እንዴት ማስተካከል እችላለሁ?
$array[0] = 'Z' # 1st item[0]
ከፓወር ሼል የአሬይን መጠን እንዴት ማረጋገጥ እችላለሁ?
$array = 'A', 'B', 'C'
$array.Length # Returns 3
ከፓወር ሼል አንድን ነገር/የተለያየ/ሁሉንም እንዴት ማምጣት እችላለሁ?
$array = @('A', 'B', 'C')
$array[0] # One item (A)
$array[0] + $array[2] # Several items (A,C)
$array # All items (A,B,C)
ከፓወር ሼል በአሬይ ውስጥ ያሉ ባዶ ነገሮችን እንዴት ማስወገድ እችላለሁ?
$array = @('A', 'B', 'C', '')
$array = $array.Split('',[System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object # A,B,C
ከፓወር ሼል አንድን ነገር አሬይ ውስጥ እንዳለ እንዴት ማረጋገጥ እችላለሁ?
$array = @('A', 'B', 'C')
'A' | ForEach-Object -Process {$array.Contains($_)} # Returns True
'D' | ForEach-Object -Process {$array.Contains($_)} # Returns False
ከፓወር ሼል የአሬይን ማውጫ ቁጥር እንዴት መፈለግ እችላለሁ?
$array = @('A', 'B', 'C')
[array]::IndexOf($array,'A') # Returns 0
ከፓወር ሼል አሬይ ውስጥ ያሉ ነገሮችን ተራቸውን እንዴት ማገለባበጥ እችላለሁ?
$array = @('A', 'B', 'C')
[array]::Reverse($array) # C,B,A
ከፓወር ሼል ከአሬይ ድንገተኛ የሆነ ነገርን እንዴት ማመንጨት እችላለሁ?
$array | Get-Random
ከፓወር ሼል አንድ አሬይን በማሻቀብ/በማሽቆልቆል እንዴት መልቀም እችላለሁ?
$array = @('A', 'B', 'C')
$array | Sort-Object # A,B,C
$array | Sort-Object -Descending # C,B,A
ከፓወር ሼል በአሬይ ውስጥ ያሉ ነገሮችን እንዴት መቁጠር እችላለሁ?
$array.Count
ከፓወር ሼል አንድን አሬይ ሌላ ውስጥ እንዴት መጨመር እችላለሁ?
$array1 = 'A', 'B', 'C'
$array2 = 'D', 'E', 'F'
$array3 = $array1 + $array2 # A,B,C,D,E,F
ከፓወር ሼል ከአሬይ ተደጋጋሚዎችን እንዴት መፈለግ እችላለሁ?
$array = 'A', 'B', 'C', 'C'
($array | Group-Object | Where-Object -FilterScript {$_.Count -gt 1}).Values # Returns C
ከፓወር ሼል ከአሬይ ተደጋጋሚዎችን እንዴት ማጥፋት እችላለሁ?
$array = 'A', 'B', 'C', 'C'
$array = $array | Select-Object -Unique
$array # Returns A,B,C
ከፓወር ሼል ቅድመ ቅጥያቸው (“user01″,”user02”,… “user10”) የሆነ አሬይን እንዴት መፍጠር እችላለሁ?
$array = 1..10 | ForEach-Object -Process { "user$_" }
ACL
ከፓወር ሼል የADን ACL እንዴት መዘርዘር እችላለሁ?
(Get-Acl -Path "AD:\$dn").Access
ከፓወር ሼል የፎልደርን ACL እንዴት መዘርዘር እችላለሁ?
(Get-Acl -Path C:\scripts).Access
ከፓወር ሼል የACL የፍቃድ ገቢዎችን(ተጠቃሚዎች ወይም ግሩፖች)እንዴት መዘርዘር እችላለሁ?
1 |
((Get-Acl -Path "AD:\$dn").Access | Select-Object -Property IdentityReference | Where-Object -FilterScript {$_.IdentityReference -match 'Admin'} | Get-Unique | ForEach-Object -Process {$_.IdentityReference}).Value |
Variables
ከፓወር ሼል የሚታወቁ ዳታ አይነቶች እነማን ናቸው?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[bool]$variable = $true [byte]$variable = ('0x10') [char]$variable = 0x260E [datetime]$variable = Get-Date [decimal]$variable = 1.89 [double]$variable = 1.89 [float]$variable = 1.89 [guid]$variable = 'b19b2a2e-ce1b-4b62-844f-ac8829ffbe8f' [int16]$variable = -32767 [int32]$variable = -2147483647 [int64]$variable = -9223372036854775807 [string]$variable = 'test' [uint16]$variable = 32767 [uint32]$variable = 2147483647 [uint64]$variable = 9223372036854775807 |
ከፓወር ሼል የአንድን አይነት ቫርያብል ትንሹንና ትልቁን ዋጋ እንዴት ማግኘት እችላለሁ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[int] (integer) # int16 : MIN:-32768 MAX:32767 'MIN:{1:D} MAX:{0:D}' -f [int16]::MaxValue, [int16]::MinValue # int32 : MIN:-2147483648 MAX:2147483647 'MIN:{1:D} MAX:{0:D}' -f [int32]::MaxValue |