今天给大家讲解PowerShell Cmdlet概念介绍,希望对大家学习PowerShell能有所帮助!
一、概念大家可能对cmd命令比较熟悉cmd就是Windows系统命令行窗口执行的命令,微软为了和传统的Shell命令区分,所以重新起了一个名词“Cmdlet”专门给PowerShell配套使用,Cmdlet可以理解为在PowerShell环境中执行的命令,并且依赖于PowerShell环境才可以执行。
注意:Cmdlet必须有Net环境支持,否则就会报错。
二、传统的CMD和Cmdlet命令的区别传统CMD是32位的命令行程序【cmd.exe】,继承DOS操作模式,是Windows系统的‘标配’组件,可执行Windows命令和BAT文件,CMD只能执行基本的任务,本身并没有集成太多的功能。
Cmdlet是PowerShell的命令,所有的cmdlet命令都遵循动词-名词这样语法结构,PowerShell提供了Get-Command这个强大的命令,可以查找所有的cmdlet命令。它拥有强大的第三方类库支持,可以实现非常复杂的运维任务和数据处理分析。
三、Cmdlet说明属于Net类实例化编译后的可执行脚本程序。
Cmdlet不负责错误处理和数据输出,依赖于PowerShell本身的运行环境来处理
Cmdlet采用管道进行对象处理,而非文本数据流,也支持把Cmdlet的执行结果作为对象传递到管道。
Cmdlet一次只能面对一个对象实现处理操作
四、PowerShell支持执行的命令PowerShell功能非常强大也了兼容旧版的cmd shell,具体支持下面几种类型的命令
Cmdlet命令:Cmdlet命令属于PowerShell的“亲儿子”,所有命令都可以支持,还包括基于PowerShell构建的别名命令。
CMD命令:为了兼容旧版的命令行窗口,支持除别名以外所有的命令。所以大家使用cmd 别名命令要注意一下。
Bat脚本:对应cmd shell支持的bat脚本,它也支持。
VBS脚本:也支持VBS脚本命令的执行。
Function:当然也支持PowerShell Function的功能函数。
五、Cmdlet命令的特点Cmdlet命令的更加人性化便于理解,如果没有使用别名的情况下,它的命令格式统一都是
动词+名词 这样的格式更容易书写也更容易理解。
执行如下命令:
查询当前环境支持的命令
get-commandCommandType Name Version Source
----------- ---- ------- ------
Alias Add-AppPackage 2.0.1.0 Appx
Alias Add-AppPackageVolume 2.0.1.0 Appx
Alias Add-AppProvisionedPackage 3.0 Dism
Alias Add-ProvisionedAppPackage 3.0 Dism
Alias Add-ProvisionedAppxPackage 3.0 Dism
Alias Add-ProvisioningPackage 3.0 Provisioning
Alias Add-TrustedProvisioningCertificate 3.0 Provisioning
Alias Apply-WindowsUnattend 3.0 Dism
Alias Begin-WebCommitDelay 1.0.0.0 WebAdministration
Alias Disable-PhysicalDiskIndication 2.0.0.0 Storage
Alias Disable-StorageDiagnosticLog 2.0.0.0 Storage
Alias Dismount-AppPackageVolume 2.0.1.0 Appx
Alias Enable-PhysicalDiskIndication 2.0.0.0 Storage
Alias Enable-StorageDiagnosticLog 2.0.0.0 Storage
Alias End-WebCommitDelay 1.0.0.0 WebAdministration
Alias Flush-Volume 2.0.0.0 Storage
Alias Get-AppPackage 2.0.1.0 Appx
Alias Get-AppPackageDefaultVolume 2.0.1.0 Appx
Alias Get-AppPackageLastError 2.0.1.0 Appx
Alias Get-AppPackageLog 2.0.1.0 Appx
Alias Get-AppPackageManifest 2.0.1.0 Appx
Alias Get-AppPackageVolume 2.0.1.0 Appx
Alias Get-AppProvisionedPackage 3.0 Dism
Alias Get-DiskSNV 2.0.0.0 Storage
Alias Get-Language 1.0 LanguagePackManagement
Alias Get-PhysicalDiskSNV 2.0.0.0 Storage
Alias Get-PreferredLanguage 1.0 LanguagePackManagement
Alias Get-ProvisionedAppPackage 3.0 Dism
Alias Get-ProvisionedAppxPackage 3.0 Dism
Alias Get-StorageEnclosureSNV 2.0.0.0 Storage
Alias Get-SystemLanguage 1.0 LanguagePackManagement
Alias Initialize-Volume 2.0.0.0 Storage
Alias Mount-AppPackageVolume 2.0.1.0 Appx
Alias Move-AppPackage 2.0.1.0 Appx
Alias Move-SmbClient 2.0.0.0 SmbWitness
Alias Optimize-AppProvisionedPackages 3.0 Dism
Alias Optimize-ProvisionedAppPackages 3.0 Dism
Alias Optimize-ProvisionedAppxPackages 3.0 Dism
Alias Remove-AppPackage 2.0.1.0 Appx
Alias Remove-AppPackageVolume 2.0.1.0 Appx
Alias Remove-AppProvisionedPackage 3.0 Dism
Alias Remove-EtwTraceSession 1.0.0.0 EventTracingManagement
Alias Remove-ProvisionedAppPackage 3.0 Dism
Alias Remove-ProvisionedAppxPackage 3.0 Dism
Alias Remove-ProvisioningPackage 3.0 Provisioning
Alias Remove-TrustedProvisioningCertificate 3.0 Provisioning
Alias Set-AppPackageDefaultVolume 2.0.1.0 Appx
Alias Set-AppPackageProvisionedDataFile 3.0 Dism
Alias Set-AutologgerConfig 1.0.0.0 EventTracingManagement
Alias Set-EtwTraceSession 1.0.0.0 EventTracingManagement
Alias Set-PreferredLanguage 1.0 LanguagePackManagement
Alias Set-ProvisionedAppPackageDataFile 3.0 Dism
Alias Set-ProvisionedAppXDataFile 3.0 Dism
Alias Set-SystemLanguage 1.0 LanguagePackManagement
Alias Write-FileSystemCache 2.0.0.0 Storage
Function A:
Function Add-BCDataCacheExtension 1.0.0.0 BranchCache
Function Add-BitLockerKeyProtector 1.0.0.0 BitLocker
Function Add-DnsClientNrptRule 1.0.0.0 DnsClient
Function Add-DtcClusterTMMapping 1.0.0.0 MsDtc
Function Add-EtwTraceProvider 1.0.0.0 EventTracingManagement
Function Add-InitiatorIdToMaskingSet 2.0.0.0 Storage
Function Add-MpPreference 1.0 ConfigDefender
Function Add-MpPreference 1.0 Defender
Function Add-NetEventNetworkAdapter 1.0.0.0 NetEventPacketCapture
Function Add-NetEventPacketCaptureProvider 1.0.0.0 NetEventPacketCapture
Function Add-NetEventProvider 1.0.0.0 NetEventPacketCapture
Function Add-NetEventVFPProvider 1.0.0.0 NetEventPacketCapture
Function Add-NetEventVmNetworkAdapter 1.0.0.0 NetEventPacketCapture
Function Add-NetEventVmSwitch 1.0.0.0 NetEventPacketCapture
Function Add-NetEventVmSwitchProvider 1.0.0.0 NetEventPacketCapture
Function Add-NetEventWFPCaptureProvider 1.0.0.0 NetEventPacketCapture
Function Add-NetIPHttpsCertBinding 1.0.0.0 NetworkTransition
Function Add-NetLbfoTeamMember 2.0.0.0 NetLbfo
Function Add-NetLbfoTeamNic 2.0.0.0 NetLbfo
Function Add-NetNatExternalAddress 1.0.0.0 NetNat
Function Add-NetNatStaticMapping 1.0.0.0 NetNat
Function Add-NetSwitchTeamMember 1.0.0.0 NetSwitchTeam
Function Add-OdbcDsn 1.0.0.0 Wdac
Function Add-PartitionAccessPath 2.0.0.0 Storage
Function Add-PhysicalDisk 2.0.0.0 Storage
Function Add-Printer 1.1 PrintManagement
Function Add-PrinterDriver 1.1 PrintManagement
Function Add-PrinterPort 1.1 PrintManagement
Function Add-StorageFaultDomain 2.0.0.0 Storage
Function Add-TargetPortToMaskingSet 2.0.0.0 Storage
Function Add-VirtualDiskToMaskingSet 2.0.0.0 Storage
Function Add-VpnConnection 2.0.0.0 VpnClient
Function Add-VpnConnectionRoute 2.0.0.0 VpnClient
Function Add-VpnConnectionTriggerApplication 2.0.0.0 VpnClient
Function Add-VpnConnectionTriggerDnsConfiguration 2.0.0.0 VpnClient
Function Add-VpnConnectionTriggerTrustedNetwork 2.0.0.0 VpnClient
Function AfterAll 3.4.0 Pester
Function AfterEach 3.4.0 Pester
Function Assert-MockCalled 3.4.0 Pester
Function Assert-VerifiableMocks 3.4.0 Pester
Function B:
Function Backup-BitLockerKeyProtector 1.0.0.0 BitLocker
Function BackupToAAD-BitLockerKeyProtector 1.0.0.0 BitLocker
Function BeforeAll 3.4.0 Pester
Function BeforeEach 3.4.0 Pester
Function Block-FileShareAccess 2.0.0.0 Storage
Function Block-SmbShareAccess 2.0.0.0 SmbShare
Function C:
Function cd..
Function cd\
Function Clear-AssignedAccess 1.0.0.0 AssignedAccess
Function Clear-BCCache 1.0.0.0 BranchCache
Function Clear-BitLockerAutoUnlock 1.0.0.0 BitLocker
Function Clear-Disk 2.0.0.0 Storage
Function Clear-DnsClientCache 1.0.0.0 DnsClient
Function Clear-FileStorageTier 2.0.0.0 Storage
Function Clear-Host
Function Clear-PcsvDeviceLog 1.0.0.0 PcsvDevice
Function Clear-StorageBusDisk 1.0.0.0 StorageBusCache
Function Clear-StorageDiagnosticInfo 2.0.0.0 Storage
Function Close-SmbOpenFile 2.0.0.0 SmbShare
Function Close-SmbSession 2.0.0.0 SmbShare
Function Compress-Archive 1.0.1.0 Microsoft.PowerShell.Archive
Function Configuration 1.1 PSDesiredStateConfiguration
Function Connect-IscsiTarget 1.0.0.0 iSCSI
Function Connect-VirtualDisk 2.0.0.0 Storage
Function Context 3.4.0 Pester
Function ConvertFrom-SddlString 3.1.0.0 Microsoft.PowerShell.Utility