PowerShell w ćwiczeniach – korzystanie z pomocy

PowerShell korzystanie z pomocy

#Ćwiczenie 1 – aktualizacja pomocy

PS C:\Users\Admin> Get-Command -Noun Help

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-Help                                           7.5.0.500  Microsoft.PowerShell.Core
Cmdlet          Save-Help                                          7.5.0.500  Microsoft.PowerShell.Core
Cmdlet          Update-Help                                        7.5.0.500  Microsoft.PowerShell.Core
PS C:\Users\Admin> Update-Help
Update-Help : Failed to update Help for the module(s) :
'ActiveDirectory, AppBackgroundTask, AppLocker, AppvClient, Appx, AssignedAccess, BestPractices, BitLocker, BitsTransfe
r, BranchCache, CimCmdlets, ConfigCI, Defender, DefenderPerformance, DeliveryOptimization, DirectAccessClientComponents
, Dism, DnsClient, DnsServer, EventTracingManagement, HgsClient, HgsDiagnostics, HostNetworkingService, Hyper-V, Intern
ational, iSCSI, IscsiTarget, ISE, Kds, LanguagePackManagement, LAPS, Microsoft.PowerShell.Archive, Microsoft.PowerShell
.Core, Microsoft.PowerShell.Diagnostics, Microsoft.PowerShell.Host, Microsoft.PowerShell.LocalAccounts, Microsoft.Power
Shell.Management, Microsoft.PowerShell.ODataUtils, Microsoft.PowerShell.Security, Microsoft.PowerShell.Utility, Microso
ft.ReFsDedup.Commands, Microsoft.Windows.Bcd.Cmdlets, Microsoft.WSMan.Management, MMAgent, MsDtc, NetAdapter, NetConnec
tion, NetEventPacketCapture, NetLbfo, NetNat, NetQos, NetSecurity, NetSwitchTeam, NetTCPIP, NetworkConnectivityStatus,
NetworkSwitchManager, NetworkTransition, NFS, OsConfiguration, PackageManagement, PcsvDevice, PersistentMemory, PKI, Pn
pDevice, PowerShellGet, PrintManagement, ProcessMitigations, Provisioning, PSDesiredStateConfiguration, PSDiagnostics,
PSReadLine, PSScheduledJob, PSWorkflow, PSWorkflowUtility, RemoteDesktop, ScheduledTasks, SecureBoot, ServerManager, Se
rverManagerTasks, SmbShare, SmbWitness, StartLayout, Storage, StorageBusCache, TLS, TroubleshootingPack, TrustedPlatfor
mModule, UEV, VMDirectStorage, VpnClient, Wdac, Whea, WindowsDeveloperLicense, WindowsErrorReporting, WindowsSearch, Wi
ndowsUpdate, WinHttpProxy'
Access is denied. The command could not update Help topics for the Windows PowerShell core modules, or for any modules
in the $pshome\Modules directory. To update these Help topics, start Windows PowerShell by using the "Run as Administra
tor" command, and try running Update-Help again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UpdatableHelpSystemRequiresElevation,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'ConfigDefender, ConfigDefenderPerformance' with UI culture(s) {p
l-PL} : Unable to retrieve the HelpInfo XML file for UI culture pl-PL. Make sure the HelpInfoUri property in the module
 manifest is valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand

PS C:\WINDOWS\system32> Update-Help
Update-Help : Failed to update Help for the module(s) 'ConfigDefender, ConfigDefenderPerformance' with UI culture(s) {p
l-PL} : Unable to retrieve the HelpInfo XML file for UI culture pl-PL. Make sure the HelpInfoUri property in the module
 manifest is valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand

# Ćwiczenie 2 – pokaż plik pomocy dla cmdletu Get-Localuser

PS C:\Users\Admin> Get-Help Get-LocalUser

NAME
    Get-LocalUser

SYNOPSIS
    Gets local user accounts.


SYNTAX
    Get-LocalUser [[-Name] <System.String[]>] [<CommonParameters>]

    Get-LocalUser [[-SID] <System.Security.Principal.SecurityIdentifier[]>] [<CommonParameters>]


DESCRIPTION
    The `Get-LocalUser` cmdlet gets local user accounts. This cmdlet gets default built-in user accounts, local user ac
    counts that you created, and local accounts that you connected to Microsoft accounts.

    > [!NOTE] > The Microsoft.PowerShell.LocalAccounts module is not available in 32-bit PowerShell on a 64-bit > syste
    m.


RELATED LINKS
    Online Version: https://learn.microsoft.com/powershell/module/microsoft.powershell.localaccounts/get-localuser?view
    =powershell-5.1&WT.mc_id=ps-gethelp
    Disable-LocalUser
    Enable-LocalUser
    New-LocalUser
    Remove-LocalUser
    Rename-LocalUser
    Set-LocalUser

REMARKS
    To see the examples, type: "get-help Get-LocalUser -examples".
    For more information, type: "get-help Get-LocalUser -detailed".
    For technical information, type: "get-help Get-LocalUser -full".
    For online help, type: "get-help Get-LocalUser -online"

