1. 添加 powershell-ise:
Import-Module servermanager
Add-WindowsFeature powershell-ise
2. 设置.ps1文件的可执行权限
Set-ExecutionPolicy Remotesigned
3. 获取帮助
Get-Help Get-Service -Detail
4. 注释 #,多行注释 <#…#>
5. 关键词 :Module,ServerManager,WebAdministration,ActiveDirectory
6. 创建空数组
$array=@( )
7. 测试路径或文件是否存在
Test-Path c:\scripts\test.txt
Test-Path "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4“
8.退域、加域
Add domain :
(Get-WmiObject-Namespace “root\cimv2″ -Class“Win32_ComputerSystem”).JoinDomainOrWorkgroup(“DomainName”,”AdminPassword”,”Domain\Administrator”,$null,3)
Eg:
(Get-WmiObject -Namespace “root\cimv2" -Class“Win32_ComputerSystem”).JoinDomainOrWorkgroup("scx.com","OpsMgr2007R2","scx\scxsvc",$null,3)
Remove domain:
netdom remove $ComName/Domain:$Domainname /userD:$Domainuser /PasswordD:$Domainpsw /REBoot:5
Eg:
Netdom remove scxcmt-ws7-23 /Domain:scx.com /UserD:scx\scxsvc /PasswordD:OpsMgr2007R2