Powershell Snapin 和 Module 相关

2012年4月20日 没有评论

#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: 三种调用方式 & | dot-sourced | direct-invocation

2012年3月23日 没有评论

<#
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”;

分类: 学习笔记 标签:

Powershell 定义Function: 可以同时接受Pipe参数和Param参数

2012年3月23日 没有评论

<#
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”

分类: 学习笔记 标签:

PHP & MYSQL Study Notes 2012-02-26

2012年2月26日 没有评论
#=================================
# 2012-02-25 Saturday February
#=================================
html
<sup></sup>
#Structure informations
Files
Lists
Arrays
Records
Trees
Tables
Study PHP&MySQL
阅读全文…
分类: 学习笔记 标签: ,

Emacs用指定编码读文件和写文件

2012年2月16日 没有评论

[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 函数调用时的参数格式

2012年2月13日 没有评论

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=
阅读全文…

Powershell 环境变量的创建,修改,列举,删除

2012年2月10日 没有评论

New or Modify

  • $env:TestVar = 12  # ok
  • $env:\TestVar = 12  # error
  • env:TestVar = 12  # error
  • env:\TestVar = 12  # error

Read

  • echo “hello world $env:windir” # ok
  • echo “hello world $env:\windir” # error
  • echo “hello world env:windir” # error
  • echo “hello world env:\windir” # error

阅读全文…

Powershell 调用外部命令(exe,cmd,bat,vbs,js) 格式小结

2012年2月9日 没有评论

[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

阅读全文…

各种脚本Escape字符-总结 [持续更新...]

2012年2月6日 没有评论

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”

分类: 生活笔记 标签:

空间已从Hostmonster主机搬到icdsoft香港主机

2012年2月5日 没有评论

别了 hostmonster

分类: 生活笔记 标签: