随笔分类 - Powershell--String
摘要:从网上拿到hosts记录,然后将它整形输出成address=/www.google.com/127.0.0.1这种格式。 第一个办法有点偷懒,只找出URL列,然后手动在最后加上IP地址。误打误撞学到了Trim的特殊之处。 第二个办法老老实实把URL列和IP列交换位置,然后输出。 将诸如"google
阅读全文
摘要:转自: http://simy88.blog.51cto.com/7370552/1683487 一、 哈希表用于AD属性修改,-add可以用于新属性的添加,-replace则可以用于属性的修改。 $custom = @{} $custom.ExtensionAttribute3= 12 $cust
阅读全文
摘要:哈希表 -> 真正的对象 1. [pscustomobject]@{'ID' = 'ZhangSan'; 'Age' = 23} 2. New-Object -TypeName PSObject -Property @{'ID' = 'ZhangSan'; 'Age' = 23} 字符串 -> 数组
阅读全文
摘要:FunctionDescriptionExampleCompareTo()Compares one string to another("Hello").CompareTo("Hello")Contains()Returns "True" if a specified comparison string is in a string or if the comparison string is e...
阅读全文
摘要:字符串(头上的@"必须单独一行, 末尾的"@必须顶格写):$string = @" I am a stringagain"@ 数组:$array = @( 'I am array[0]' 'I am array[1]') 或者:$array = 1, 'element', 3 哈希表:$ht = @
阅读全文
摘要:$a = 348 "{0:N2}" -f $a "{0:D8}" -f $a "{0:C2}" -f $a "{0:P0}" -f $a "{0:X0}" -f $a 348.00 00000348 ¥348.00 34,800% 15C 参考: https://msdn.microsoft.com
阅读全文
摘要:求B的补集:$A = 1, 2, 3, 4$B = 2,4$A | where {$B -notcontains $_}求A,B的交集:$A = 1, 2, 3, 4$B = 2,4$A | where {$B -contains $_}求A,B的全集:$A = 1, 2, 3, 4$B = 2, ...
阅读全文
摘要:1. "abcd" -replace "a", "x"xbcd2. "abcd" -replace "bc"ad3. "aaabcde" -replace "^a*"bcde4. "dfaq-adfdfsafd-asdfadf" -replace "-.*-","-xxx-"dfaq-xxx...
阅读全文
摘要:"abc" + "def" => abcdef "abc" * 3 => abcabcabc -Join(一元联接运算符): 一元联接运算符 (-join <string[]>) 的优先级高于逗号。因此,如果向一元联接运算符提交逗号分隔的字符串列表,则只有第一个字符串(第一个逗号之前的部分)才会提交
阅读全文
摘要:1.$number= 68'{0:d7}' -f $number2.$number1= '68'$number1.PadLeft(7,'0')
阅读全文
摘要:1. 取字符串中的某些值a. $a = '123456789' $a.substring($a.length - 3, 3)789b. '123456'.Substring(3, 2)452. 移除字符串前后的空格a.$text = ' Hello '$text.Trim()b. 移除字符串...
阅读全文
摘要:-Split:(-cSplit 区分大小写) 一元拆分运算符 (-split <string>) 的优先级高于逗号。因此,如果向一元拆分运算符提交逗号分隔的字符串列表,将只拆分第一个字符串(第一个逗号之前的部分)。要拆分多个字符串,请使用二元拆分运算符 (<string> -split <delim
阅读全文