Я хочу выполнить свой скрипт с командной строкой. Я использую функцию внутри моего скрипта.
Я использовал этот скрипт:
Function Get-IniFile
{
Param(
[parameter(mandatory=$true)][string]$FilePath
)
$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
}
}
$Get = $ini_file.Class.Amount
$Get
}
Я выполняю этот скрипт из командной строки с помощью этой команды:
PowerShell.ps1 Get-IniFile -FilePath
Я не получаю никакого результата при выполнении этого кода, но если я удалю «Function Get-IniFile
», я получу значение Amount.
Это мой INI-файл
[Class]
Amount = 1000
Feature = 20
[Item]
Set = 100
Return = 5