PowerShell学习笔记
1,ps7官方文档
function Add-Node {
param (
$selectedNode,
$name,
$tag
)
$newNode = new-object System.Windows.Forms.TreeNode
$newNode.Name = $name
$newNode.Text = $name
$newNode.Tag = $tag
$selectedNode.Nodes.Add($newNode) | Out-Null
return $newNode
} function Get-HelpTree {
if ($script:cmdletNodes)
{
$treeview1.Nodes.remove($script:cmdletNodes)
$form1.Refresh()
}
$script:cmdletNodes = New-Object System.Windows.Forms.TreeNode
$script:cmdletNodes.text = "PowerShell Help"
$script:cmdletNodes.Name = "PowerShell Help"
$script:cmdletNodes.Tag = "root"
$treeView1.Nodes.Add($script:cmdletNodes) | Out-Null $treeView1.add_AfterSelect({
if ($this.SelectedNode.Tag -eq "Cmdlet") {
$helpText = Get-Help $this.SelectedNode.Name -Full
$richTextBox1.Text = $helpText | Out-String
$linkLabel1.Text = $helpText.relatedLinks.navigationLink[0].uri
$form1.refresh()
} else {
$richTextBox1.Text = "Example to show how to use TreeView control in PowerShell script"
$linkLabel1.Text = "http://www.ravichaganti.com/blog"
}
}) #Generate Module nodes
$modules = @("Microsoft.PowerShell.Core","Microsoft.PowerShell.Diagnostics","Microsoft.PowerShell.Host","Microsoft.PowerShell.Management","Microsoft.PowerShell.Security","Microsoft.PowerShell.Utility") $modules | % {
$parentNode = Add-Node $script:cmdletNodes $_ "Module"
$moduleCmdlets = Get-Command -Module $_
$moduleCmdlets | % {
$childNode = Add-Node $parentNode $_.Name "Cmdlet"
}
}
$script:cmdletNodes.Expand()
} #Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.7.0
# Generated On: 3/2/2010 5:46 PM
# Generated By: Ravikanth Chaganti (http://www.ravichaganti.com/blog)
######################################################################## #region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion #region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$linkLabel1 = New-Object System.Windows.Forms.LinkLabel
$label4 = New-Object System.Windows.Forms.Label
$label3 = New-Object System.Windows.Forms.Label
$label2 = New-Object System.Windows.Forms.Label
$button1 = New-Object System.Windows.Forms.Button
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$treeView1 = New-Object System.Windows.Forms.TreeView
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects #----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick=
{
$form1.Close() } $OnLoadForm_StateCorrection=
{Get-HelpTree
} $linkLabel1_OpenLink=
{
[system.Diagnostics.Process]::start($linkLabel1.text)
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 838
$System_Drawing_Size.Height = 612
$form1.ClientSize = $System_Drawing_Size $linkLabel1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,0,3,0)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 539
$System_Drawing_Size.Height = 23
$linkLabel1.Size = $System_Drawing_Size
$linkLabel1.TabIndex = 10
$linkLabel1.Text = "http://www.ravichaganti.com/blog"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 541
$linkLabel1.Location = $System_Drawing_Point
$linkLabel1.TabStop = $True
$linkLabel1.DataBindings.DefaultDataSourceUpdateMode = 0
$linkLabel1.Name = "linkLabel1"
$linkLabel1.add_click($linkLabel1_OpenLink) $form1.Controls.Add($linkLabel1) $label4.TabIndex = 9
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 136
$System_Drawing_Size.Height = 23
$label4.Size = $System_Drawing_Size
$label4.Text = "Cmdlet Help URI"
$label4.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 518
$label4.Location = $System_Drawing_Point
$label4.DataBindings.DefaultDataSourceUpdateMode = 0
$label4.Name = "label4" $form1.Controls.Add($label4) $label3.TabIndex = 6
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$label3.Size = $System_Drawing_Size
$label3.Text = "Description"
$label3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 255
$System_Drawing_Point.Y = 37
$label3.Location = $System_Drawing_Point
$label3.DataBindings.DefaultDataSourceUpdateMode = 0
$label3.Name = "label3" $form1.Controls.Add($label3) $label2.TabIndex = 5
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 177
$System_Drawing_Size.Height = 23
$label2.Size = $System_Drawing_Size
$label2.Text = "PowerShell Help Tree"
$label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$label2.Location = $System_Drawing_Point
$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Name = "label2" $form1.Controls.Add($label2) $button1.TabIndex = 4
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True $button1.Text = "Close" $System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 577
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick) $form1.Controls.Add($button1) $richTextBox1.Name = "richTextBox1"
$richTextBox1.Text = ""
$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 255
$System_Drawing_Point.Y = 61
$richTextBox1.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 562
$System_Drawing_Size.Height = 454
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 1 $form1.Controls.Add($richTextBox1) $System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 224
$System_Drawing_Size.Height = 563
$treeView1.Size = $System_Drawing_Size
$treeView1.Name = "treeView1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 37
$treeView1.Location = $System_Drawing_Point
$treeView1.DataBindings.DefaultDataSourceUpdateMode = 0
$treeView1.TabIndex = 0 $form1.Controls.Add($treeView1) #endregion Generated Form Code #Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null } #End Function #Call the Function
GenerateForm
3,查看命令帮助:man get-filehash / get-help get-filehash
4,get-filehash
1, 获取文件MD5
get-filehash xxx.txt -Algorithm MD5
2, 获取字符串MD5: 需要自定义函数实现, 这里的函数有些问题,比如例子中得出的“123456”的MD5值和实际不同:实际:E10ADC3949BA59ABBE56E057F20F883E答案:E1ADC3949BA59ABBE56E057F2F883E少了2位,当然也不是全部的0都去掉了。原因是字节转换成字符串的时候没有保证是2位宽度造成的,待研究。
function Get-Hash{
param(
[string] $string = $(throw 'string is required'),
[ValidateSet("MD5", "SHA256")]
[string] $algorithm
) $utf8 = new-object -TypeName System.Text.UTF8Encoding
$hasher = [System.Security.Cryptography.HashAlgorithm]::create($algorithm)
$hash = $hasher.ComputeHash($utf8.GetBytes($string)) -join ( $hash | foreach {"{0:X}" -f $_} )
} Get-Hash '123456' -algorithm MD5
Get-Hash '123456' -algorithm SHA256
5,
6,
PowerShell学习笔记的更多相关文章
- Powershell 学习笔记【持续更新】
1. 判断一个对象是不是空可以用 $null来比较 2. 判断一个字符串是不是空的: [string]::IsNullOrEmpty(...) 3. 在powershell中把结果输出为一个CSV格式 ...
- [Windows Powershell]-学习笔记(6)
Powershell环境变量 传统的控制台一般没有象Powershell这么高级的变量系统.它们都是依赖于机器本身的环境变量,进行操作 .环境变量对于powershell显得很重要,因为它涵盖了许多操 ...
- [Windows Powershell]-学习笔记(5)
Powershell自动化变量 Powershell 自动化变量 是那些一旦打开Powershell就会自动加载的变量,或者说是运行是变量. 这些变量一般存放的内容包括 用户信息:例如用户的根目录$h ...
- [Windows Powershell]-学习笔记(4)
Powershell 定义变量 在powershell中变量名均是以美元符"$"开始,剩余字符可以是数字.字母.下划线的任意字符,并且powershell变量名大小写不敏感($a和 ...
- [Windows Powershell]-学习笔记(3)
Powershell 通过函数扩展别名 在powershell中设置别名的确方便快捷,但是在设置别名的过程中并设置参数的相关信息,尽管别名会自动识别参数,但是如何把经常使用的参数默认设定在别名里面呢? ...
- [Windows Powershell]-学习笔记(2)
数学运算 我们可以把powershell当成一个计算器.如键入命令行那样输入数学表达式,回车,powershell会自动计算并把结果输出.常用的加减乘除模(+,-,*,/,%)运算和小括号表达式都支持 ...
- [Windows Powershell]-学习笔记(1)
Powershell 快捷键 Powershell的快捷键和cmd,linux中的shell,都比较像. ALT+F7 清除命令的历史记录 PgUp PgDn 显示当前会话的第 ...
- Powershell学习笔记:(二)、基础知识
从Window7以后,WIndows系统都自带了Windows PowerShell. 自带版本如下 WIndow7 2.0 WIndow8 3.0 Window8.1 4.0 Win ...
- Powershell学习笔记:(一)、初识Powershell
什么是Powershell? MSDN上的说明是:PowerShell 是构建于 .NET 上基于任务的命令行 shell 和脚本语言. PowerShell 可帮助系统管理员和高级用户快速自动执行用 ...
随机推荐
- VC检测内存泄漏(Detected memory leaks!)
Detected memory leaks!Dumping objects ->{98500} normal block at 0x05785AD0, 152 bytes long.Data: ...
- 20180527模拟赛T1——新田忌赛马
[问题描述] (注:此题为d2t2-难度) 田忌又在跟大王van赛马的游戏 田忌与大王一共有2n匹马,每个马都有一个能力值x,1<=x<=2n且每匹马的x互不相同.每次田忌与大王放出一匹马 ...
- 数据库join解释 与视图
数据库的视图是表运算的结果. 数据库的表是数据单元: join是运算符: 视图是运算结果. 数据库join解释 1.join:将两个表结构连接成一个视图 2.left.right.inner: 从基准 ...
- 使用plotly dash-component-boilerplate 生成自己的组件
plotly 基于dash-component-boilerplate给我们提供了可以快速生成基于使用python 调用的react 组件 以下是一个简单的使用脚手架生成一个组件,同时可以了解组件的工 ...
- 鸿蒙OS与手机系统
鸿蒙发布会上,华为只是说手机端能很快切换到鸿蒙上,但并没有将切换到手机端放到计划表.如果不出意外,手机会是最后用上鸿蒙的终端,尽管它是现在对人们最重要.应用最多.也是人们讨论最多希望鸿蒙迁移到的终端. ...
- 洛谷P4170 [CQOI2007]涂色题解
废话: 这个题我第一眼看就是贪心呐, 可能是我之前那做过一道类似的题这俩题都是关于染色的 现在由于我帅气无比的学长的指导, 我已经豁然开朗, 这题贪心不对啊, 当时感觉自己好厉害贪心都能想出来 差点就 ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 分组加密器(encryption)
分组加密器(encryption) 题解点这里 #include<map> #include<stack> #include<vector> #include< ...
- socket数据传输
目录 subprocess模块 struct模块: 粘包问题: QQ聊天的实现: 文件的传输: 大文件的传输: 传输层协议: TCP : UDP: FTP: socketServer模块: subpr ...
- [WEB安全]源码泄露总结
原文链接:https://blog.csdn.net/qq_36869808/article/details/88895109 源码泄露总结: svn源码泄露:https://blog.csdn.ne ...
- 在 Ubuntu/Debian 下安装 PHP7.3 教程
介绍 最近的 PHP 7.3.0 已经在 2018 年12月6日 发布 GA,大家已经可以开始第一时间体验新版本了,这里先放出 PHP7.3 安装的教程以便大家升级. 适用系统: Ubuntu 18. ...