Teraz dla przykładu to samo polecenie, ale uzupełnione o parametr -Full.

PS C:\Users\Admin> Get-Help Get-LocalUser -Full

NAME
    Get-LocalUser

SYNOPSIS
    Gets local user accounts.


SYNTAX
    Get-LocalUser [[-Name] <System.String[]>] [<CommonParameters>]

    Get-LocalUser [[-SID] <System.Security.Principal.SecurityIdentifier[]>] [<CommonParameters>]


DESCRIPTION
    The `Get-LocalUser` cmdlet gets local user accounts. This cmdlet gets default built-in user accounts, local user ac
    counts that you created, and local accounts that you connected to Microsoft accounts.

    > [!NOTE] > The Microsoft.PowerShell.LocalAccounts module is not available in 32-bit PowerShell on a 64-bit > syste
    m.


PARAMETERS
    -Name <System.String[]>
        Specifies an array of names of user accounts that this cmdlet gets. You can use the wildcard character.

        Required?                    false
        Position?                    0
        Default value                None
        Accept pipeline input?       True (ByPropertyName, ByValue)
        Accept wildcard characters?  true

    -SID <System.Security.Principal.SecurityIdentifier[]>
        Specifies an array of security IDs (SIDs) of user accounts that this cmdlet gets.

        Required?                    false
        Position?                    0
        Default value                None
        Accept pipeline input?       True (ByPropertyName, ByValue)
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).

INPUTS
    System.String
        You can pipe a string to this cmdlet.

    System.Security.Principal.SecurityIdentifier
        You can pipe a SID to this cmdlet.


OUTPUTS
    System.Management.Automation.SecurityAccountsManager.LocalUser[]
        This cmdlet returns local user accounts.


NOTES


        Windows PowerShell includes the following aliases for `Get-LocalUser`:

        - `glu`

        The PrincipalSource property on LocalUser , LocalGroup , and LocalPrincipal objects describes the source of the
         object. The possible sources are as follows:

        - Local

        - Active Directory

        - Microsoft Entra group

        - Microsoft Account PrincipalSource is supported only by Windows 10, Windows Server 2016, and later versions of
         the Windows operating system. For earlier versions, the property is blank.

    --------- Example 1: Get an account by using its name ---------

    Get-LocalUser -Name "AdminContoso02"

    Name             Enabled Description
    ----             ------- -----------
    AdminContoso02   True    Description of this account.


    Example 2: Get an account that is connected to a Microsoft account

    Get-LocalUser -Name "MicrosoftAccount\username@Outlook.com"

    Name                                    Enabled  Description
    ----                                    -------  -----------
    MicrosoftAccount\username@outlook.com  True     Description of this account.


    ----- Example 3: Get an account that has the specified SID -----

    Get-LocalUser -SID S-1-5-21-9526073513-1762370368-3942940353-500

    Name          Enabled Description
    ----          ------- -----------
    Administrator True    Built-in account for administering the computer/domain



RELATED LINKS
    Online Version: https://learn.microsoft.com/powershell/module/microsoft.powershell.localaccounts/get-localuser?view
    =powershell-5.1&WT.mc_id=ps-gethelp
    Disable-LocalUser
    Enable-LocalUser
    New-LocalUser
    Remove-LocalUser
    Rename-LocalUser
    Set-LocalUser
PS C:\Users\Admin> Get-LocalUser -?

NAME
    Get-LocalUser

SYNOPSIS
    Gets local user accounts.


SYNTAX
    Get-LocalUser [[-Name] <System.String[]>] [<CommonParameters>]

    Get-LocalUser [[-SID] <System.Security.Principal.SecurityIdentifier[]>] [<CommonParameters>]


DESCRIPTION
    The `Get-LocalUser` cmdlet gets local user accounts. This cmdlet gets default built-in user accounts, local user ac
    counts that you created, and local accounts that you connected to Microsoft accounts.

    > [!NOTE] > The Microsoft.PowerShell.LocalAccounts module is not available in 32-bit PowerShell on a 64-bit > syste
    m.


RELATED LINKS
    Online Version: https://learn.microsoft.com/powershell/module/microsoft.powershell.localaccounts/get-localuser?view
    =powershell-5.1&WT.mc_id=ps-gethelp
    Disable-LocalUser
    Enable-LocalUser
    New-LocalUser
    Remove-LocalUser
    Rename-LocalUser
    Set-LocalUser

REMARKS
    To see the examples, type: "get-help Get-LocalUser -examples".
    For more information, type: "get-help Get-LocalUser -detailed".
    For technical information, type: "get-help Get-LocalUser -full".
    For online help, type: "get-help Get-LocalUser -online"

Jak widzisz identyczny rezultat. Opcja ta jest dobra również w przypadku chęci uzyskania pomocy dla zewnętrznych narzędzi, gdyż tradycyjny Get-Help działa tylko dla poleceń PowerShella. Przkładowo, jeżeli chciałbyś zobaczyć pomoc dla aplikacji ping.exe to  Get-Help niestety nie pomoże.

