小编Job*_*Job的帖子

无法识别函数 Get-IniContent - PowerShell 中的 INI 文件支持

我想编辑INI文件的值。我使用这个脚本,但它给了我错误。

Get-IniContent : The term 'Get-IniContent' is not recognized as the name of a 
cmdlet, function, script file, or operable program.
Run Code Online (Sandbox Code Playgroud)

我的 INI 文件的内容位于c:\Users\file.ini:

[XXX]
AB=23
BC=34
Run Code Online (Sandbox Code Playgroud)

用于读取和更新脚本的内容:

# Read the content of an *.ini file into a (nested) hashtable.
$ini = Get-IniContent "C:\Users\file.ini"

# Update the 'AB' entry in section [XXX] in-memory.
$ini["XXX"]["AB"] = "12"  

# Write the updated content back to the *.ini file.
$ini | Out-IniFile -FilePath "C:\Users\file.ini -Force"
Run Code Online (Sandbox Code Playgroud)

powershell ini

3
推荐指数
1
解决办法
1万
查看次数

如何从命令行调用PowerShell脚本中的特定函数?

我想从命令行调用 powershell 脚本中的特定函数。但它返回给我这样的错误:键不能为空。

参数名称:键
$Get = $ini_file.($a_section).($b_node)

键不能为空。
参数名称:键
$输出 = $ini_file.($a_section).($b_node) | 输出文件 $Store\Val ...

这是我的代码:

Param(
    [Parameter(Mandatory=$true)]
    [string]$FilePath,
    $ini, $a_section, $b_node, $c_store,
    $a, $b, $c
)

function Get-File {
    $input_file = $FilePath
    $ini_file = @{}

    Get-Content $input_file | ForEach-Object {
        $_.Trim()
    } | Where-Object {
        $_ -notmatch '^(;|$)'
    } | ForEach-Object {
        if ($_ -match '^\[.*\]$') {
            $section = $_ -replace '\[|\]'
            $ini_file[$section] = @{}
        } else {
            $key, $value = $_ -split '\s*=\s*', 2
            $ini_file[$section][$key] = $value …
Run Code Online (Sandbox Code Playgroud)

powershell ini command-line

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

ini ×2

powershell ×2

command-line ×1