博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hash Table构建
阅读量:6463 次
发布时间:2019-06-23

本文共 2856 字,大约阅读时间需要 9 分钟。

 

1 get-item e:\test\* |format-table @{name="aa";expression={
$_.name.tostring().split(".")[1]}} 2 3 4 5 get-childitem e:\test\* |select name,@{name="changdu";expression={
$_.name.length}},lastwritetime |format-table -autosize 6 7 8 9 Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName . | 10 Format-Table deviceid,@{Label="free(GB)"; Expression={
$_.freespace/1024/1024/1024}},@{Label="size(GB)"; Expression={
$_.size/1024/1024/1024}} -AutoSize | Out-String

 

 

 ================================================================

Hash Table只能add两个属性,一个name,一个value

1 $n =$null2 $n = [pscustomobject]@{3 Name= 'Boe'4 Number = 15 ID = 0076 }7 $n.add("p1","v1")

结果:

1 $states = @{
"Washington" = "Olympia"; "Oregon" = "Salem"; California = "Sacramento"} 2 $states.Add("Alaska", "Fairbanks") 3 $states.Remove("Alaska") 4 $states.Set_Item("Alaska", "Juneau") 5 $states.Get_Item("Oregon") 6 $states.ContainsKey("Oregon") 7 $states.ContainsValue("Salem") 8 $states | Sort-Object 9 $states.GetEnumerator() | Sort-Object Name10 11 $states.GetEnumerator() | % {
$_.name}

 结果:  只有 .name和.value 两个属性列,不能再添加其他属性列

 

1 $hash=$null 2 $hash=@{} 3 $ps = gps 4 foreach($p in $ps) 5 { 6 $hash.add($p.id,$p.processname) 7 } 8  9 $hash.getenumerator()| % {
$_.name}10 # $hash[0] 或者 $hash.getenumerator()[0] #提示出错

 结果:

===================================================

这个不是Hash Table

1 $ps = gps 2 $hashs = $null 3 $hashs = @() 4 Foreach ($p in $ps) 5     { 6      $hash = ""|Select pid,pname 7      $hash.pid = $p.ID 8      $hash.pname = $p.Processname 9      $hashs += $hash10     }11 12 $hashs[0].pid     13 $hashs.psobject|select -ExpandProperty baseobject
1 $results=@() 2 foreach ($m in $ms) 3 { 4 $result=""|select a,b,c 5 $result.a = $m.a 6 $result.b = $m.b 7 $result.c = $m.c 8 $results += $result 9 }10 $results | export-csv -encoding utf8 -notypeinformation -path c:\perc\result.csv

 

 Example1:

1 $servers="10.4.34.41","10.4.34.40","10.4.34.36"#,"10.4.34.37","10.4.34.39" 2 $results = @()  3 foreach ($c in $servers) 4 { 5 $serverpass="Dell1950" 6 $UserName="Administrator" 7 $Password = ConvertTo-SecureString $serverpass -AsPlainText –Force 8 $cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) 9 $cs = gwmi win32_computersystem -computer $c -Credential $cred10 $sys = gwmi win32_operatingsystem -computer $c -Credential $cred11 12 $result=""|select name,version13 $result.name = $cs.name14 $result.version =$sys.version15 $results +=$result16 }17 $results

=====================

Example2:

1 $infors = gc E:\Port-Test_htm\ports01.txt 2 $results=@() 3 foreach ($infor in $infors) 4 { 5 $a=$infor.split(",")[0] 6 $b=$infor.split(",")[1] 7 $result=""|select name,port 8 $result.name = $a 9 $result.port = $b10 $results += $result11 }12 $results

 

转载于:https://www.cnblogs.com/dreamer-fish/p/3451811.html

你可能感兴趣的文章
[LintCode] Longest Substring Without Repeating Characters
查看>>
in-list expansion
查看>>
设计原则(四):接口隔离原则
查看>>
CSS3常见问题:100vh在移动浏览器中不是固定的,恒定的
查看>>
基于react的滑动图片验证码组件
查看>>
用户认证系统
查看>>
iOS快速清除全部的消息推送
查看>>
ecshop二次开发攻略
查看>>
【算法学习笔记】贪心算法
查看>>
java单例模式深度解析
查看>>
什么是堆、栈?
查看>>
记录一次axios的封装
查看>>
【学习笔记】阿里云Centos7.4下配置Nginx
查看>>
VuePress手把手一小時快速踩坑
查看>>
dnsmasq安装使用和体验
查看>>
学习constructor和instanceof的区别
查看>>
用docker容器来制作nginx镜像
查看>>
关于分布式系统
查看>>
枚举类
查看>>
封装之--JAVA中的访问修饰符(区别于.NET)
查看>>