powershell Powershell函数从文件中读取哈希表文本表示并将其转换为哈希表对象
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Powershell函数从文件中读取哈希表文本表示并将其转换为哈希表对象相关的知识,希望对你有一定的参考价值。
# .SYNOPSIS
# Reads and evaluates Hastable object from file
#
# .DESCRIPTION
# Reads and evaluates Hastable object from file. As example you can read Module manifest
# file (*.psd1) as Hashtable object
#
# .EXAMPLE
# PS C:> Get-Module | Where { [IO.Path]::GetExtension($_) -match '.psd1' } |
# Select -Last 1 |
# ConvertFrom-TextToHashtable | Tee-Object -Variable HashT
#
Function ConvertFrom-TextToHashtable {
($Input + $Args) |
Out-String |
Invoke-Expression
}
# Invoke as follows: & ${Get hashtable from file} '.\awesome Hashtable.txt'
${Get hashtable from file} = { PARAM($file)
Get-Content $file |
ConvertFrom-TextToHashTable
}
# Invoke as follows:
# & ${Import hashtable from file} '.\awesome Hashtable.txt' 'myVar'
# Write $myVar.userData
${Import hashtable from file} = { PARAM($file, $VarName)
& ${Get hashtable from file} $file |
Tee-object -Variable $VarName
}
以上是关于powershell Powershell函数从文件中读取哈希表文本表示并将其转换为哈希表对象的主要内容,如果未能解决你的问题,请参考以下文章
powershell REST API PowerShell函数列表
powershell PowerShell:当前脚本/函数名称(范围)
powershell Powershell字符串哈希函数。
powershell PowerShell:sendMail函数
powershell 模板powershell函数,占位符解释了Powershell中发生的高级参数绑定。用法:见里面的评论
powershell PowerShell函数用于扩展ISE和文件的别名