Windows 8 驚艷登場,當Metro界面吸引了無數人的眼球時,其實還有很多特性值得關注,如PowerShell 3.0、Hyper-V 3.0、vhdx、IIS 8等。
PowerShell 2.0實踐系列從本次開始全面轉向3.0,體驗一下PowerShell 3.0帶來的管理方案提升。
很慶幸PowerGUI Script Editor 可以在Windows 8下安裝:官方下載
本系列全部腳本在Windows 8 x64(PowerShell 3.0) + PowerGUI Script Editor 3.0 Free Edition x64 上測試通過
一、PowerShell 3.0概述
如同PowerShell 2.0內置于Windows 7和 Windows Server 2008 R2,在Build大會上發布的Windows 8 Developer Preview 和 Windows Server 8 Developer Preview也內置了PowerShell 3.0。我安裝的Windows 8 Developer Preview x64,快捷鍵Win + R 打開運行,輸入powershell即可打開PowerShell 3.0的命令行:
雖然標題欄還是1.0,但是通過全局變量 $host 可以查看具體版本信息:
未安裝 Windows 8 的朋友也不必掃興,微軟已經放出了PowerShell 3.0 CTP1的下載,在這里下載:
需要注意的是操作系統必須為Windows 7 SP1 或 Windows Server 2008 R2 SP1,且需要.NET Framework 4.0。
PowerShell 3.0 只是 WMF(Windows Management Framework 3.0,Windows 管理框架)的一部分,WMF 3.0的新特性有:
1、PowerShell 3.0
支持 Workflows - 讓你可以在命令行就可以操作 Windows Workflow Foundation
更穩定的 Session - 讓你的 Session 可以更加適應不穩定的網絡、突然停機的系統、隨時重新連接
計劃任務 - 讓你從命令行就可以創建、管理 Windows 計劃任務
權限托管 - 讓受限的用戶可以在特定情況下執行更高權限的腳本
更簡化的語法 - 讓腳本看起來更像程序或者更像自然語言
Cmdlet 發掘 - 改進的自動模塊加載可以讓你更容易發掘系統中的各種 Cmdlet
PowerShell ISE插件- 更容易編寫腳本命令
2、WMI(Windows Management Instrumentation,Windows管理規范)
新的開發模型提供者 - 新的開發模型降低了管理成本,移除了對COM的依賴
新的管理客戶端API – 提供標準的公共信息模型(CIM = Common Information Model)操作,允許在Windows上管理*ninx等非Windows操作系統
附注:
公共信息模型CIM,是一個與具體實現無關的、用于描述管理信息的概念性模型。CIM分為兩部分:CIM 規范(CIM Specification)和CIM 模式(CIM Schema)。CIM 規范提供了模型的正式定義,它描述了語言、命名、元模式和到其他管理模型(如SNMP MIB)的映射技術;CIM 模式則給出了實際模型的描述。CIM 模型由核心模型、公共模型和擴展模型三層構成。核心模型是一系列類、連接和屬性的集合,該對象組提供了所有管理域通用的基本信息模型;公共模型提供特定管理域的通用信息模型,這些特定的管理域,如系統、應用程序、網絡和設備等;擴展模型代表通用模型的特定技術擴展。
通過CIM 建模,能夠得到管理域中實體的抽象和表示,包括它們的屬性、操作和關系。這樣的模型獨立于任何具體的數據庫、應用、協議以及平臺。因此,CIM 模型要求不同開發商所提供的基于不同平臺的應用都采用一種標準的格式來描述管理數據,以使數據能夠在多種應用間共享。CIM 采用面向對象的方式構建了一種新的適用于管理系統、網絡的結構和概念模型。CIM 建模是一種通用方法。特定管理域的CIM 建模是在核心模型和公共模型的基礎上進行擴展。
總的來說公共信息模型(CIM)是一個標準,定義了一個前后一致的模型,依據這個模型,網絡設備、系統和應用程序能顯示有關它們自己的信息,并使這些信息能被管理工具利用CIM能描述諸如桌面軟件和硬件配置、CPU 封裝塊的序列號以及某個特殊路由器端口上的流量水平等信息。
也許CIM有別于以前標準的最重要之處是其表示組成計算機系統或公司網絡的不同單元和部件之間關系的能力。DIF主席、Novell的公司設計師Winston Bumpus 稱,利用CIM"你能看到這臺計算機是否與這個應用 程序連在一起,它是在運行從這臺服務器上送出的服務。"他還說,通過跟蹤路徑和檢查一路上每個部件的狀態,管理工具就能" 回答我為什么不能送出電子郵件這樣的問題了。"
CIMOM 公共信息模型對象管理器(Common Information Model Object Manager)
是一個描述操作系統構成單元的對象數據庫,為MMC和腳本程序提供了一個訪問操作系統構成單元的公共接口。
3、WinRM(Windows Remote Management,Windows 遠程管理)
更穩定的連接 - 更加適應不穩定的網絡、突然停機的系統、隨時重新連接
更彈性的連接 - 當連接中斷后,可以迅速重新連接
4、PowerShell Web服務
支持REST形式的Web服務使用開放式數據協議(Open Data Protocol ,OData)遠程執行PowerShell腳本,支持Windows和非Windows客戶端。
二、Windows Server 8中的PowerShell 3.0新模塊
ADDeploymentWF
AppLocker
Appx
BestPractices
BitsTransfer
BranchCache
CimCmdlets
ClusterAwareUpdating
DirectAccessClientComponents
Dism
DnsClient
DnsConfig
DnsLookup
DnsNrpt
FailoverClusters
FileServer
iSCSI
KdsCmdlets
Microsoft.PowerShell.Core
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.PowerShell.Utility
Microsoft.WSMan.Management
MicrosoftiSCSITarget
MsDtc
NetAdapter
NetLbfo
NetQos
NetSwitchTeam
NetTCPIP
netwnv
NetworkConnectivityStatus
NetworkSecurity
NetworkTransition
PKIClient
PrintManagement
PS_MMAgent
PSDiagnostics
PSScheduledJob
PSWorkflow
RDManagement
三、Windows 8 Developer Preview中的PowerShell 3.0的命令與別名
Disable-PSSessionConfiguration
New-PSSessionConfigurationFile
Register-PSSessionConfiguration
Test-PSSessionConfigurationFile
Unregister-PSSessionConfiguration
Complete-DtcDiagnosticTransaction
Join-DtcDiagnosticResourceManager
Receive-DtcDiagnosticTransaction
Start-DtcDiagnosticResourceManager
Stop-DtcDiagnosticResourceManager
New-NetQuickModeCryptoProposal
New-CertificateNotificationTask
Get-CertificateNotificationTask
Remove-CertificateNotificationTask
New-PSSessionConfigurationFile
Test-PSSessionConfigurationFile
Connect-PSSession ALIASES cnsn
Connect-PSSession [-ComputerName] <string[]> [-Credential <PSCredential>] [-Authentication
[-ThrottleLimit <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Confirm] [<CommonParameters>]
[-ThrottleLimit <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-ThrottleLimit <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
ConvertFrom-Json [-InputObject] <string> [<CommonParameters>]
ConvertTo-Json [-InputObject] <Object> [-Depth <int>] [-Compress] [<CommonParameters>]
Disable-PSRemoting ALIASES None
Disable-PSRemoting [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
Disconnect-PSSession ALIASES dnsn
[-WhatIf] [-Confirm] [<CommonParameters>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-Confirm] [<CommonParameters>]
[-Confirm] [<CommonParameters>]
Export-CimCommand ALIASES None
Get-ControlPanelItem ALIASES None
Get-ControlPanelItem [[-Name] <string[]>] [-Category <string[]>] [<CommonParameters>]
Get-ControlPanelItem -CanonicalName <string[]> [-Category <string[]>] [<CommonParameters>]
Get-TypeData [[-TypeName] <string[]>] [<CommonParameters>]
New-PSSessionConfigurationFile ALIASES NONE
<string[]>] [-VisibleAliases <string[]>] [-VisibleCmdlets <string[]>] [-VisibleFunctions <string[]>]
[-VisibleProviders <string[]>] [-VisibleVariables <string[]>] [-AliasDefinitions <hashtable[]>]
Restricted | Default | Bypass | Undefined}] [-ScriptsToProcess <string[]>] [<CommonParameters>]
New-PSTransportOption [-MaxIdleTimeout <int>] [-ProcessIdleTimeout <int>] [-MaxSessions <int>]
[-OutputBufferingMode <OutputBufferingMode>] [<CommonParameters>]
New-WinEvent [-ProviderName] <string> [-Id] <int> [[-Payload] <Object[]>] [-Version <byte>] [-Force]
Receive-PSSession ALIASES rcsn
[-WhatIf] [-Confirm] [<CommonParameters>]
[-Confirm] [<CommonParameters>]
[-Port <int>] [-UseSSL] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Port <int>] [-UseSSL] [-WhatIf] [-Confirm] [<CommonParameters>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-Confirm] [<CommonParameters>]
<scriptblock>] [-MessageData <psobject>] [-SupportEvent] [-Forward] [<CommonParameters>]
Remove-TypeData -TypeData <TypeData> [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-TypeData [-TypeName] <string> [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-TypeData [-Path <string[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-LocalCredential <PSCredential>] [-Force] [-Restart] [-WhatIf] [-Confirm] [<CommonParameters>]
Resume-Job [-Id] <int[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Resume-Job [-Job] <Job[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Resume-Job [[-Name] <string[]>] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Resume-Job [[-InstanceId] <Guid[]>] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Suspended | Disconnected | Suspending | Stopping}] [-WhatIf] [-Confirm] [<CommonParameters>]
Resume-Job [-PassThru] [-Filter <hashtable>] [-WhatIf] [-Confirm] [<CommonParameters>]
Save-Help [[-DestinationPath] <string[]>] [[-UICulture] <string[]>] [-Force] [<CommonParameters>]
[-LiteralPath <string[]>] [-Force] [<CommonParameters>]
<string[]>] [-Force] [<CommonParameters>]
Save-Help [[-UICulture] <string[]>] [-LiteralPath <string[]>] [-Force] [<CommonParameters>]
Show-ControlPanelItem [-Name] <string[]> [<CommonParameters>]
Show-ControlPanelItem -CanonicalName <string[]> [<CommonParameters>]
Show-ControlPanelItem [[-InputObject] <ControlPanelItem[]>] [<CommonParameters>]<strong></strong>
Suspend-Job [-Id] <int[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Suspend-Job [-Job] <Job[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Suspend-Job [[-Name] <string[]>] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Suspend-Job [[-InstanceId] <Guid[]>] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Suspended | Disconnected | Suspending | Stopping}] [-WhatIf] [-Confirm] [<CommonParameters>]
Suspend-Job [-PassThru] [-Filter <hashtable>] [-WhatIf] [-Confirm] [<CommonParameters>]
Test-PSSessionConfigurationFile
Test-PSSessionConfigurationFile [-Path] <string> [<CommonParameters>]
Unblock-File [-Path] <string[]> [-WhatIf] [-Confirm] [<CommonParameters>]
Unblock-File [-LiteralPath] <string[]> [-WhatIf] [-Confirm] [<CommonParameters>]
[-Recurse] [-Force] [<CommonParameters>]
<string[]>] [-Recurse] [-Force] [<CommonParameters>]
查看ScheduledTasks模塊包含的所有命令:Get-Command –Module ScheduledTasks
![]() |
不含病毒。www.avast.com |