#PSSnapin and Modules
http://msdn.microsoft.com/en-us/library/windows/desktop/dd745031(v=vs.85).aspx
from this page, it says
snap-in (PSSnapin) is a dynamic link library (.dll) that implements cmdlets and providers
And for Modules, it can contains cmdlets, providers, functions, aliases, variables, and drives
#PSSnapin install and import
1. Create PSCmdlet class for command
2. Create PSsnapin class for install
3. InstallUtil.exe “mydll.dll”
4. In PS > Add-PSsnapIn TheNamePropertyOfSnapInInstallClass
我现在的感觉是,微软会他内部产品的Powershell支持写成Module的形式,
因为module比snapin包含更多的东西
比如IIS 7.5 的Module webadministration
Win2k8R2 的Module ServerManager
[On Win2k8 R2]
Import-Module ServerManager
Get-WindowsFeature Add-WindowsFeature
Add-type -path (“.\somepath\somedll.dll”)
Import-Module webadministration cd IIS:
<#
Powershell have 3 type of invocations
1. & #Script base?
2. . #Script base?
3. Abs path or related path or iex #Direct invocation
#>
if ($MyInvocation.InvocationName -eq ‘&’)
{
“Called using operator”;
}
elseif ($MyInvocation.InvocationName -eq ‘.’)
{
“Dot sourced”;
}
elseif ((Resolve-Path -Path $MyInvocation.InvocationName).ProviderPath -eq $MyInvocation.MyCommand.Path)
{
(Resolve-Path -Path $MyInvocation.InvocationName).ProviderPath
$MyInvocation.MyCommand.Path;
“Called using path $($MyInvocation.InvocationName)”;
}
(pwd).path;
iex “cmd /c pause”;
<#
Now… as trivial as this looks… this function is truly amazing.
It not only has the ability to take a parameter,
but it can also take a pipe (pipe is explained below.)
#>
Function Foo
{
Param([string]$name)
Begin
{
# Only gets process at the Beginning
# Normally include Variable creation and functions
Write-Host “At Starting $name”
}
Process
{
# Gets process for each object in the pipe (if ones exist)
if($_){Write-Host “Process $_”}
}
End
{
# Always get processed once at the end
if($name){Write-Host “At End $name”}
}
}
“Calling by param”
Foo “YesName”;
“Calling by pipe and param”
@(“Panda1″,“Panda2″,“Panda3″) | Foo “YesName”
[Emacs 用指定编码读文件]
C-x RET c utf-8 RET C-x C-f
[Emacs 用指定编码写文件]
C-x C-m f utf-8 RET # 即可把当前文件转换为 utf-8 编码
C-x C-m c <encoding> RET C-x C-w # 即可把当前文件转换为 utf-8 编码,并且另存为
请参看 http://www.emacswiki.org/cgi-bin/wiki/ChangingEncodings
Powershell 函数调用时的参数格式,特别注意加粗的部分
PS D:\Workplace\001> function PFunc($a,$b){echo “Argu1=$a; Argu2=$b”}
PS D:\Workplace\001> PFunc 232 4343 434
Argu1=232; Argu2=4343
PS D:\Workplace\001> PFunc “232 4343″ 434
Argu1=232 4343; Argu2=434
PS D:\Workplace\001> PFunc (“232 4343″ 434)
Unexpected token '434' in expression or statement.
At line:1 char:22
+ PFunc ("232 4343" 434 <<<< )
+ CategoryInfo : ParserError: (434:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
PS D:\Workplace\001> PFunc (“232 4343″, 434)
Argu1=232 4343 434; Argu2=
阅读全文…
[Invoke traditional commands from Powershell]
- 1. for these commands are already located on $env:path
- You can directly input the command ddke following
- Sample >Notepad
- 2. for these commands which aren’t located on $env:path
- You need input the absolute path for it
- Sample >c:\windows\microsoft\wordpad.exe
- Sample >.\test.htm
- Sample >& “c:\programs\Windows NT\accessories\wordpad.exe”
- 3. for these built-in command you need use “cmd /c” before it
- Sample >cmd /c echo hello world
- 4. add the path to $env:path
- Sample >$env:path += “;C:\programs\Windows NT\accessories”
- Sample >wordpad.exe
阅读全文…
1. CMD Batch (*.cmd, *.bat)
(a). 双引号
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -Command “. “”C:\SCOnline\Support\ScoPowerShellSnapin\Wave C\CssShellSnapin.ps1″”"
(b). 回车符
echo “`nNew line start”
2. Powershell (*.ps1)
$msg = “`nPS”