PS C:\Users\Admin> Get-Help ping.exe
Get-Help : Get-Help could not find ping.exe in a help file in this session. To download updated help topics type: "Upda
te-Help". To get help online, search for the help topic in the TechNet library at https:/go.microsoft.com/fwlink/?LinkI
D=107116.
At line:1 char:1
+ Get-Help ping.exe
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException
    + FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpComman

Jeżeli jednak zastosujemy znak zapytania to PowerShell jak najbardziej prawidłowo wykona takie polecenie.

PS C:\Users\Admin> ping.exe -?

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-c compartment] [-p]
            [-4] [-6] target_name

Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet (IPv4-only).
    -i TTL         Time To Live.
    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated
                   and has no effect on the type of service field in the IP
                   Header).
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host-list   Loose source route along host-list (IPv4-only).
    -k host-list   Strict source route along host-list (IPv4-only).
    -w timeout     Timeout in milliseconds to wait for each reply.
    -R             Use routing header to test reverse route also (IPv6-only).
                   Per RFC 5095 the use of this routing header has been
                   deprecated. Some systems may drop echo requests if
                   this header is used.
    -S srcaddr     Source address to use.
    -c compartment Routing compartment identifier.
    -p             Ping a Hyper-V Network Virtualization provider address.
    -4             Force using IPv4.
    -6             Force using IPv6.

Warto jeszcze znać aliasy dla Get-Help, czyli manhelp. W przypadku z korzystania z help tak na prawdę wywołujemy funkcję, która nie tylko zwraca plik pomocy, ale dodatkowo pozwala na stronicowanie (ang. paging). Czyli w przypadku, gdy ilośc treści nie mieści się w oknie konsoli funkcja dzieli go na strony co automatycznie zwiększa czytelność.

Na zakończenie tego ćwiczenia jeszcze jeden parametr, który może być pomocy przy chęci wyświetlenia pliku pomocy. Mowa tutaj o -ShowWindow, dzieki któremu uzyskujemy pełny widok i to w oknie graficzym, gdzie w niektórych przypadakch dużo łatwiej znaleść konkretne informacje.

Get-Help Get-LocalUser -ShowWindow

# Ćwiczenie 3 – wyszukaj polecenia z wyrazem „localuser”

Co ciekawe Get-Help nie tylko przydaje się do wyświetlenia plików pomocy, dzięki temu, że posiada spis wszystkich poleceń, można również wykorzystać to polecenie do wyszukiwania innych. Wszystkie pliki pomocy można wyświetlić w np. w ten sposób:

PS C:\Users\Admin> Get-Help *

