ਧਾਰਨਾ : PowerShell ਬਾਰੇ ਅਕਸਰ ਪੁੱਛੇ ਜਾਣ ਵਾਲੇ ਸਵਾਲ
ਤੁਹਾਨੂੰ ਵੱਖ-ਵੱਖ ਢੰਗ ਨਾਲ ਇਸ ਸੂਚੀ ਨੂੰ ਵਰਤ ਸਕਦੇ ਹੋ :
- ਇੱਕ ਸਕਰਿਪਟ ਕਮਾਂਡਸ ਨੂੰ ਕਾਪੀ /ਪੇਸਟ ਕਰਨ ਲਈ
- ਕਿਸੇ ਖ਼ਾਸ ਕਮਾਂਡ ਦਾ ਸਿਨਟੈਕਸ ਦੇਖਣ ਲਈ
- ਆਪਣੇ ਤਕਨੀਕੀ ਗਿਆਨ ਵਿੱਚ ਸੁਧਾਰ ਕਰਨ ਲਈ
- ਨਵੀਆਂ ਕਮਾਂਡਸ ਦੇਖਣ ਲਈ
- ਇੱਕ ਨੌਕਰੀ ਦੀ ਇੰਟਰਵਿਊ ਦੀ ਤਿਆਰੀ ਕਰਨ ਲਈ
ਅੱਪਡੇਟ ਕੀਤਾ ਗਿਆ |
2015/28/06
|
ਲੇਖਕ | powershell-guru.com |
ਸਰੋਤ | punjabi-eastern.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 ਨਾਲ ਇੱਕ Windows Explorer ਨੂੰ ਕਿਵੇਂ ਖੋਲ੍ਹਿਆ ਜਾਂਦਾ ਹੈ?
[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 Framework Version 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 (ਗਲੋਬਲ ਅਸੈਮਬਲੀ ਕੈਸ਼ੇ) ਦਾ ਪਾਥ ਕਿਵੇਂ ਪਤਾ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਦੇ ਨਾਲ Pagefile ਜਾਣਕਾਰੀ ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤੀ ਜਾਂਦੀ ਹੈ?
Get-WmiObject -Class Win32_PageFileusage | Select-Object -Property Name, CurrentUsage, AllocatedBaseSize, PeakUsage, InstallDate
PowerShell ਦੇ ਨਾਲ Pagefile ਲਈ ਸਿਫਾਰਸ਼ੀ ਆਕਾਰ (MB) ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤੀ ਜਾਂਦਾ ਹੈ?
[Math]::Truncate(((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory) / 1MB) * 1.5
PowerShell ਦੇ ਨਾਲ (D:) ਡ੍ਰਾਇਵ ਉੱਤੇ Pagefile(4096 MB) ਕਿਵੇਂ ਬਣਾਈ ਜਾਂਦੀ ਹੈ?
1 2 3 4 5 |
Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{ Name = 'D:\pagefile.sys' InitialSize = 4096 MaximumSize = 4096 } |
PowerShell ਦੇ ਨਾਲ (C:) ਡ੍ਰਾਇਵ ਉੱਤੇ Pagefile ਕਿਵੇਂ ਮਿਟਾਈ ਜਾਂਦੀ ਹੈ?
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 ਦੇ ਨਾਲ ਮੌਜੂਦਾ ਸਕਰਿਪਟ ਫ਼ਾਈਲ ਦਾ fullname (ਪੂਰਾ ਨਾਮ) ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$MyInvocation.MyCommand.Path
PowerShell ਦੇ ਨਾਲ ਫਾਈਲਾਂ ਨੂੰ ਕੰਪ੍ਰੈਸ/ ਜ਼ਿਪ ਕਿਵੇਂ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ZIP ਆਰ੍ਕਾਇਵ ਵਿੱਚ ਫਾਈਲਾਂ ਨੂੰ ਕਿਵੇਂ ਦੇਖਿਆ ਜਾਂਦਾ ਹੈ?
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 |
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 |
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 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 ਨਾਲ ਐਕਟਿਵ ਡਾਇਰੈਕਟਰੀ ਵਿੱਚ “ਹਟਾਏ ਗਏ ਔਬਜੈਕਟ” ਕੰਨਟੇਨਰ ਦੇ ਪਾਥ ਨੂੰ ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
(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 ਨਾਲ ਐਕਟਿਵ ਡਾਇਰੈਕਟਰੀ ਵਿੱਚ ਰੀਸਾਈਕਲ ਬਿਨ ਵਿਚੋਂ ਇੱਕ AD ਖਾਤੇ ਨੂੰ ਕਿਵੇਂ ਮੁੜ ਬਹਾਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ਮੌਜੂਦਾ logon ਸਰਵਰ ਨੂੰ ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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' |
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 ਨਾਲ ਐਕਟਿਵ ਡਾਇਰੈਕਟਰੀ ਵਿੱਚ “Get-ADUser” ਦੇ ਫਿਲਟਰ ਵਿੱਚ ਇੱਕ wildcard ਕਿਵੇਂ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ਇੱਕ ਯੂਜ਼ਰ ਦੇ ਲਈ ਸਭ ਸਦੱਸਾਂ ਨੂੰ (ਨੈਸਟਡ) ਕਿਵੇਂ ਲੱਭਿਆ ਜਾਂਦਾ ਹੈ?
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($dn))"
PowerShell ਨਾਲ ਇੱਕ ਯੂਜ਼ਰ ਲਈ ਸਦੱਸਾਂ ਨੂੰ ਕਿਵੇਂ (ਛੋਟਾ ਨਾਮ/ ਕੱਟਿਆ ਹੋਇਆ) ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
(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 ਨਾਲ ਐਕਟਿਵ ਡਾਇਰੈਕਟਰੀ ਵਿੱਚ ਇੱਕ ਯੂਜ਼ਰ ਲਈ 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 ਨਾਲ ਐਕਟਿਵ ਡਾਇਰੈਕਟਰੀ ਵਿੱਚ ਇੱਕ ਯੂਜ਼ਰ ਲਈ 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] |
1 2 |
$dn = (Get-ADUser $user -Properties DistinguishedName).DistinguishedName $owner = (Get-Acl -Path "AD:$dn").Owner |
PowerShell ਨਾਲ ਐਕਟਿਵ ਡਾਇਰੈਕਟਰੀ ਨਾਲ ਇੱਕ ਯੂਜ਼ਰ ਲਈ 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 |
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 ਨਾਲ ਖਾਲੀ ਔਰਗਨੈਜੇਸ਼ਨਲ ਯੂਨਿਟ (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 } |
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
PowerShell ਦੇ ਨਾਲ “-” Regex ਨਾਲ ਵੱਖਰੇ ਕੀਤੇ ਗਏ 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
PowerShell ਦੇ ਨਾਲ “:” Regex ਨਾਲ ਵੱਖਰੇ ਕੀਤੇ ਗਏ 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
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 ਨਾਲ ਸਟ੍ਰਿੰਗ ਉਦਾਹਰਨ ਵਿੱਚੋਂ “guru” ਨੂੰ ਕਿਵੇਂ ਐਕਸਟਰੈਕਟ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$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
PowerShell ਨਾਲ regex ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ ਕਿਸੇ ਅੱਖਰ (* .com) ਨੂੰ ਕਿਸੇ ਹੋਰ (* .fr) ਵਿੱਚ ਕਿਵੇਂ ਤਬਦੀਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$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 ਨਾਲ ਕਿਸੇ ਮਿਤੀ (Datetime)ਨੂੰ ਮਿਤੀ (String) ਵਿੱਚ ਤਬਦੀਲ ਕਿਵੇਂ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$datetimeToString = '{0:dd/MM/yy}' -f (Get-Date 30/01/2015)
$datetimeToString = (Get-Date 31/01/2015).ToShortDateString()
PowerShell ਨਾਲ ਕਿਸੇ ਮਿਤੀ (String) ਨੂੰ ਮਿਤੀ (Datetime)ਵਿੱਚ ਤਬਦੀਲ ਕਿਵੇਂ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ Datetime ਦੇ ਐਰੇ ਨੂੰ ਸੌਰਟ ਕਿਵੇਂ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$arrayDate | Sort-Object -Property {$_ -as [Datetime]}
PowerShell ਨਾਲ ਇੱਕ stopwatch ਨੂੰ ਕਿਵੇਂ ਚਾਲੂ ਜਾਂ ਬੰਦ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$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
PowerShell ਨਾਲ URL ਨੂੰ ਕਿਵੇਂ ਇਨਕੋਡ ਅਤੇ ਡੀਕੋਡ (ASCII ਫਾਰਮੈਟ ਵਿੱਚ) ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ਨੇਟਿਵ ਨੈੱਟਵਰਕ ਕਮਾਂਡਸ ਦੇ equivalents ਕੀ ਹਨ?
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 ਐਡਰੈੱਸ V-6 (IPv6) ਨੂੰ ਕਿਵੇਂ ਅਯੋਗ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
1 |
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters' -Name 'DisabledComponents' -Value '0xFFFFFFFF' -PropertyType"DWORD" # Reboot required |
PowerShell ਨਾਲ ਇੱਕ IP ਐਡਰੈੱਸ V4(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')
PowerShell ਨਾਲ ਪਬਲਿਕ IP (ਭੂਗੋਲਿਕ) ਦੇ ਵੇਰਵੇ ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤੇ ਜਾਂਦੇ ਹਨ?
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()
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 ਨਾਲ ਰਜਿਸਟਰੀ ਕੀਅ ਸਬਕੀਜ਼ ਨੂੰ ਕਿਵੇਂ ਸੂਚੀਬੱਧ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ਰਜਿਸਟਰੀ ਕੀਅ ਸਬਕੀਜ਼ ਨੂੰ ਲਗਾਤਾਰ ਕਿਵੇਂ ਸੂਚੀਬੱਧ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
Get-ChildItem -Path 'HKLM:\SYSTEM' -Recurse -ErrorAction SilentlyContinue
PowerShell ਦੇ ਨਾਲ ਇੱਕ ਖਾਸ ਨਾਮ ਦੇ ਨਾਲ ਸਬਕੀਜ਼ ਕਿਵੇਂ ਲੱਭਿਆ ਜਾਂਦਾ ਹੈ?
Get-ChildItem -Path 'HKLM:\SOFTWARE' -Include *Plugin* -Recurse -ErrorAction SilentlyContinue
PowerShell ਨਾਲ ਸਿਰਫ ਰਜਿਸਟਰੀ ਸਬਕੀਜ਼ ਦੇ ਨਾਮ ਕਿਵੇਂ ਵਾਪਿਸ ਪ੍ਰਾਪਤ ਕੀਤੇ ਜਾਂਦੇ ਹਨ?
(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” ਸਟ੍ਰਿੰਗ ਵਿੱਚ “PowerShell” ਸਬਸਟ੍ਰਿੰਗ ਨੂੰ ਕਿਵੇਂ ਚੁਣਿਆ ਜਾਂਦਾ ਹੈ?
$string.Substring(0,10)
PowerShell ਨਾਲ “PowershellGuru” ਸਟ੍ਰਿੰਗ ਵਿੱਚ “Guru” ਸਬਸਟ੍ਰਿੰਗ ਨੂੰ ਕਿਵੇਂ ਚੁਣਿਆ ਜਾਂਦਾ ਹੈ?
$string.Substring(10)
PowerShell ਨਾਲ “PowershellGuru” ਸਟ੍ਰਿੰਗ ਵਿੱਚ “123” ਨੰਬਰ ਨੂੰ ਕਿਵੇਂ ਚੁਣਿਆ ਜਾਂਦਾ ਹੈ?
$string = 'Powershell123Guru'
[regex]::match($string,'(\d+)').value
PowerShell ਨਾਲ ਸਟ੍ਰਿੰਗ “PowershellGuru” ਦੀ “Guru” ਦੇ ਜ਼ੀਰੋ-ਅਧਾਰਿਤ ਇੰਡੈਕਸ ਨੂੰ ਕਿਵੇਂ ਪ੍ਰਾਪਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string.IndexOf('Guru') # 10
PowerShell ਨਾਲ ਕਿਸੇ ਇੱਕ ਸਟ੍ਰਿੰਗ ਦਾ NULL ਜਾਂ ਖਾਲੀ ਹੋਣਾ ਕਿਵੇਂ ਚੈੱਕ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = $null
$string = ''
[string]::IsNullOrEmpty($string)
PowerShell ਦੇ ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਦਾ NULL ਹੋਣਾ, ਖਾਲੀ, ਜਾਂ ਵਾਈਟ-ਸਪੇਸ ਅੱਖਰ ਹੋਣਾ ਕਿਵੇਂ ਚੈੱਕ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = $null
$string = ''
$string = ' '
[string]::IsNullOrWhiteSpace($string)
PowerShell ਦੇ ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ ਖਾਸ ਅੱਖਰ ਸ਼ਾਮਿਲ ਹਨ, ਇਸਨੂੰ ਕਿਵੇਂ ਚੈੱਕ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = 'PowershellGuru'
$string.Contains('s')
[regex]::match($string,'s').Success
PowerShell ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਦੀ ਲੰਬਾਈ ਨੂੰ ਕਿਵੇਂ ਵਾਪਸ ਕਲਿਆ ਜਾਂਦਾ ਹੈ?
$string.Length
PowerShell ਦੇ ਨਾਲ ਦੋ ਸਟ੍ਰਿੰਗਸ ਨੂੰ ਜੋੜਿਆ ਕਿਵੇਂ ਜਾਂਦਾ ਹੈ?
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
PowerShell ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ ਇੱਕ ਜਾਂ ਕਈ ਐਂਗਲ ਬਰੈਕਟਾਂ “< >” ਨੂੰ ਕਿਵੇਂ ਮੈਚ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = ''
$string -match '\<' # Only 1
$string -match "\<(.*)\>" # Several
PowerShell ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ lowercase letters (abc) ਨੂੰ ਕਿਵੇਂ ਮੈਚ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = 'POWERSHELLGURU'
$string -cmatch "^[a-z]*$" #False
PowerShell ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ upperletters (ABC) ਨੂੰ ਕਿਵੇਂ ਮੈਚ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = 'powershellguru'
$string -cmatch "^[A-Z]*$" #False
PowerShell ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ “[p” (p lower case) ਨੂੰ ਕਿਵੇਂ ਮੈਚ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$string = '[powershellGuru]'
$string -cmatch '\[[a-z]\w+' #True
PowerShell ਨਾਲ ਇੱਕ ਸਟ੍ਰਿੰਗ ਵਿੱਚ “[P” (P upper case) ਨੂੰ ਕਿਵੇਂ ਮੈਚ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$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 ਦੇ ਨਾਲ, ਇੱਕ ਸਟ੍ਰਿੰਗ ਪਹਿਲੇ ਅਖਰ ਨੂੰ uppercase ਵਿੱਚ ਕਿਵੇਂ ਤਬਦੀਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ਕਿਸੇ ਨਿਰਧਾਰਤ ਨੰਬਰ ਦੇ sine ਨੂੰ ਕਿਵੇਂ ਵਾਪਿਸ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
[Math]::ASin(1) #Returns 1,5707963267949
PowerShell ਨਾਲ ceiling ਨੂੰ ਕਿਵੇਂ ਵਾਪਿਸ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
[Math]::Ceiling(1.4) #Returns 2
[Math]::Ceiling(1.9) #Returns 2
PowerShell ਨਾਲ floor ਤੇ ਕਿਵੇਂ ਵਾਪਿਸ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
[Math]::Floor(1.4) #Returns 1
[Math]::Floor(1.9) #Returns 1
PowerShell ਦੇ ਨਾਲ ਇੱਕ ਖਾਸ ਨੰਬਰ ਦੇ ਨੈਚੁਰਲ (ਬੇਸ E) ਲੌਗਾਰਿਥਮ ਨੂੰ ਕਿਵੇਂ ਵਾਪਿਸ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
[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' } |
PowerShell ਨਾਲ ਕੀਜ਼/ਨਾਮ ਨਾਲ ਸੌਰਟ ਕੀਤੇ ਆਈਟਮ ਦੇ ਹੈਸ਼ਟੇਬਲ ਨੂੰ ਕਿਵੇਂ ਬਣਾਇਆ ਜਾਂਦਾ ਹੈ?
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 ਨਾਲ ਇੱਕ ਐਰੇ ਨੂੰ ਦੂਜੇ ਵਿੱਚ ਕਿਵੇਂ ਸ਼ਾਮਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ?
$array1 = 'A', 'B', 'C'
$array2 = 'D', 'E', 'F'
$array3 = $array1