కాన్సెప్ట్: తరచుగా Powershell గురించి ప్రశ్నలు.
మీరు వివిధ మార్గాల్లో ఈ జాబితా ఉపయోగించవచ్చు:
- స్క్రిప్ట్గా / పేస్ట్ ఆదేశాలను కాపీ
- వెంటనే ఒక నిర్దిష్ట కమాండ్ యొక్క సింటాక్స్ చూడండి
- మీ సాంకేతిక జ్ఞానాన్ని పెంచుకోండి
- కొత్త ఆదేశాలు తెలుసుకుంటారు
- ఒక ఉద్యోగ ఇంటర్వ్యూ సిద్ధం
నవీకరించబడింది |
జూలై 02, 2015
|
రచయిత | powershell-guru.com |
మూల0 | telugu.powershell-guru.com |
వర్గం |
75
|
ప్రశ్నలు |
610
|
System
ఎలా PowerShell నా వెర్షన్ నిర్ణయించడం ఎలా?
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 అమలు చేయడానికి?
powershell.exe -Version 2.0
ఎలా PowerShell తో స్క్రిప్ట్ లో ఒక తక్కువ PowerShell వెర్షన్ (3.0 మరియు అధిక) అవసరం?
#Requires -Version 3.0
ఎలా PowerShell తో స్క్రిప్ట్ కోసం నిర్వాహక అధికారాలను అవసరం?
1 2 3 4 5 |
# Solution 1 #Requires -RunAsAdministrator # Solution 2 [bool]((whoami.exe /all) -match 'S-1-16-12288') |
ఎలా PowerShell తో స్క్రిప్ట్ పారామితులు తనిఖీ ఎలా?
help -Name .\Get-ExchangeEnvironmentReport.ps1 -Full
ఎలా PowerShell తో ప్రస్తుత యూజర్ కోసం సమాచారం పొందడానికి?
[Security.Principal.WindowsIdentity]::GetCurrent()
ఎలా సృష్టించడానికి, సవరించడానికి మరియు PowerShell తో ఒక ప్రొఫైల్ రీలోడ్?
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 |
ఎలా PowerShell తో ఒక లిపిలో 5 సెకన్ల / నిమిషాల విరామం చేయడానికి?
Start-Sleep -Seconds 5
Start-Sleep -Seconds 300 # 5 minutes
ఎలా PowerShell తో గత బూట్ సమయం పొందుటకు?
(Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime
ఎలా PowerShell తో రకము యాక్సిలరేటర్ పొందడానికి?
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 |
ఎలా PowerShell తో స్టార్టప్ ప్రొగ్రాయ్ జాబితా?
1 |
Get-WmiObject -Class Win32_StartupCommand | Sort-Object -Property Caption | Format-Table -Property Caption, Command, User -AutoSize |
ఎలా PowerShell తో ఒక అప్లికేషన్ అన్ఇన్స్టాల్?
1 2 |
$application = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name LIKE 'HP Recovery Manager'" $application.Uninstall() |
ఎలా మొత్తం డెస్క్ టాప్ లేదా PowerShell తో ఒక క్రియాశీల గవాక్షం యొక్క స్క్రీన్ షాట్ వహించడానికి ఎలా?
Take-ScreenShot -Screen -File 'C:\scripts\screenshot.png' -Imagetype JPEG
Repository : Take-ScreenShot
ఎలా PowerShell తో MSMQ క్యూలు సందేశాన్ని కౌంట్ పొందడానికి?
1 |
Get-WmiObject -Class Win32_PerfRawData_MSMQ_MSMQQueue -ComputerName $computer | Format-Table -Property Name, MessagesInQueue -AutoSize |
ఎలా PowerShell తో అమలు విధానం సెట్ ఎలా?
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 |
ఎలా PowerShell తో ఒక షార్ట్ కట్ సృష్టించడానికి?
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() |
ఎలా పిన్ లేదా PowerShell తో టాస్క్ బార్ కార్యక్రమాన్ని పిన్ తీసివేయి?
1 2 3 4 |
$shell = New-Object -ComObject shell.application $program = $shell.Namespace($env:windir).Parsename('notepad.exe') $program.Invokeverb('TaskbarPin') $program.Invokeverb('TaskbarUnpin') |
ఎలా PowerShell తో ఒక ఎక్స్ ఫ్లొరర్ విండోస్ తెరిచేందుకు?
[Diagnostics.Process]::Start('explorer.exe')
Invoke-Item -Path C:\Windows\explorer.exe
ఎలా PowerShell తో పరికర డ్రైవర్లు జాబితా?
Get-WmiObject -Class Win32_PnPSignedDriver
Get-WindowsDriver -Online -All
driverquery.exe
ఎలా PowerShell తో ఒక GUID సృష్టించడానికి?
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') |
ఎలా PowerShell తో ప్రస్తుత యూజర్ కోసం తాత్కాలిక డైరక్టరీని స్థానాన్ని పొందడానికి?
[System.IO.Path]::GetTempPath()
ఎలా ఒక మార్గం మరియు PowerShell తో ఒక్క మార్గంలో ఒక పిల్లల మార్గం చేరడానికి?
Join-Path -Path C:\ -ChildPath \windows
ఎలా PowerShell తో అన్ని cmdlets “Get- *” జాబితా?
Get-Command -Verb Get
ఎలా PowerShell తో ప్రత్యేక సిస్టమ్ ఫోల్డర్లు జాబితా?
1 |
[System.Enum]::GetNames([System.Environment+SpecialFolder]) | ForEach-Object -Process { $_ + " [System.Environment]::GetFolderPath($_)" } |
ఎలా PowerShell తో ISO / VHD ఫైళ్లు మౌంట్?
Mount-DiskImage 'D:\ISO\file.iso' # ISO
Mount-DiskImage 'D:\VHD\file.vhd' # VHD
ఎలా PowerShell తో ఇన్స్టాల్ .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 PowerShell తో ఇన్స్టాల్ చేసినట్లయితే తనిఖీ ఎలా?
(Get-ItemProperty -Path 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full' -EA 0).Version -like '4.5*'
ఎలా మొదలు మరియు PowerShell తో (Windows PowerShell సెషన్ రికార్డు సృష్టించడానికి) నకలు ఆపడానికి?
Start-Transcript -Path 'C:\scripts\transcript.txt
Stop-Transcript
ఎలా PowerShell తో ఒక నిర్దిష్ట నగర ప్రస్తుత డైరెక్టరీ మార్చడం ఎలా?
Set-Location -Path 'C:\scripts'
ఎలా PowerShell తో స్క్రీన్ క్లియర్?
Clear-Host
cls # Alias
ఎలా PowerShell తో ప్రదర్శన స్పష్టత మార్చడానికి ఎలా?
Set-DisplayResolution -Width 1280 -Height 1024 -Force # Windows 2012
ఎలా PowerShell తో పూర్తి స్క్రీన్ విండో సెట్ ఎలా?
mode.com 300
ఎలా PowerShell తో ఒక చిత్రాన్ని కొలతలు (వెడల్పు మరియు ఎత్తు) పొందుటకు?
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 } |
ఎలా PowerShell తో Windows ఉత్పత్తి కీ పొందడానికి?
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
ఎలా PowerShell తో గత 5 సెకన్లు (10 సార్లు) ప్రస్తుత “% ప్రాసెసర్ సమయం” (సగటు) పొందుటకు?
(Get-Counter '\Processor(_total)\% Processor Time' -SampleInterval 5 -MaxSamples 10).CounterSamples.CookedValue
Assemblies
ఎలా PowerShell తో సమావేశాలు లోడ్?
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') |
ఎలా PowerShell తో లోడ్ ప్రస్తుత .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*' } |
ఎలా PowerShell తో GAC (గ్లోబల్ అసెంబ్లీ Cache) మార్గం కనుగొనేందుకు?
1 |
(New-Object -TypeName Regex -ArgumentList '(?<=file:///)(.*)(?=\/GAC)', 'IgnoreCase').Match(([PSObject].Assembly.Evidence | Where-Object -FilterScript { $_.Value -ne $null }).Value).Value -replace '/', '\' |
Clipboard
ఎలా PowerShell తో క్లిప్ బోర్ద్ ఫలితాలు కాపీ?
1 |
Get-Process | clip.exe |
ఎలా PowerShell తో క్లిప్ బోర్ద్ కంటెంట్ పొందడానికి?
Add-Type -AssemblyName PresentationCore
[Windows.Clipboard]::GetText()
Hotfixes
ఎలా PowerShell తో ఇన్స్టాల్ hotfixes పొందడానికి?
Get-HotFix -ComputerName $computer
ఎలా PowerShell తో ఒక నిర్దిష్ట తేదీ తర్వాత ముందు ఇన్స్టాల్ hotfixes / పొందాలో?
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
ఒక hotfix PowerShell తో ఇన్స్టాల్ చేసినట్లయితే తనిఖీ ఎలా?
Get-HotFix -Id KB2965142
ఎలా PowerShell తో రిమోట్ కంప్యూటర్లో ఇన్స్టాల్ hotfixes పొందడానికి?
Get-HotFix -ComputerName $computer
Pagefile
ఎలా PowerShell తో పేజ్ ఫైల్ సమాచారం పొందడానికి?
Get-WmiObject -Class Win32_PageFileusage | Select-Object -Property Name, CurrentUsage, AllocatedBaseSize, PeakUsage, InstallDate
ఎలా PowerShell తో పేజ్ ఫైల్ సిఫార్సు పరిమాణం (MB) పొందుటకు?
[Math]::Truncate(((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory) / 1MB) * 1.5
ఎలా D ఒక పేజ్ ఫైల్ (4096 MB) సృష్టించడానికి: PowerShell తో డ్రైవ్?
1 2 3 4 5 |
Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{ Name = 'D:\pagefile.sys' InitialSize = 4096 MaximumSize = 4096 } |
ఎలా సి ఒక pagefile తొలగించడానికి: PowerShell తో డ్రైవ్?
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
ఎలా PowerShell తో ఒక డ్రైవ్ ఫ్రాగ్మెంటేషన్ తనిఖీ ఎలా?
1 |
$drive = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = 'c:'" $defragReport = $drive.DefragAnalysis() $defragReport.DefragAnalysis |
ఎలా PowerShell తో డ్రైవులు డిస్క్ స్పేస్ తనిఖీ ఎలా?
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
ఎలా PowerShell తో ఒక ఫైల్ తెరిచి?
Invoke-Item -Path 'C:\scripts\file.txt'
.'C:\scripts\file.txt'
ఎలా PowerShell తో ఒక ఫైల్ చదవడానికి?
Get-Content -Path 'C:\scripts\file.txt'
gc "C:\scripts\file.txt" # Alias
ఎలా PowerShell తో ఒక ఫైల్ కు ఔట్ పుట్ వ్రాయడానికి?
'Line1', 'Line2', 'Line3' | Out-File -FilePath 'C:\scripts\file.txt'
'Line1', 'Line2', 'Line3' | Add-Content -Path file.txt
ఎలా PowerShell తో ప్రస్తుత స్క్రిప్ట్ ఫైలు యొక్క పుర్తి పేరు పొందడానికి?
$MyInvocation.MyCommand.Path
ఎలా PowerShell తో / zip ఫైళ్లను విస్తరించడంలో?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory($folder,$fileZIP)
ఎలా PowerShell తో /ఆన్ జిప్ ఫైళ్ళను విస్తరించడంలో?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::ExtractToDirectory($fileZIP, $folder)
ఎలా PowerShell తో ఒక జిప్ ఆర్చీవ్ ఫైల్స్ చూడటానికి?
Add-Type -AssemblyName 'System.IO.Compression.Filesystem'
[System.IO.Compression.ZipFile]::OpenRead($fileZIP)
ఎలా PowerShell తో KB ఒక ఫైల్ యొక్క పరిమాణం ప్రదర్శించడానికి?
(Get-ChildItem -Path .\winsrv.dll).Length /1KB
(Get-ChildItem -Path .\winsrv.dll).Length /1MB
(Get-ChildItem -Path .\winsrv.dll).Length /1GB
ఎలా పెద్ద ఫైళ్ళను లేదా PowerShell తో 1 GB కంటే తక్కువ కనుగొనేందుకు?
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} |
ఎలా PowerShell తో పొడిగింపు లేకుండా ఒక ఫైల్ యొక్క పేరు ప్రదర్శించడానికి?
[System.IO.Path]::GetFileNameWithoutExtension('C:\Windows\system32\calc.exe') # Return calc
ఎలా PowerShell తో ఒక ఫైల్ పొడిగింపు ప్రదర్శించడానికి?
[System.IO.Path]::GetExtension('C:\scripts\file.txt') # Return .txt
ఎలా PowerShell తో ఒక ఫైల్ యొక్క ఫైల్ వెర్షన్ పొందుటకు?
1 2 |
(Get-Item -Path C:\Windows\System32\calc.exe).VersionInfo.FileVersion [System.Diagnostics.FileVersionInfo]::GetVersionInfo('C:\Windows\system32\calc.exe').FileVersion |
ఒక ఫైల్ ఎలా Powershell హ్యష్ పొందడానికి?
(Get-FileHash $file).Hash
ఎలా PowerShell తో ఒక ఫైల్ యొక్క MD5 / SHA1 చెక్ సయ్ పొందడానికి?
Get-FileHash $file -Algorithm MD5
Get-FileHash $file -Algorithm SHA1
ఎలా PowerShell తో దాచిన ఫైళ్లు ప్రదర్శించడానికి?
1 2 3 4 5 |
# Display only hidden files Get-ChildItem -Hidden -File # Display all files (including hidden files) Get-ChildItem -Force -File |
ఒక ఫైల్ PowerShell తో ఒక పొడిగింపును కలిగి ఉంటే తనిఖీ ఎలా?
1 |
[System.IO.Path]::HasExtension('C:\hiberfil.sys') |
ఎలా మాత్రమే PowerShell తో చదవండి వంటి ఫైల్ సెట్ ఎలా?
Set-ItemProperty -Path .\file.txt -Name IsReadOnly -Value $true
ఎలా PowerShell తో ఒక ఫైల్ కోసం గత వారం LastWriteTime గుణం మార్చడం ఎలా?
Set-ItemProperty -Path .\file.txt -Name LastWriteTime -Value ((Get-Date).AddDays(-7))
If not working, use Nirsoft tool: BulkFileChanger.
ఎలా PowerShell తో ఒక కొత్త ఫైల్ సృష్టించడానికి?
New-Item -ItemType File -Path 'C:\scripts\file.txt' -Value 'FirstLine'
ఎలా PowerShell తో ఒక ఫైలు పేరును?
Rename-Item -Path 'C:\scripts\file.txt' -NewName 'C:\scripts\powershellguru2.txt'
ఎలా బల్క్ / బ్యాచ్ PowerShell తో బహుళ ఫైళ్లను పేరు ఎలా?
Get-ChildItem -Path C:\scripts\txt | Rename-Item -NewName { $_.Name -replace ' ', '_' }
ఎలా PowerShell తో ఒక ఫైల్ను మీరు తొలగించాలని?
Remove-Item -Path 'C:\scripts\file.txt'
ఎలా PowerShell తో ఒక ఫైల్ యొక్క 10 తాజా పంక్తులు ప్రదర్శించడానికి?
Get-Content -Path 'C:\scripts\log.txt' -Tail 10
ఎలా PowerShell తో ఫోల్డర్ పలు ఫైళ్లను బ్లాక్ తీయడానికి?
Get-ChildItem -Path 'C:\scripts\Modules' | Unblock-File
ఎలా PowerShell తో ఒక ఫైల్ నుండి ఖాళీ పంక్తులు తొలగించడానికి ఎలా?
(Get-Content -Path file.txt) | Where-Object -FilterScript {$_.Trim() -ne '' } | Set-Content -Path file.txt
ఒక ఫైల్ PowerShell తో ఉనికిలో ఉంటే తనిఖీ ఎలా?
1 |
Test-Path -Path 'C:\Windows\notepad.exe' # Return True |
ఎలా PowerShell తో ఫోల్డర్ లో సరికొత్త / పురాతన రూపొందించినవారు ఫైలు ఎలా పొందాలో?
1 2 |
Get-ChildItem | Sort-Object -Property CreationTime | Select-Object -Last 1 # Newest Get-ChildItem | Sort-Object -Property CreationTime | Select-Object -First 1 # Oldest |
ఎలా PowerShell తో ఒక ఫైల్ నుండి నకిలీలను పంక్తులు తొలగించడానికి ఎలా?
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 |
ఎలా PowerShell తో ఫోల్డర్ లో మరింత / 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 |
ఎలా PowerShell తో ఫోల్డర్ లో మరింత / తక్కువ కంటే 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 |
ఎలా PowerShell తో ఒక ఫైల్ ఒక వేరియబుల్ విలువ ఎగుమతి?
Set-Content -Path file.txt -Value $variable
ఎలా PowerShell తో ఒక ఫోల్డర్లో ఫైళ్లను సంఖ్య (* .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 |
ఎలా PowerShell తో బహుళ ఫైళ్లను లోపల ఒక స్ట్రింగ్ అన్వేషణ?
Select-String -Path 'C:\*.txt' -Pattern 'Test'
ఎలా PowerShell తో ఒక ఫైల్ యొక్క మొదటి / చివరి లైన్ ప్రదర్శించడానికి?
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 |
ఎలా PowerShell తో ఒక ఫైల్ యొక్క ఒక నిర్దిష్ట లైన్ సంఖ్య ప్రదర్శించడానికి?
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 |
ఎలా PowerShell తో ఒక ఫైల్ యొక్క రేఖల సంఖ్య లెక్కించడానికి?
1 2 |
'Line1', 'Line2', 'Line3' | Out-File -FilePath file.txt (Get-Content -Path .\file.txt | Measure-Object -Line).Lines # Returns 3 |
ఎలా PowerShell తో ఒక ఫైల్ యొక్క అక్షరాలు మరియు పదాలు సంఖ్యను లెక్కించటానికి?
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 |
ఎలా PowerShell తో ఒక ఫైల్ డౌన్ లోడ్ ఎలా?
Invoke-WebRequest -Uri 'http://www.nirsoft.net/utils/searchmyfiles.zip' -OutFile 'C:\tools\searchmyfiles.zip'
ఎలా PowerShell తో ఒక ఫైల్ పూర్తి మార్గం ప్రదర్శించడానికి?
Resolve-Path -Path .\script.ps1 # Return C:\Scripts\script.ps1
Copy
ఎలా PowerShell తో ఒక ఫోల్డర్కు ఒక ఫైల్ కాపీ ఎలా?
Copy-Item -Path 'C:\source\file.txt' -Destination 'C:\destination'
ఎలా PowerShell బహుళ ఫోల్డర్లను ఒక ఫైల్ కాపీ ఎలా?
1 2 |
$destination = 'C:\destination\Folder1', 'C:\destination\Folder2' $destination | Copy-Item -Path 'C:\source\file.txt' -Recurse -Destination {$_} |
ఎలా PowerShell లో ఒక ఫోల్డర్ బహుళ ఫైళ్లను కాపీ?
Get-ChildItem -Path 'C:\source' -Filter *.txt | Copy-Item -Destination 'C:\destination'
Active Directory
Domain & Forest
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో గ్లోబల్ కాటలాగ్ సర్వర్లు కనుగొనేందుకు?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ సైట్లు కనుగొనేందుకు?
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
ఎలా PowerShell తో ప్రస్తుత డొమైన్ నియంత్రకం కనుగొనేందుకు?
(Get-ADDomainController).HostName
ఎలా PowerShell తో ఒక డొమైన్ లో అన్ని డొమైన్ నియంత్రిక కనుగొనేందుకు?
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} |
ఎలా PowerShell తో AD ప్రతికృతి వైఫల్యాలు కనుగొనేందుకు?
Get-ADReplicationFailure dc02.domain.com # Windows 8 and 2012
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ అడవి కోసం సమాధి జీవితకాలం తెలుసుకోవడం ఎలా?
1 |
(Get-ADObject -Identity "cn=Directory Service,cn=Windows NT,cn=Services,$(([adsi]('LDAP://RootDSE')).configurationNamingContext)" -Properties tombstonelifetime).tombstonelifetime |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో అడవి / డొమైన్ వివరాలు పొందడానికి?
1 2 |
Get-ADDomain domain.com Get-ADForest domain.com |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో “తొలగించినవి Objects” కంటైనర్ మార్గం పొందడానికి?
(Get-ADDomain).DeletedObjectsContainer
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ 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' |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ రీసైకిల్ బిన్ నుండి ఒక ప్రకటనను ఖాతా పునరుద్ధరించడానికి ఎలా?
Get-ADObject -Filter 'samaccountname -eq "powershellguru"' -IncludeDeletedObjects | Restore-ADObject
ఎలా PowerShell తో 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 |
ఎలా PowerShell తో ఒక నిర్దిష్ట డొమైన్ కంట్రోలర్ కు కనెక్ట్?
Get-ADUser -Identity $user -Server 'serverDC01'
ఎలా PowerShell తో ప్రస్తుత లాగాన్ సర్వర్ కావాలని?
1 2 |
($env:LOGONSERVER).Substring(2) ([System.Environment]::GetEnvironmentVariable('logonserver')).Substring(2) |
ఎలా PowerShell తో ఒక కంప్యూటర్లో “gpupdate” నిర్వహించడానికి ఎలా?
Invoke-GPUpdate -Computer $computer -Force -RandomDelayInMinutes 0 # Windows 2012
Groups
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ కొత్త గుంపును సృష్టించడానికి?
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' |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ గుంపును తొలగించు?
Remove-ADGroup -Identity 'PowershellGuru'
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ సమూహానికి వినియోగదారుని జోడించడానికి ఎలా?
Add-ADGroupMember "Powershell Guru" -Members powershellguru
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో గుంపు నుండి ఒక యూజర్ తొలగించడానికి ఎలా?
Remove-ADGroupMember 'Powershell Guru' -Members powershellguru
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ (ఏ సభ్యులతో) ఖాళీ సమూహాలు కనుగొనేందుకు?
Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ (ఏ సభ్యులతో) ఖాళీ సమూహాలు లెక్కించడానికి?
(Get-ADGroup -Filter * -Properties Members | Where-Object -FilterScript {-not $_.Members}).Count
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో గుంపు సభ్యులు పొందడానికి?
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' |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ రికర్సివ్ సభ్యులతో ఒక గుంపు సభ్యులు పొందడానికి?
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
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ “గెట్-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 |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ మరొక OU ఒక యూజర్ తరలించడానికి?
Move-ADObject -Identity $dn -TargetPath 'OU=myOU,DC=domain,DC=com'
ఎలా PowerShell తో వినియోగదారు కోసం అన్ని MemberOf (Nested) కనుగొనడానికి?
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($dn))"
ఎలా PowerShell తో ఒక వినియోగదారు కోసం MemberOf (చిన్న పేరు / కత్తిరించబడింది) పొందుటకు?
(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 |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారు ఖాతా కోసం వివరణ, ఆఫీసు మరియు (టెలి) ఫోన్ నంబర్ మార్చడం ఎలా?
Set-ADUser $samAccountName -Description 'IT Consultant' -Office 'Building B' -OfficePhone '12345'
1 2 3 4 5 |
# 31/12/2015 Set-ADAccountExpiration $samAccountName -DateTime '01/01/2016' # Never Clear-ADAccountExpiration $samAccountName |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారు డీ ఖాతా అన్లాక్ ఎలా?
Unlock-ADAccount $samAccountName
ఎలా ఎనేబుల్ / PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారుడీ ఖాతా డిసేబుల్?
1 2 |
Disable-ADAccount $samAccountName Enable-ADAccount $samAccountName |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారుడీ ఖాతా తొలగించడానికి ఎలా?
Remove-ADUser $samAccountName
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారుడీ ఖాతా కోసం ఫాస్ వర్డ్ రీసెట్?
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 |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ పలు వినియోగదారుడీ ఖాతాలు (సమూహ) కోసం ఒక ఫాస్ వర్డ్ రీసెట్?
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 |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో ఒక ఫైల్ యొక్క యజమాని కనుగొనేందుకు?
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 |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారు కోసం OU (ఆర్గనైజేషనల్ యూనిట్) కనుగొనడానికి?
[regex]::match("$((Get-ADUser $user -Properties DistinguishedName).DistinguishedName)",'(?=OU=)(.*\n?)').value
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ వికలాంగులు వినియోగదారుల ఖాతాలకు కనుగొనేందుకు?
1 2 |
Search-ADAccount -AccountDisabled Get-ADUser -Filter {Enabled -ne $true} |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో గడువు వినియోగదారుల ఖాతాలకు కనుగొనేందుకు?
Search-ADAccount -AccountExpired
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లాక్ వినియోగదారుల ఖాతాలకు కనుగొనేందుకు?
Search-ADAccount -LockedOut
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక వినియోగదారు ఖాతా SID కనుగొనేందుకు?
(Get-ADUser $user -Properties SID).SID.Value
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ SID కు ఒక యూజర్ పేరు మార్చేందుకు?
1 2 |
$user = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList ('DOMAIN', 'user') $SID = ($user.Translate([System.Security.Principal.SecurityIdentifier])).Value |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ వాడుకరిపేరు ఒక SID మార్చేందుకు?
1 2 |
$SID = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ('SID') $user = ($SID.Translate( [System.Security.Principal.NTAccount])).Value |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ వినియోగదారు ఖాతాకు యొక్క విశిష్ట పేరు స్ప్లిట్?
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" |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ వినియోగదారు ఖాతాకు సృష్టి / సవరణ తేదీ కనుగొనేందుకు?
Get-ADUser -Identity $user -Properties whenChanged, whenCreated | Format-List -Property whenChanged, whenCreated
1 2 3 |
$schema = [DirectoryServices.ActiveDirectory.ActiveDirectorySchema]::GetCurrentSchema() $schema.FindClass('user').mandatoryproperties | Format-Table $schema.FindClass('user').optionalproperties | Format-Table |
ఎలా PowerShell తో Active Directory తో ఒక వినియోగదారు కోసం 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 |
ఎలా PowerShell తో Active Directory తో ఒక వినియోగదారు కోసం CN (చట్ట పేరు) మార్చడం ఎలా?
Rename-ADObject $((Get-ADUser $user -Properties DistinguishedName).DistinguishedName) -NewName 'Test Powershell'
1 2 |
$dn = (Get-ADUser $user -Properties DistinguishedName).DistinguishedName $parent = $dn.Split(',',2)[1] |
ఎలా PowerShell తో Active Directory తో (ఖాతా సృష్టించిన) ఒక వినియోగదారు యొక్క యజమాని పొందడానికి?
1 2 |
$dn = (Get-ADUser $user -Properties DistinguishedName).DistinguishedName $owner = (Get-Acl -Path "AD:$dn").Owner |
ఎలా PowerShell తో Active Directory తో ఒక వినియోగదారు కోసం pwdLastSet గుణం మార్చేందుకు?
1 2 3 4 5 |
# Solution 1 [DateTime]::FromFileTime((Get-ADUser $user -Properties pwdLastSet).pwdLastSet) # Solution 2 w32tm /ntte 130787549514737594 |
Computers
ఎలా స్థానిక కంప్యూటర్ మరియు PowerShell తో డొమైన్ మధ్య సురక్షిత చానెల్ పరీక్షించడానికి?
Test-ComputerSecureChannel
ఎలా స్థానిక కంప్యూటర్ మరియు PowerShell తో డొమైన్ మధ్య సురక్షిత చానెల్ రిపేరు?
Test-ComputerSecureChannel -Repair
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో కంప్యూటర్ ఖాతాలో డిసేబుల్?
Disable-ADAccount $computer
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ నిర్దిష్ట ఆపరేటింగ్ సిస్టమ్ కంప్యూటర్లు కనుగొనేందుకు?
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)
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక ఆర్గనైజేషనల్ యూనిట్ (OU) సృష్టించడానికి?
New-ADOrganizationalUnit -Name 'TEST' -Path 'DC=domain,DC=com'
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఆర్గనైజేషనల్ యూనిట్ (OU) వివరాలను పొందడానికి?
Get-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -Properties *
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ ఒక ఆర్గనైజేషనల్ యూనిట్ (OU) యొక్క వివరణ మార్చడానికి ఎలా?
Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -Description 'My description'
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 |
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ అన్ని ఆర్గనైజేషనల్ యూనిట్ (OU) అనుకోకుండా తొలగింపు ఎనేబుల్?
1 |
Get-ADOrganizationalUnit -Filter * -Property ProtectedFromAccidentalDeletion | Where-Object -FilterScript { $_.ProtectedFromAccidentalDeletion -eq $false } | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true |
1 2 |
Set-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' -ProtectedFromAccidentalDeletion $false Remove-ADOrganizationalUnit 'OU=TEST,DC=domain,DC=com' |
1 2 |
$parent = $dn.Split(',',2)[1] $parent = (Get-ADOrganizationalUnit $parent -Properties CanonicalName).CanonicalName |
ఎలా PowerShell తో ఖాళీ సంస్థల యూనిట్ల (మరో మార్గము) జాబితాకు?
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 } |
ఎలా PowerShell తో ఒక సమూహం యొక్క మేనేజర్ పొందడానికి?
(Get-ADGroup $dn -Properties Managedby).Managedby
Regex (Regular Expression)
ఎలా PowerShell తో Regex తో ఒక 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
“-” Regex తో PowerShell తో ఎలా విభజించడానికి ఒక 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
విభజించడానికి తో (2D: డీ -9: 62: 39: 61 C0) “:” Regex తో PowerShell ఎలా ఒక MAC చిరునామా సేకరించేందుకు?
$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
ఎలా PowerShell తో Regex ఒక తేదీ (10/02/2015) సేకరించేందుకు?
$example = 'The date is 10/02/2015'
$date = [regex]::match($example,'(\d{2}\/\d{2}\/\d{4})').value
ఎలా PowerShell తో Regex ఒక URL (www.powershell-guru.com) సేకరించేందుకు?
$example = 'The URL is www.powershell-guru.com'
$url = [regex]::match($example,'[a-z]+[:.].*?(?=\s)').value
ఎలా PowerShell తో Regex తో ఒక ఈ మెయిల్ (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
ఎలా PowerShell తో Regex తో స్ట్రింగ్ ఉదాహరణకు నుండి “గురు” తీయడం ఎలా?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?=.com)').value
ఎలా PowerShell తో Regex తో స్ట్రింగ్ ఉదాహరణకు నుండి “guru.com” తీయడం ఎలా?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=-)(.*\n?)(?<=.)').value
ఎలా PowerShell తో Regex తో స్ట్రింగ్ ఉదాహరణకు నుండి “powershell-guru.com” తీయడం ఎలా?
$example = 'www.powershell-guru.com'
[regex]::match($example,'(?<=www.)(.*\n?)').value
ఎలా PowerShell తో Regex తో స్ట్రింగ్ ఉదాహరణకు నుండి “123” తీయడం ఎలా?
$example = 'Powershell123'
[regex]::match($example,'(\d+)').value
ఎలా PowerShell తో Regex తో స్ట్రింగ్ ఉదాహరణకు నుండి “$” (డాలర్ సైన్) సేకరించేందుకు?
$example = 'Powershell`$123'
[regex]::match($example,'(\$)').value
ఎలా మరొక తో ఒక పాత్ర (* .com) స్థానంలో (* .fr) PowerShell తో Regex ఒక స్ట్రింగ్ లో?
$example = 'www.powershell-guru.com'
[regex]::Replace($example, '.com','.fr')
ఎలా PowerShell తో Regex ఒక స్ట్రింగ్ తప్పించుకోవడానికి?
[regex]::Escape('\\server\share')
Memory
ఎలా PowerShell తో చెత్త కలెక్టర్ మెమరీ సమాహారం బలవంతం?
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
ఎలా PowerShell తో ఒక కంప్యూటర్ యొక్క RAM పరిమాణం పొందడానికి?
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
ఎలా PowerShell తో ప్రస్తుత తేదీ పొందడానికి?
Get-Date
[Datetime]::Now
ఎలా PowerShell తో వివిధ ఫార్మాట్లలో లో తేదీ ప్రదర్శించడానికి?
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 46 47 48 49 50 51 52 |
### DATETIME ### Get-Date -Format D : Tuesday, June 30, 2015 Get-Date -Format f : Tuesday, June 30, 2015 3:22 PM Get-Date -Format F : Tuesday, June 30, 2015 3:22:58 PM Get-Date -Format g : 6/30/2015 3:23 PM Get-Date -Format G : 6/30/2015 3:23:30 PM Get-Date -DisplayHint Date : Tuesday, June 30, 2015 Get-Date -DisplayHint DateTime : Tuesday, June 30, 2015 3:31:21 PM ### DATE ### Get-Date -Format d : 6/30/2015 Get-Date -Format yyyyMMdd : 20150630 Get-Date -UFormat '%d%m%Y' : 30062015 Get-Date -UFormat '%m%d%Y' : 06302015 Get-Date -UFormat '%Y%m%d' : 20150630 Get-Date -UFormat '%d.%m.%Y' : 30.06.2015 Get-Date -UFormat '%m.%d.%Y' : 06.30.2015 Get-Date -UFormat '%Y.%m.%d' : 2015.06.30 Get-Date -UFormat '%d-%m-%Y' : 30-06-2015 Get-Date -UFormat '%m-%d-%Y' : 06-30-2015 Get-Date -UFormat '%Y-%m-%d' : 2015-06-30 Get-Date -UFormat '%d/%m/%Y' : 30/06/2015 Get-Date -UFormat '%m/%d/%Y' : 06/30/2015 Get-Date -UFormat '%Y/%m/%d' : 2015/06/30 ### HOUR ### Get-Date -Format t : 3:23 PM Get-Date -Format T : 3:23:30 PM Get-Date -Format HH : 15 (Hour) Get-Date -Format mm : 28 (Minute) Get-Date -Format ss : 30 (Seconds) Get-Date -DisplayHint Time : 3:23:30 PM ### DAY ### Get-Date -Format dddd : Tuesday Get-Date -Format ddd : Tue Get-Date -Format dd : 30 ### MONTH ### Get-Date -Format MMMM : June Get-Date -Format MMM : Jun Get-Date -Format MM : 06 ### YEAR ### Get-Date -Format yyyy : 2015 |
ఎలా తేదీ PowerShell తో (స్ట్రింగ్) ఒక తేదీ (తేదీసమయం) మార్చేందుకు?
$datetimeToString = '{0:dd/MM/yy}' -f (Get-Date 30/01/2015)
$datetimeToString = (Get-Date 31/01/2015).ToShortDateString()
ఎలా తేదీ PowerShell తో (తేదీసమయం) ఒక తేదీ (స్ట్రింగ్) మార్చేందుకు?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Solution 1 $stringToDatetime = '07/15/2015' | Get-Date $stringToDatetime = '07-15-2015' | Get-Date # Solution 2 $stringToDatetime = [Datetime]::ParseExact('07/15/2015', 'MM/dd/yyyy', $null) # Solution 3 $stringToDatetime = [Datetime]"7/15/2015" # Check $stringToDatetime Wednesday, July 15, 2015 12:00:00 AM $stringToDatetime.GetType().Name Datetime |
ఎలా PowerShell తో రెండు కాలాల మధ్య (రోజులు, గంటలు, నిమిషాలు లేదా సెకన్లు సంఖ్య) తేడా లెక్కించేందుకు?
(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
ఎలా PowerShell తో రెండు తేదీలు పోల్చడానికి?
(Get-Date 2015-01-01) -lt (Get-Date 2015-01-30) # True
(Get-Date 2015-01-01) -gt (Get-Date 2015-01-30) # False
ఎలా PowerShell తో తేదీసమయం తేదీలు యొక్క ఒక అర్రే క్రమం?
$arrayDate | Sort-Object -Property {$_ -as [Datetime]}
ఎలా మొదలు మరియు PowerShell తో ఒక స్టాప్ వాచ్ ఆపడానికి?
$chrono = [Diagnostics.Stopwatch]::StartNew()
$chrono.Stop()
$chrono
ఎలా PowerShell తో వారం ప్రస్తుత రోజు పొందుటకు ఎలా?
(Get-Date).DayOfWeek #Sunday
ఎలా PowerShell తో నిన్న తేదీ పొందడానికి?
(Get-Date).AddDays(-1)
ఎలా PowerShell తో (2015 ఫిబ్రవరిలో) ఒక నెల రోజుల సంఖ్యను పొందడం ఎలా?
[DateTime]::DaysInMonth(2015, 2)
ఎలా PowerShell తో ఉంటే లీపు సంవత్సరం తెలుసు?
[DateTime]::IsLeapYear(2015)
ఎలా PowerShell తో కాలమానాలు జాబితా?
[System.TimeZoneInfo]::GetSystemTimeZones()
Networking
ఎలా (ASCII ఫార్మాట్) ఎన్ కొడ్ మరియు PowerShell తో ఒక 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 |
PowerShell తో స్థానిక నెట్వర్క్ ఆదేశాల సమానతా ఏమిటి?
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 |
ఎలా PowerShell తో IP చిరునామాలు పొందడానికి?
Get-NetIPAddress # Windows 8.1 & Windows 2012
Get-NetIPConfiguration # Windows 8.1 & Windows 2012
ఎలా PowerShell తో IP చిరునామా V6 (IPv6) డిసేబుల్?
1 |
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters' -Name 'DisabledComponents' -Value '0xFFFFFFFF' -PropertyType"DWORD" # Reboot required |
ఎలా ఒక IP చిరునామా v4 PowerShell తో (IPv4) ధ్రువీకరించడానికి?
if([ipaddress]'10.0.0.1'){'validated'}
ఎలా PowerShell తో బాహ్య 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 } |
ఎలా PowerShell తో ఒక IP చిరునామా నుండి హోస్ట్ పేరు కనుగొనేందుకు?
([System.Net.Dns]::GetHostEntry($IP)).Hostname
ఎలా PowerShell తో ఒక అతిధేయ నుండి IP చిరునామా కనుగొనేందుకు ఎలా?
([System.Net.Dns]::GetHostAddresses($computer)).IPAddressToString
ఎలా PowerShell తో ఒక అతిధేయ నుండి FQDN కనుగొనేందుకు?
[System.Net.Dns]::GetHostByName($computer).HostName
ఎలా PowerShell తో (IP, సబ్ నెట్, గేట్వే మరియు DNS) నెట్వర్క్ కాన్ఫిగరేషన్ కనుగొనేందుకు?
1 |
Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Format-Table -Property Description, IpAddress, IPSubnet, DefaultIPGateway, DNSServerSearchOrder |
ఎలా PowerShell తో MAC చిరునామా కనుగొనేందుకు ఎలా?
Get-CimInstance win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress
Get-WmiObject -Class win32_networkadapterconfiguration | Select-Object -Property Description, Macaddress
ఎలా PowerShell తో ఒక కంప్యూటర్ పింగ్?
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) |
ఒక కంప్యూటర్ PowerShell తో ఇంటర్నెట్ కనెక్ట్ ఉంటే తనిఖీ ఎలా?
1 |
[Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet |
ఎలా PowerShell తో వెబ్ సైట్ కోసం ఒక whois లుక్అప్ చేయటానికి ఎలా |?
$whois = New-WebServiceProxy 'http://www.webservicex.net/whois.asmx?WSDL'
$whois.GetWhoIs('powershell-guru.com')
ఎలా ప్రజా IP PowerShell తో (జియోలొకేషన్) యొక్క వివరాలను పొందడానికి?
1 2 |
$externalIP = (Invoke-WebRequest -Uri 'myexternalip.com/raw').Content $detailsIP = ([xml](Invoke-WebRequest -Uri "http://freegeoip.net/xml/$externalIP" -UseBasicParsing).Content).Response |
ఒక పోర్ట్ / తెరిచి ఉంది PowerShell తో మూసివేశారు ఉంటే తనిఖీ ఎలా?
New-Object -TypeName Net.Sockets.TcpClient -ArgumentList $computer, 135
ఎలా PowerShell తో tracert చేయటానికి ఎలా |?
Test-NetConnection www.google.com -TraceRoute
ఎలా PowerShell తో హోమ్ నెట్వర్క్ కనెక్షన్ ప్రొఫైల్ పరిష్కరించడానికి?
Get-NetAdapter | Format-Table -Property Name, InterfaceDescription, ifIndex -AutoSize # Windows 8.1
Set-NetConnectionProfile -InterfaceIndex 6 -NetworkCategory Private
ఎలా PowerShell తో TCP పోర్ట్ కనెక్షన్లు చూపించడానికి?
netstat.exe -ano
Get-NetTCPConnection #Windows 8 and 2012
ఎలా PowerShell తో ఒక చిన్న URL లో సుదీర్ఘ URL చిన్నదిగా?
$url = 'www.powershell-guru.com'
$tiny = Invoke-RestMethod -Uri "http://tinyurl.com/api-create.php?url=$url"
ఎలా PowerShell తో ప్రాక్సీ సెట్టింగ్లను పొందడానికి?
Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
DNS
ఎలా PowerShell తో స్థానిక కంప్యూటర్లో DNS కేచ్ తనిఖీ ఎలా?
ipconfig.exe /displaydns
Get-DnsClientCache #Windows 8 and 2012
ఎలా PowerShell తో స్థానిక కంప్యూటర్లో DNS కేచ్ క్లియర్?
ipconfig.exe /flushdns
Start-Process -FilePath ipconfig -ArgumentList /flushdns -WindowStyle Hidden
Clear-DnsClientCache #Windows 8 and 2012
ఎలా PowerShell తో రిమోట్ కంప్యూటర్లలో DNS కేచ్ క్లియర్?
Invoke-Command -ScriptBlock {Clear-DnsClientCache} -ComputerName computer01, computer02
ఎలా హోస్ట్స్ PowerShell తో దాఖలు చదవడానికి?
Get-Content -Path 'C:\Windows\system32\drivers\etc\hosts'
Password
ఎలా PowerShell తో యాదృచ్చిక పాస్వర్డ్ ను ఉత్పత్తి?
[Reflection.Assembly]::LoadWithPartialName('System.Web')
[System.Web.Security.Membership]::GeneratePassword(30,2)
ఎలా PowerShell తో రిమోట్ సర్వర్ నిర్వహణాధికారి స్థానిక పాస్వర్డ్ ను మార్చడం ఎలా?
$admin = [ADSI]('WinNT://server01/administrator,user')
$admin.SetPassword($password)
$admin.SetInfo()
ఎలా PowerShell తో యాక్టివ్ డైరెక్టరీ లో ఒక ఖాతా పాస్వర్డ్ ను గడువు తేదీ కనుగొనేందుకు?
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
ఎలా PowerShell తో ఒక నిర్దిష్ట సర్వర్ కోసం అన్ని ప్రింటర్లు జాబితా?
Get-WmiObject -Query 'Select * From Win32_Printer' -ComputerName $computer
ఎలా PowerShell తో ఒక నిర్దిష్ట సర్వర్ కోసం అన్ని పోర్ట్సు జాబితా?
Get-WmiObject -Class Win32_TCPIPPrinterPort -Namespace 'root\CIMV2' -ComputerName $computer
ఎలా PowerShell తో ఒక ప్రింటర్ వ్యాఖ్య / స్థానాన్ని మార్చడానికి?
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() |
ఎలా PowerShell తో ఒక ప్రింటర్ (అన్ని ఉద్యోగాలు రద్దు) ప్రక్షాళన?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.CancelAllJobs()
ఎలా PowerShell తో ఒక ప్రింటర్ కోసం ఒక పరీక్షా పేజీని ముద్రించు ఎలా?
$printer = Get-WmiObject -Class win32_printer -Filter "Name='HP Deskjet 2540 series'"
$printer.PrintTestPage()
ఎలా PowerShell తో ప్రింటర్ల ముద్రణ క్యూలు పొందడానికి?
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
ఎలా PowerShell తో రిజిస్ట్రీ దద్దుర్లు జాబితా?
Get-ChildItem -Path Registry::
ఎలా PowerShell తో రిజిస్ట్రీ విలువలు మరియు విలువ రకాల పొందడానికి?
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) } } } |
ఎలా PowerShell తో రిజిస్ట్రీ కీ subkeys జాబితా?
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:\' |
ఎలా PowerShell తో పునరావృత విధంగా రిజిస్ట్రీ కీ subkeys జాబితా?
Get-ChildItem -Path 'HKLM:\SYSTEM' -Recurse -ErrorAction SilentlyContinue
ఎలా PowerShell తో ఒక నిర్దిష్ట పేరు మార్గం subkeys కనుగొనేందుకు?
Get-ChildItem -Path 'HKLM:\SOFTWARE' -Include *Plugin* -Recurse -ErrorAction SilentlyContinue
ఎలా PowerShell తో రిజిస్ట్రీ subkeys యొక్క మాత్రమే పేరు తిరిగి?
(Get-ChildItem -Path 'HKLM:\SYSTEM').Name # Return HKEY_LOCAL_MACHINE\SYSTEM\ControlSet
Get-ChildItem -Path 'HKLM:\SYSTEM' -Name # Return ControlSet
ఎలా PowerShell తో రిజిస్ట్రీ విలువలు జాబితాకు?
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
ఎలా PowerShell తో ఒక నిర్దిష్ట రిజిస్ట్రీ విలువ చదవడానికి?
(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ProductName
ఎలా PowerShell తో రిమోట్ కంప్యూటర్ లో ఒక నిర్దిష్ట రిజిస్ట్రీ విలువ చదవడానికి?
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
ఎలా PowerShell తో ఒక కొత్త రిజిస్ట్రీ కీ సృష్టించడానికి?
New-Item -Path 'HKCU:\Software\MyApplication'
ఎలా PowerShell తో ఒక రిజిస్ట్రీ విలువ సృష్టించడానికి?
New-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '1.0'
ఎలా PowerShell తో ఇప్పటికే ఉన్న రిజిస్ట్రీ విలువ సవరించడానికి?
Set-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version' -Value '2.0'
Delete
ఎలా PowerShell తో ఒక రిజిస్ట్రీ విలువ తొలగించడానికి ఎలా?
Remove-ItemProperty -Path 'HKCU:\Software\MyApplication' -Name 'Version'
ఎలా PowerShell తో ఒక రిజిస్ట్రీ కీ తొలగించడానికి ఎలా?
Remove-Item -Path 'HKCU:\Software\MyApplication' -Force
Test
ఒక రిజిస్ట్రీ కీ PowerShell తో ఉందని ఎలా పరీక్షించడానికి?
Test-Path -Path 'HKCU:\Software\MyApplication'
ఒక రిజిస్ట్రీ విలువ PowerShell తో ఉందని ఎలా పరీక్షించడానికి?
(Get-Item -Path 'HKCU:\Software\MyApplication').GetValueNames() -contains 'Version'
Strings
ఎలా PowerShell తో ఒక స్ట్రింగ్ ప్రారంభంలో నుండి తెల్లని ఖాళీ అక్షరాలు తొలగించడానికి ఎలా?
$string = ' PowershellGuru'
$string = $string.TrimStart()
ఎలా PowerShell తో ఒక స్ట్రింగ్ ముగింపు నుండి తెల్లని స్థలం అక్షరాలు తొలగించడానికి ఎలా?
$string = 'PowershellGuru '
$string = $string.TrimEnd()
ఎలా PowerShell తో ఒక స్ట్రింగ్ యొక్క తెల్లని ఖాళీ అక్షరాలు (ప్రారంభం మరియు ముగింపు) తొలగించాలని?
$string = ' PowershellGuru '
$string = $string.Trim()
ఎలా PowerShell తో ఎగువ కేసు ఒక స్ట్రింగ్ మార్చడానికి?
$string = 'powershellguru'
$string = $string.ToUpper()
ఎలా PowerShell తో తక్కువ కేసు స్ట్రింగ్ మార్చడానికి?
$string = 'POWERSHELLGURU'
$string = $string.ToLower()
ఎలా PowerShell తో “PowershellGuru” స్ట్రింగ్ యొక్క substring “PowerShell” ఎంచుకోండి ఎలా?
$string.Substring(0,10)
ఎలా PowerShell తో “PowershellGuru” స్ట్రింగ్ యొక్క substring “గురు” ఎంచుకోండి ఎలా?
$string.Substring(10)
ఎలా PowerShell తో “Powershell123Guru” సంఖ్య “123” ఎంచుకోండి ఎలా?
$string = 'Powershell123Guru'
[regex]::match($string,'(\d+)').value
ఎలా PowerShell తో స్ట్రింగ్ “PowershellGuru” యొక్క “గురు” సున్నా ఆధారిత ఇండెక్స్ పొందడానికి?
$string.IndexOf('Guru') # 10
ఎలా ఒక స్ట్రింగ్ PowerShell తో శూన్యం లేదా ఖాళీగా ఉంటే తనిఖీ ఎలా?
$string = $null
$string = ''
[string]::IsNullOrEmpty($string)
ఒక స్ట్రింగ్ శూన్య, ఖాళీ, లేదా మాత్రమే PowerShell తో తెల్లని ఖాళీ పాత్రలను కలిగి ఉంటే తనిఖీ ఎలా?
$string = $null
$string = ''
$string = ' '
[string]::IsNullOrWhiteSpace($string)
ఒక స్ట్రింగ్ PowerShell తో ఒక నిర్దిష్ట లేఖ కలిగి ఉంటే తనిఖీ ఎలా?
$string = 'PowershellGuru'
$string.Contains('s')
[regex]::match($string,'s').Success
ఎలా PowerShell తో ఒక స్ట్రింగ్ యొక్క పొడవు తిరిగి ఎలా?
$string.Length
ఎలా PowerShell తో రెండు స్ట్రింగ్ concatenate కు?
1 2 3 4 5 6 7 |
# Solution 1 $string1 + $string2 # Solution 2 $string1 = 'Powershell' $string2 = 'Guru' [string]::Concat($string1,$string2) |
ఎలా “[]” ఒకటి లేదా అనేక పరిధులు కోసం మ్యాచ్ PowerShell తో ఒక స్ట్రింగ్ లో?
$string = '[PowershellGuru]'
$string -match '\[' # Only 1
$string -match '\[(.*)\]' # Several
ఎలా “()” PowerShell తో ఒక స్ట్రింగ్ లో ఒకటి లేదా అనేక వాక్యాల కోసం మ్యాచ్?
$string = '(PowershellGuru)'
$string -match '\(' # Only 1
$string -match '\((.*)\)' # Several
ఎలా “{}” PowerShell తో ఒక స్ట్రింగ్ లో ఒకటి లేదా ఎక్కువ కర్లీ బ్రాకెట్స్ కోసం మ్యాచ్?
$string = '{PowershellGuru}'
$string -match '\{' # Only 1
$string -match '\{(.*)\}' # Several
ఒకటి లేదా అనేక బ్రాకెట్లు కోసం సరిపోలడం ఎలా “; & gt; & lt” PowerShell తో ఒక స్ట్రింగ్ లో?
$string = ''
$string -match '\<' # Only 1
$string -match "\<(.*)\>" # Several
ఎలా PowerShell తో ఒక స్ట్రింగ్ లో ఏ చిన్న అక్షరాలు (ABC) మ్యాచ్?
$string = 'POWERSHELLGURU'
$string -cmatch "^[a-z]*$" #False
ఎలా PowerShell తో ఒక స్ట్రింగ్ లో ఏ upperletters (ABC) మ్యాచ్?
$string = 'powershellguru'
$string -cmatch "^[A-Z]*$" #False
ఎలా PowerShell తో ఒక స్ట్రింగ్ లో “[p” (p తక్కువ కేసు) మ్యాచ్?
$string = '[powershellGuru]'
$string -cmatch '\[[a-z]\w+' #True
ఎలా PowerShell తో ఒక స్ట్రింగ్ లో “[P” (పి అప్పర్ కేస్) మ్యాచ్?
$string = '[PowershellGuru]'
$string -cmatch '\[[A-Z]\w+' #True
ఎలా PowerShell తో మరొక లైన్ తో లైన్ భర్తీ ఎలా?
$a = 'Line A'
$b = 'Line B'
$a = $a -replace $a, $b
ఎలా PowerShell తో ఒక స్ట్రింగ్ (శాతం) ఒక విభజన ఆపరేషన్ మార్చేందుకు?
(1/2).ToString('P')
ఎలా PowerShell తో సంఖ్యలు తీగలను కలిగి క్రమం?
1 |
'string-10', 'string-2', 'string-23', 'string-30' | Sort-Object -Property {$_ -replace '[\d]'}, {$_ -replace '[a-zA-Z\p{P}]'-as [int]} |
ఎలా PowerShell తో ఒక వాక్యం యొక్క చివరి పదం ఎంచుకోవడానికి?
$sentence = 'My name is Test Powershell'
$sentence.Split(' ')[-1] # Returns Powershell
ఎలా PowerShell తో వాక్యం యొక్క అతిపెద్ద పదం పొందడానికి?
$sentence = 'My name is Test Powershell'
$sentence.Split(' ') | Sort-Object -Property Length | Select-Object -Last 1 # Returns Powershell
ఎలా ఒక స్ట్రింగ్ PowerShell తో ఒక వాక్యం లోపల ఉంది ఎన్నిసార్లు లెక్కించడానికి?
$sentence = 'test test test Powershell'
[regex]::Matches($sentence, 'test').Count # Returns 3
ఎలా PowerShell తో ఒక పాత్ర శ్రేణి ఒక స్ట్రింగ్ లో ప్రతి పాత్ర కాపీ?
1 2 3 4 5 6 7 |
$name = 'test' $name.ToCharArray() s t e v e |
ఎలా PowerShell తో ఒక స్ట్రింగ్ యొక్క అప్పర్ కేస్ మొదటి అక్షరం మార్చేందుకు?
1 2 |
$name = 'test' $name.Substring(0,1).ToUpper() + $name.Substring(1) |
ఎలా ప్యాడ్ (ఎడమ లేదా కుడి) PowerShell తో ఒక స్ట్రింగ్?
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 |
ఎలా ఎన్కోడ్ మరియు PowerShell తో నివేదించండి Base64- ఒక స్ట్రింగ్ డీకోడ్?
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 |
ఎలా బైనరీ మరియు PowerShell తో బైనరీ నుండి సంఖ్య మార్చేందుకు?
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) |
ఎలా PowerShell తో ఒక మార్గంలో మాత్రమే గత పేరెంట్ ఫోల్డర్ తిరిగి?
1 2 |
$path = 'C:\Folder1\Folder2\Folder3\file.txt' Split-Path -Path (Split-Path -Path $path -Parent) -Leaf # Return Folder3 |
ఎలా PowerShell తో ఒక మార్గంలో మాత్రమే గత అంశాన్ని తిరిగి?
1 2 |
$path = 'C:\Folder1\Folder2\Folder3\file.txt' Split-Path -Path $path -Leaf # Return file.txt |
Math
ఎలా PowerShell తో System.Math తరగతి పద్ధతులు జాబితా?
[System.Math] | Get-Member -Static -MemberType Method
ఎలా PowerShell తో సంపూర్ణ విలువ తిరిగి?
[Math]::Abs(-12) #Returns 12
[Math]::Abs(-12.5) # Returns 12.5
ఎలా దీని సైన్ PowerShell తో పేర్కొన్న సంఖ్య కోణం తిరిగి?
[Math]::ASin(1) #Returns 1,5707963267949
ఎలా PowerShell తో పైకప్పు తిరిగి?
[Math]::Ceiling(1.4) #Returns 2
[Math]::Ceiling(1.9) #Returns 2
ఎలా PowerShell తో ఫ్లోర్ తిరిగి?
[Math]::Floor(1.4) #Returns 1
[Math]::Floor(1.9) #Returns 1
ఎలా PowerShell తో ఒక నిర్దిష్ట సహజ (బేస్ ఈ) సంవర్గమానం తిరిగి?
[Math]::Log(4) #Returns 1,38629436111989
ఎలా PowerShell తో ఒక పేర్కొన్న సంఖ్యలో బేస్ 10 సంవర్గమానం తిరిగి?
[Math]::Log10(4) #Returns 0,602059991327962
ఎలా PowerShell తో రెండు విలువలు గరిష్ట తిరిగి?
[Math]::Max(2,4) #Returns 4
[Math]::Max(-2,-4) #Returns -2
ఎలా PowerShell తో రెండు విలువలు కనీస తిరిగి?
[Math]::Min(2,4) #Returns 2
[Math]::Max(-2,-4) #Returns -4
ఎలా PowerShell తో పేర్కొన్న ఘాతానికి ఒక సంఖ్య తిరిగి?
[Math]::Pow(2,4) #Returns 16
ఎలా PowerShell తో సమీప సమగ్ర విలువ ఒక దశాంశ విలువ తిరిగి?
[Math]::Round(3.111,2) #Returns 3,11
[Math]::Round(3.999,2) #Returns 4
ఎలా PowerShell తో ఒక పేర్కొన్న దశాంశ సంఖ్య యొక్క అంతర్భాగం తిరిగి?
[Math]::Truncate(3.111) #Returns 3
[Math]::Truncate(3.999) #Returns 3
ఎలా PowerShell తో ఒక పేర్కొన్న సంఖ్య యొక్క వర్గమూలం తిరిగి?
[Math]::Sqrt(16) #Returns 4
ఎలా PowerShell తో PI స్థిరంగా తిరిగి?
[Math]::Pi #Returns 3,14159265358979
ఎలా PowerShell తో సహజ సంవర్గమాన బేస్ (స్థిరాంకం e) తిరిగి?
[Math]::E #Returns 2,71828182845905
ఎలా అనేక సరి లేదా బేసి PowerShell తో ఉంటే తనిఖీ ఎలా?
[bool]($number%2)
Hashtables
ఎలా PowerShell తో ఒక ఖాళీ హేష్ టెబుల్ సృష్టించడానికి?
$hashtable = @{}
$hashtable = New-Object -TypeName System.Collections.Hashtable
ఎలా PowerShell తో అంశాలను ఒక హేష్ టెబుల్ సృష్టించడానికి?
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 |
ఎలా PowerShell తో ఒక హేష్ టెబుల్ అంశాలు (కీ-విలువ జంట) జోడించడానికి?
$hashtable.Add('Key3', 'Value3')
ఎలా PowerShell తో ఒక హేష్ టెబుల్ ఒక నిర్దిష్ట విలువ పొందడానికి?
$hashtable.Key1
$hashtable.Get_Item('Key1')
ఎలా PowerShell తో ఒక హేష్ టెబుల్ కనీస విలువ పొందడానికి?
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 |
ఎలా PowerShell తో ఒక హేష్ టెబుల్ యొక్క గరిష్ట విలువ పొందడానికి?
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 |
ఎలా PowerShell తో ఒక హేష్ టెబుల్ అంశాలను సవరించడానికి?
$hashtable.Set_Item('Key1', 'Value1Updated')
ఎలా PowerShell తో ఒక హేష్ టెబుల్ అంశాలను తొలగించడానికి ఎలా?
$hashtable.Remove('Key1')
ఎలా PowerShell తో ఒక హేష్ టెబుల్ క్లియర్?
$hashtable.Clear()
ఎలా PowerShell తో ఒక హేష్ టెబుల్ ఒక నిర్దిష్ట కీ / విలువ ఉనికిని తనిఖీ ఎలా?
$hashtable.ContainsKey('Key3')
$hashtable.ContainsValue('Value3')
ఎలా PowerShell తో ఒక హేష్ టెబుల్ కీ / విలువ క్రమం?
$hashtable.GetEnumerator() | Sort-Object -Property Name
$hashtable.GetEnumerator() | Sort-Object -Property Value -Descending
Arrays
ఎలా PowerShell తో ఒక ఖాళీ శ్రేణిని సృష్టించడానికి?
$array = @()
$array = [System.Collections.ArrayList]@()
ఎలా PowerShell తో వస్తువులను వ్యూహం సృష్టించడానికి?
$array = @('A', 'B', 'C')
$array = 'A', 'B', 'C'
$array = 'a,b,c'.Split(',')
$array = .{$args} a b c
$array = echo a b c
ఎలా PowerShell తో వ్యూహం అంశాలను జోడించాలి?
$array += 'D'
[void]$array.Add('D')
ఎలా PowerShell తో ఒక శ్రేణి ఒక అంశం సవరించడానికి?
$array[0] = 'Z' # 1st item[0]
ఎలా PowerShell తో వ్యూహం యొక్క పరిమాణం తనిఖీ ఎలా?
$array = 'A', 'B', 'C'
$array.Length # Returns 3
ఎలా PowerShell తో ఒక శ్రేణి లో ఒక అంశం / కొన్ని / అన్ని అంశాలను తిరిగి?
$array = @('A', 'B', 'C')
$array[0] # One item (A)
$array[0] + $array[2] # Several items (A,C)
$array # All items (A,B,C)
ఎలా PowerShell తో ఒక శ్రేణి ఖాళీ అంశాలను తొలగించడానికి ఎలా?
$array = @('A', 'B', 'C', '')
$array = $array.Split('',[System.StringSplitOptions]::RemoveEmptyEntries) | Sort-Object # A,B,C
ఒక అంశం PowerShell తో ఒక శ్రేణి లో ఉనికిలో ఉంటే తనిఖీ ఎలా?
$array = @('A', 'B', 'C')
'A' | ForEach-Object -Process {$array.Contains($_)} # Returns True
'D' | ForEach-Object -Process {$array.Contains($_)} # Returns False
ఎలా PowerShell తో ఒక శ్రేణి ఒక అంశం ఇండెక్స్ సంఖ్య కనుగొనేందుకు?
$array = @('A', 'B', 'C')
[array]::IndexOf($array,'A') # Returns 0
ఎలా PowerShell తో ఒక శ్రేణి అంశాలను క్రమాన్ని రివర్స్?
$array = @('A', 'B', 'C')
[array]::Reverse($array) # C,B,A
ఎలా PowerShell తో వ్యూహం నుండి రాండమ్ అంశం ఉత్పత్తి?
$array | Get-Random
ఎలా PowerShell తో మార్గం అవరోహణ / ఆరోహణ ఒక అర్రే క్రమం?
$array = @('A', 'B', 'C')
$array | Sort-Object # A,B,C
$array | Sort-Object -Descending # C,B,A
ఎలా PowerShell తో వ్యూహంలో అంశాల సంఖ్యను లెక్కించడానికి?
$array.Count
ఎలా PowerShell తో antoher కు వ్యూహం జోడించడానికి?
$array1 = 'A', 'B', 'C'
$array2 = 'D', 'E', 'F'
$array3 = $array1 + $array2 # A,B,C,D,E,F
ఎలా PowerShell తో వ్యూహం నుండి నకిలీలను కనుగొనడంలో?
$array = 'A', 'B', 'C', 'C'
($array | Group-Object | Where-Object -FilterScript {$_.Count -gt 1}).Values # Returns C
ఎలా PowerShell తో వ్యూహం నుండి నకిలీలను తొలగించడానికి ఎలా?
$array = 'A', 'B', 'C', 'C'
$array = $array | Select-Object -Unique
$array # Returns A,B,C
ఎలా ఒక ఉపసర్గ తో మొదలు (“user01”, “user02”, …, “user10”) PowerShell తో వస్తువులను వ్యూహం సృష్టించడానికి?
$array = 1..10 | ForEach-Object -Process { "user$_" }
ACL
ఎలా PowerShell తో ఒక యూజర్ యొక్క ACL జాబితా?
(Get-Acl -Path "AD:\$dn").Access