Name                              Category  Module                    Synopsis
----                              --------  ------                    --------
foreach                           Alias                               ForEach-Object
%                                 Alias                               ForEach-Object
where                             Alias                               Where-Object
?                                 Alias                               Where-Object
clc                               Alias                               Clear-Content
cli                               Alias                               Clear-Item
clp                               Alias                               Clear-ItemProperty
clv                               Alias                               Clear-Variable
cpi                               Alias                               Copy-Item
cvpa                              Alias                               Convert-Path
dbp                               Alias                               Disable-PSBreakpoint
ebp                               Alias                               Enable-PSBreakpoint
epal                              Alias                               Export-Alias
epcsv                             Alias                               Export-Csv
fl                                Alias                               Format-List
ft                                Alias                               Format-Table
fw                                Alias                               Format-Wide
gal                               Alias                               Get-Alias
gbp                               Alias                               Get-PSBreakpoint
gc                                Alias                               Get-Content
gci                               Alias                               Get-ChildItem
gcm                               Alias                               Get-Command
gdr                               Alias                               Get-PSDrive
gcs                               Alias                               Get-PSCallStack
ghy                               Alias                               Get-History
gi                                Alias                               Get-Item
gl                                Alias                               Get-Location
gm                                Alias                               Get-Member
gmo                               Alias                               Get-Module
gp                                Alias                               Get-ItemProperty
gpv                               Alias                               Get-ItemPropertyValue
gps                               Alias                               Get-Process
group                             Alias                               Group-Object
gu                                Alias                               Get-Unique
gv                                Alias                               Get-Variable
iex                               Alias                               Invoke-Expression
ihy                               Alias                               Invoke-History
ii                                Alias                               Invoke-Item
ipmo                              Alias                               Import-Module
ipal                              Alias                               Import-Alias
ipcsv                             Alias                               Import-Csv
measure                           Alias                               Measure-Object
mi                                Alias                               Move-Item
mp                                Alias                               Move-ItemProperty
nal                               Alias                               New-Alias
ndr                               Alias                               New-PSDrive
ni                                Alias                               New-Item
nv                                Alias                               New-Variable
nmo                               Alias                               New-Module
oh                                Alias                               Out-Host
rbp                               Alias                               Remove-PSBreakpoint
rdr                               Alias                               Remove-PSDrive
ri                                Alias                               Remove-Item
rni                               Alias                               Rename-Item
rnp                               Alias                               Rename-ItemProperty
rp                                Alias                               Remove-ItemProperty
rmo                               Alias                               Remove-Module
rv                                Alias                               Remove-Variable
gerr                              Alias                               Get-Error
rvpa                              Alias                               Resolve-Path
sal                               Alias                               Set-Alias
sbp                               Alias                               Set-PSBreakpoint
select                            Alias                               Select-Object
si                                Alias                               Set-Item
sl                                Alias                               Set-Location
sp                                Alias                               Set-ItemProperty
saps                              Alias                               Start-Process
spps                              Alias                               Stop-Process
sv                                Alias                               Set-Variable
irm                               Alias                               Invoke-RestMethod
iwr                               Alias                               Invoke-WebRequest
ac                                Alias                               Add-Content
clear                             Alias                               Clear-Host
compare                           Alias                               Compare-Object
cpp                               Alias                               Copy-ItemProperty
diff                              Alias                               Compare-Object
gsv                               Alias                               Get-Service
sleep                             Alias                               Start-Sleep
sort                              Alias                               Sort-Object
start                             Alias                               Start-Process
sasv                              Alias                               Start-Service
spsv                              Alias                               Stop-Service
tee                               Alias                               Tee-Object
write                             Alias                               Write-Output
cat                               Alias                               Get-Content
cp                                Alias                               Copy-Item
ls                                Alias                               Get-ChildItem
man                               Alias                               help
mount                             Alias                               New-PSDrive
mv                                Alias                               Move-Item
ps                                Alias                               Get-Process
rm                                Alias                               Remove-Item
rmdir                             Alias                               Remove-Item
cnsn                              Alias                               Connect-PSSession
dnsn                              Alias                               Disconnect-PSSession
ogv                               Alias                               Out-GridView
shcm                              Alias                               Show-Command
cd                                Alias                               Set-Location
dir                               Alias                               Get-ChildItem
echo                              Alias                               Write-Output
fc                                Alias                               Format-Custom
kill                              Alias                               Stop-Process
pwd                               Alias                               Get-Location
type                              Alias                               Get-Content
h                                 Alias                               Get-History
history                           Alias                               Get-History
md                                Alias                               mkdir
popd                              Alias                               Pop-Location
pushd                             Alias                               Push-Location
r                                 Alias                               Invoke-History
cls                               Alias                               Clear-Host
chdir                             Alias                               Set-Location
copy                              Alias                               Copy-Item
del                               Alias                               Remove-Item
erase                             Alias                               Remove-Item
move                              Alias                               Move-Item
rd                                Alias                               Remove-Item
ren                               Alias                               Rename-Item
set                               Alias                               Set-Variable
icm                               Alias                               Invoke-Command
clhy                              Alias                               Clear-History
gjb                               Alias                               Get-Job
rcjb                              Alias                               Receive-Job
rjb                               Alias                               Remove-Job
sajb                              Alias                               Start-Job
spjb                              Alias                               Stop-Job
wjb                               Alias                               Wait-Job
nsn                               Alias                               New-PSSession
gsn                               Alias                               Get-PSSession
rsn                               Alias                               Remove-PSSession
etsn                              Alias                               Enter-PSSession
rcsn                              Alias                               Receive-PSSession
exsn                              Alias                               Exit-PSSession
sls                               Alias                               Select-String
gcb                               Alias                               Get-Clipboard
gin                               Alias                               Get-ComputerInfo
gtz                               Alias                               Get-TimeZone
scb                               Alias                               Set-Clipboard
stz                               Alias                               Set-TimeZone
fhx                               Alias                               Format-Hex
algm                              Alias                               Add-LocalGroupMember
dlu                               Alias                               Disable-LocalUser
elu                               Alias                               Enable-LocalUser
glg                               Alias                               Get-LocalGroup
glgm                              Alias                               Get-LocalGroupMember
glu                               Alias                               Get-LocalUser
nlg                               Alias                               New-LocalGroup
nlu                               Alias                               New-LocalUser
rlg                               Alias                               Remove-LocalGroup
rlgm                              Alias                               Remove-LocalGroupMember
rlu                               Alias                               Remove-LocalUser
rnlg                              Alias                               Rename-LocalGroup
rnlu                              Alias                               Rename-LocalUser
slg                               Alias                               Set-LocalGroup
slu                               Alias                               Set-LocalUser
cd..                              Function                            …
cd\                               Function                            …
cd~                               Function                            …
Pause                             Function                            …
help                              Function
prompt                            Function
Clear-Host                        Function
TabExpansion2                     Function                            …
oss                               Function
mkdir                             Function
A:                                Function                            …
B:                                Function                            …
C:                                Function                            …
D:                                Function                            …
E:                                Function                            …
F:                                Function                            …
G:                                Function                            …
H:                                Function                            …
I:                                Function                            …
J:                                Function                            …
K:                                Function                            …
L:                                Function                            …
M:                                Function                            …
N:                                Function                            …
O:                                Function                            …
P:                                Function                            …
Q:                                Function                            …
R:                                Function                            …
S:                                Function                            …
T:                                Function                            …
U:                                Function                            …
V:                                Function                            …
W:                                Function                            …
X:                                Function                            …
Y:                                Function                            …
Z:                                Function                            …
PSConsoleHostReadLine             Function  PSReadLine                …
Install-PowerShellRemoting.ps1    External…                           Install-PowerShellRemoting.ps1 [-PowerShellHome …
C:\Program Files\PowerShell\7\In… External…                           Group Policy tools use administrative template f…
C:\Program Files\PowerShell\7\Re… External…                           Registers or unregisters the PowerShell ETW mani…
RegisterMicrosoftUpdate.ps1       External…                           RegisterMicrosoftUpdate.ps1 [[-TestHook] <Object…
Add-History                       Cmdlet    Microsoft.PowerShell.Core …
Clear-History                     Cmdlet    Microsoft.PowerShell.Core …
Debug-Job                         Cmdlet    Microsoft.PowerShell.Core …
Disable-PSRemoting                Cmdlet    Microsoft.PowerShell.Core …
Enable-PSRemoting                 Cmdlet    Microsoft.PowerShell.Core …
Disable-PSSessionConfiguration    Cmdlet    Microsoft.PowerShell.Core …
Enable-PSSessionConfiguration     Cmdlet    Microsoft.PowerShell.Core …
Get-PSSessionCapability           Cmdlet    Microsoft.PowerShell.Core …
Get-PSSessionConfiguration        Cmdlet    Microsoft.PowerShell.Core …
Receive-PSSession                 Cmdlet    Microsoft.PowerShell.Core …
Register-PSSessionConfiguration   Cmdlet    Microsoft.PowerShell.Core …
Unregister-PSSessionConfiguration Cmdlet    Microsoft.PowerShell.Core …
Set-PSSessionConfiguration        Cmdlet    Microsoft.PowerShell.Core …
Test-PSSessionConfigurationFile   Cmdlet    Microsoft.PowerShell.Core …
Connect-PSSession                 Cmdlet    Microsoft.PowerShell.Core …
Disconnect-PSSession              Cmdlet    Microsoft.PowerShell.Core …
Disable-ExperimentalFeature       Cmdlet    Microsoft.PowerShell.Core …
Enable-ExperimentalFeature        Cmdlet    Microsoft.PowerShell.Core …
Enter-PSHostProcess               Cmdlet    Microsoft.PowerShell.Core …
Enter-PSSession                   Cmdlet    Microsoft.PowerShell.Core …
Exit-PSHostProcess                Cmdlet    Microsoft.PowerShell.Core …
Exit-PSSession                    Cmdlet    Microsoft.PowerShell.Core …
Export-ModuleMember               Cmdlet    Microsoft.PowerShell.Core …
ForEach-Object                    Cmdlet    Microsoft.PowerShell.Core …
Get-Command                       Cmdlet    Microsoft.PowerShell.Core …
Get-ExperimentalFeature           Cmdlet    Microsoft.PowerShell.Core …
Get-Help                          Cmdlet    Microsoft.PowerShell.Core …
Get-History                       Cmdlet    Microsoft.PowerShell.Core …
Get-Job                           Cmdlet    Microsoft.PowerShell.Core …
Get-Module                        Cmdlet    Microsoft.PowerShell.Core …
Get-PSHostProcessInfo             Cmdlet    Microsoft.PowerShell.Core …
Get-PSSession                     Cmdlet    Microsoft.PowerShell.Core …
Import-Module                     Cmdlet    Microsoft.PowerShell.Core …
Invoke-Command                    Cmdlet    Microsoft.PowerShell.Core …
Invoke-History                    Cmdlet    Microsoft.PowerShell.Core …
New-Module                        Cmdlet    Microsoft.PowerShell.Core …
New-ModuleManifest                Cmdlet    Microsoft.PowerShell.Core …
New-PSRoleCapabilityFile          Cmdlet    Microsoft.PowerShell.Core …
New-PSSession                     Cmdlet    Microsoft.PowerShell.Core …
New-PSSessionConfigurationFile    Cmdlet    Microsoft.PowerShell.Core …
New-PSSessionOption               Cmdlet    Microsoft.PowerShell.Core …
New-PSTransportOption             Cmdlet    Microsoft.PowerShell.Core …
Out-Default                       Cmdlet    Microsoft.PowerShell.Core …
Out-Host                          Cmdlet    Microsoft.PowerShell.Core …
.....

Jak widzisz tematów tych jest naprwdę sporo. Przebrnięcie przez wszystkie wyniki i odnalezienie konkretnego polecenia może być dość czasochłonne. Warto zatem nieco zawęzić poszukiwania i skorzystać przykładowo z takiej składni:

PS C:\Users\Admin> Get-Help *localuser*

Name                              Category  Module                    Synopsis
----                              --------  ------                    --------
Disable-LocalUser                 Cmdlet    Microsoft.PowerShell.Loc… Disables a local user account.
Enable-LocalUser                  Cmdlet    Microsoft.PowerShell.Loc… Enables a local user account.
Get-LocalUser                     Cmdlet    Microsoft.PowerShell.Loc… Gets local user accounts.
New-LocalUser                     Cmdlet    Microsoft.PowerShell.Loc… Creates a local user account.
Remove-LocalUser                  Cmdlet    Microsoft.PowerShell.Loc… Deletes local user accounts.
Rename-LocalUser                  Cmdlet    Microsoft.PowerShell.Loc… Renames a local user account.
Set-LocalUser                     Cmdlet    Microsoft.PowerShell.Loc… Modifies a local user account.

Zgodnie z przewidywaniami lista dostępnych tematów znacznie się zmniejszyła.

# Ćwiczenie 4 – wyświetl informacje dotyczące zmiennych preferencji

Tutaj kolejna ciekawostka, o której nie każdy wie. PowerShell posiada informacje o koncepcjach swojego działania. Jest to odpowiednik podręcznika instruktażowego. Tematy, które tam się znajdują zawierają dodatkowe informacje o wszystkich modułach, a także wielu innych zagadnieniach. Roboczo nazywane są tematami about gdyż w ich nazwie zawsze występuję przedrostek about. Aby je wyświetlić wystarczy wpisać polecenie:

PS C:\Users\Admin> Get-Help -Category HelpFile

Name                              Category  Module                    Synopsis                                                                                                                       
----                              --------  ------                    --------                                                                                                                       
about_Aliases                     HelpFile                                                                                                                                                           
about_Alias_Provider              HelpFile                                                                                                                                                           
about_ANSI_Terminals              HelpFile                                                                                                                                                           
about_Arithmetic_Operators        HelpFile                                                                                                                                                           
about_Arrays                      HelpFile                                                                                                                                                           
about_Assignment_Operators        HelpFile                                                                                                                                                           
about_Automatic_Variables         HelpFile                                                                                                                                                           
about_Booleans                    HelpFile                                                                                                                                                           
about_Break                       HelpFile                                                                                                                                                           
about_Built-in_Functions          HelpFile                                                                                                                                                           
about_Calculated_Properties       HelpFile                                                                                                                                                           
about_Case-Sensitivity            HelpFile                                                                                                                                                           
about_Certificate_Provider        HelpFile                                                                                                                                                           
about_Character_Encoding          HelpFile                                                                                                                                                           
about_CimSession                  HelpFile                                                                                                                                                           
about_Classes                     HelpFile                                                                                                                                                           
about_Classes_Constructors        HelpFile                                                                                                                                                           
about_Classes_Inheritance         HelpFile                                                                                                                                                           
about_Classes_Methods             HelpFile                                                                                                                                                           
about_Classes_Properties          HelpFile                                                                                                                                                           
about_Command_Precedence          HelpFile                                                                                                                                                           
about_Command_Syntax              HelpFile                                                                                                                                                           
about_Comment_Based_Help          HelpFile                                                                                                                                                           
about_CommonParameters            HelpFile                                                                                                                                                           
about_Comparison_Operators        HelpFile                                                                                                                                                           
about_Continue                    HelpFile                                                                                                                                                           
about_Core_Commands               HelpFile                                                                                                                                                           
about_Data_Files                  HelpFile                                                                                                                                                           
about_Data_Sections               HelpFile                                                                                                                                                           
about_Debuggers                   HelpFile                                                                                                                                                           
about_DesiredStateConfiguration   HelpFile                                                                                                                                                           
about_Do                          HelpFile                                                                                                                                                           
about_Enum                        HelpFile                                                                                                                                                           
about_Environment_Provider        HelpFile                                                                                                                                                           
about_Environment_Variables       HelpFile                                                                                                                                                           
about_Eventlogs                   HelpFile                                                                                                                                                           
about_Execution_Policies          HelpFile                                                                                                                                                           
about_FileSystem_Provider         HelpFile                                                                                                                                                           
about_For                         HelpFile                                                                                                                                                           
about_Foreach                     HelpFile                                                                                                                                                           
about_Format.ps1xml               HelpFile                                                                                                                                                           
about_Functions                   HelpFile                                                                                                                                                           
about_Functions_Advanced          HelpFile                                                                                                                                                           
about_Functions_Advanced_Methods  HelpFile                                                                                                                                                           
about_Functions_Advanced_Param... HelpFile                                                                                                                                                           
about_Functions_Argument_Compl... HelpFile                                                                                                                                                           
about_Functions_CmdletBindingA... HelpFile                                                                                                                                                           
about_Functions_OutputTypeAttr... HelpFile                                                                                                                                                           
about_Function_Provider           HelpFile                                                                                                                                                           
about_Group_Policy_Settings       HelpFile                                                                                                                                                           
about_Hash_Tables                 HelpFile                                                                                                                                                           
about_Hidden                      HelpFile                                                                                                                                                           
about_History                     HelpFile                                                                                                                                                           
about_If                          HelpFile                                                                                                                                                           
about_Intrinsic_Members           HelpFile                                                                                                                                                           
about_Jobs                        HelpFile                                                                                                                                                           
about_Job_Details                 HelpFile                                                                                                                                                           
about_Join                        HelpFile                                                                                                                                                           
about_Language_Keywords           HelpFile                                                                                                                                                           
about_Language_Modes              HelpFile                                                                                                                                                           
about_Line_Editing                HelpFile                                                                                                                                                           
about_Locations                   HelpFile                                                                                                                                                           
about_Logging                     HelpFile                                                                                                                                                           
about_Logical_Operators           HelpFile                                                                                                                                                           
about_Member-Access_Enumeration   HelpFile                                                                                                                                                           
about_Methods                     HelpFile                                                                                                                                                           
about_Modules                     HelpFile                                                                                                                                                           
about_Module_Manifests            HelpFile                                                                                                                                                           
about_Numeric_Literals            HelpFile                                                                                                                                                           
about_Objects                     HelpFile                                                                                                                                                           
about_Object_Creation             HelpFile                                                                                                                                                           
about_Operators                   HelpFile                                                                                                                                                           
about_Operator_Precedence         HelpFile                                                                                                                                                           
about_Output_Streams              HelpFile                                                                                                                                                           
about_PackageManagement           HelpFile                                                                                                                                                           
about_Parameters                  HelpFile                                                                                                                                                           
about_Parameters_Default_Values   HelpFile                                                                                                                                                           
about_Parameter_Sets              HelpFile                                                                                                                                                           
about_Parsing                     HelpFile                                                                                                                                                           
about_Path_Syntax                 HelpFile                                                                                                                                                           
about_Pipelines                   HelpFile                                                                                                                                                           
about_PowerShell_exe              HelpFile                                                                                                                                                           
about_PowerShell_Ise_exe          HelpFile                                                                                                                                                           
about_Preference_Variables        HelpFile                                                                                                                                                           
about_Profiles                    HelpFile                                                                                                                                                           
about_Prompts                     HelpFile                                                                                                                                                           
about_Properties                  HelpFile                                                                                                                                                           
about_Providers                   HelpFile                                                                                                                                                           
about_PSConsoleHostReadLine       HelpFile                                                                                                                                                           
about_PSCustomObject              HelpFile                                                                                                                                                           
about_PSItem                      HelpFile                                                                                                                                                           
about_PSModulePath                HelpFile                                                                                                                                                           
about_PSSessions                  HelpFile                                                                                                                                                           
about_PSSession_Details           HelpFile                                                                                                                                                           
about_PSSnapins                   HelpFile                                                                                                                                                           
about_Quoting_Rules               HelpFile                                                                                                                                                           
about_Redirection                 HelpFile                                                                                                                                                           
about_Ref                         HelpFile                                                                                                                                                           
about_Registry_Provider           HelpFile                                                                                                                                                           
about_Regular_Expressions         HelpFile                                                                                                                                                           
about_Remote                      HelpFile                                                                                                                                                           
about_Remote_Disconnected_Sess... HelpFile                                                                                                                                                           
about_Remote_Jobs                 HelpFile                                                                                                                                                           
about_Remote_Output               HelpFile                                                                                                                                                           
about_Remote_Requirements         HelpFile                                                                                                                                                           
about_Remote_Troubleshooting      HelpFile                                                                                                                                                           
about_Remote_Variables            HelpFile                                                                                                                                                           
about_Requires                    HelpFile                                                                                                                                                           
about_Reserved_Words              HelpFile                                                                                                                                                           
about_Return                      HelpFile                                                                                                                                                           
about_Run_With_PowerShell         HelpFile                                                                                                                                                           
about_Scopes                      HelpFile                                                                                                                                                           
about_Scripts                     HelpFile                                                                                                                                                           
about_Script_Blocks               HelpFile                                                                                                                                                           
about_Script_Internationalization HelpFile                                                                                                                                                           
about_Session_Configurations      HelpFile                                                                                                                                                           
about_Session_Configuration_Files HelpFile                                                                                                                                                           
about_Signing                     HelpFile                                                                                                                                                           
about_Simplified_Syntax           HelpFile                                                                                                                                                           
about_Special_Characters          HelpFile                                                                                                                                                           
about_Splatting                   HelpFile                                                                                                                                                           
about_Split                       HelpFile                                                                                                                                                           
about_Switch                      HelpFile                                                                                                                                                           
about_Tab_Expansion               HelpFile                                                                                                                                                           
about_Throw                       HelpFile                                                                                                                                                           
about_Transactions                HelpFile                                                                                                                                                           
about_Trap                        HelpFile                                                                                                                                                           
about_Try_Catch_Finally           HelpFile                                                                                                                                                           
about_Types.ps1xml                HelpFile                                                                                                                                                           
about_Type_Accelerators           HelpFile                                                                                                                                                           
about_Type_Operators              HelpFile                                                                                                                                                           
about_Updatable_Help              HelpFile                                                                                                                                                           
about_Using                       HelpFile                                                                                                                                                           
about_Variables                   HelpFile                                                                                                                                                           
about_Variable_Provider           HelpFile                                                                                                                                                           
about_While                       HelpFile                                                                                                                                                           
about_Wildcards                   HelpFile                                                                                                                                                           
about_Windows_Powershell_5.1      HelpFile                                                                                                                                                           
about_Windows_PowerShell_ISE      HelpFile                                                                                                                                                           
about_Windows_RT                  HelpFile                                                                                                                                                           
about_WMI                         HelpFile                                                                                                                                                           
about_WMI_Cmdlets                 HelpFile                                                                                                                                                           
about_WQL                         HelpFile                                                                                                                                                           
about_WS-Management_Cmdlets       HelpFile                                                                                                                                                           
about_WSMan_Provider              HelpFile                                                                                                                                                           
default                           HelpFile                            SHORT DESCRIPTION                                                                                                              
about_BurntToast                  HelpFile                            An overview of the BurntToast module and quick start on its use.                                                               
about_az                          HelpFile                            about_Az                                                                                                                       
about_BeforeEach_AfterEach        HelpFile                            performed at the beginning and end of every It block. This can eliminate duplication of code                                   
about_Mocking                     HelpFile                            Pester provides a set of Mocking functions making it easy to fake dependencies                                                 
about_Pester                      HelpFile                            Pester is a BDD based test runner for PowerShell.                                                                              
about_should                      HelpFile                            Provides assertion convenience methods for comparing objects and throwing                                                      
about_TestDrive                   HelpFile                            A PSDrive for file activity limited to the scope of a singe Describe or                                                        
about_PSReadLine                  HelpFile                                                                                                                                                           
about_PSReadLine_Functions        HelpFile                                                                                                                                                           
about_ActiveDirectory             HelpFile                                                                                                                                                           
about_ActiveDirectory_Filter      HelpFile                                                                                                                                                           
about_ActiveDirectory_Identity    HelpFile                                                                                                                                                           
about_ActiveDirectory_ObjectModel HelpFile                                                                                                                                                           
about_Classes_and_DSC             HelpFile                                                                                                                                                           
about_Scheduled_Jobs              HelpFile                                                                                                                                                           
about_Scheduled_Jobs_Advanced     HelpFile                                                                                                                                                           
about_Scheduled_Jobs_Basics       HelpFile                                                                                                                                                           
about_Scheduled_Jobs_Troublesh... HelpFile                                                                                                                                                           
about_ActivityCommonParameters    HelpFile                                                                                                                                                           
about_Checkpoint-Workflow         HelpFile                                                                                                                                                           
about_Foreach-Parallel            HelpFile                                                                                                                                                           
about_InlineScript                HelpFile                                                                                                                                                           
about_Parallel                    HelpFile                                                                                                                                                           
about_Sequence                    HelpFile                                                                                                                                                           
about_Suspend-Workflow            HelpFile                                                                                                                                                           
about_WorkflowCommonParameters    HelpFile                                                                                                                                                           
about_Workflows                   HelpFile 

Lub w wersji skrótowej:

PS C:\Users\Admin> Get-Help about*

Samych tematów jest sporo (szczególnie w Windows PowerShell), a informacje na konkretny temat możesz uzyskać wykonując polecenie.

PS C:\Users\Admin> Get-Help about_Preference_Variables

Przy czym polecam zastosowac parametr -ShowWindows, gdyż zwykle są to dość obszerne opracowania. Warto przy tym pamiętać, że w przypadku tych konkretnych tematów pomocy, parametry -Detailed oraz -Full nie mają zastosowania.

# Ćwiczenie 5 – zlokalizuj plik pomocy dla cmdletu Get-Command

Pamiętasz zapewne, że pliki pomocy mogą znajdować się w dwóch miejscach. Lokalnie na komputerze i w wersji online. Przez co lokalizacja każdego z nich wymaga nieco innego podejścia, ale wszystko da się załatwić za pomocą w zasadzie jednego polecenia:

PS C:\Users\Admin> (Get-Command Get-ChildItem).Helpfile
Microsoft.PowerShell.Commands.Management.dll-Help.xml
PS C:\Users\Admin> (Get-Command Get-ChildItem).HelpUri
https://go.microsoft.com/fwlink/?LinkID=113308

W pierwszym przypadku rezultatem jest nazwa konkretnego pliku na dysku, który znajduje się w katalogu domowym instalacji PowerShella. Drugie polecenie zwróci adres strony internetowej. W ramach małej pracy domowej możesz zlokalizować te pliki i wyświetl je.

Na zakończenie dzisiejszego wpisu dodam jeszcze, że w przypadku tworzenia własnych poleceń, funkcji czy skryptów zaleca się również tworzenie plików pomocy, które poinformuja uzytkowników o przznaczeniu danego kawałka kodu. Ale tym tematem myślę, że zajmiemy się innym razem.

Tyle na dziś. Jeżeli masz jakieś ciekawe informacje w tym temacie to podziel się w komentarzach.

Jeżeli uważasz, że dobrze wykonaliśmy swoją robotę i dowiedziałeś się czegoś nowego to postaw nam wirtualną kawę.

Postaw mi kawę na buycoffee.to

Darmowy Ebook
Podziel się

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *