本文介绍了带功能的Powershell脚本无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的脚本使用函数。如果我使用的功能不起作用,但如果不使用功能正在工作。
INI文件:
[姓名]
Joyce = 2006
詹姆斯= 1102
我尝试了什么:
此代码无功能
Param(
[参数(强制= $ true)]
[string] $ FilePath,
$ a,
$ b ,
$ c
)
导入模块PsIni
$ ff = Get-IniContent $ FilePath
$ ff [$ a] [$ b] =$ c
$ ff | Out-IniFile -FilePath $ FilePath -Force
我从命令行运行:
PS.ps1 -FilePath C:\ Users \ file.ini -a名称-b Joyce -c 1309
此函数代码不起作用:
函数Write-IniFile {
Param(
[参数(强制性) = $ true)]
[string] $ FilePath,
$ a,
$ b,
$ c
)
Import-Module PsIni
$ ff = Get-IniContent $ FilePath
$ ff [$ a] [$ b] =$ c
$ ff | Out-IniFile -FilePath $ FilePath -Force
}
Write-File -FilePath $ FilePath -a $ a -b $ b -c $ c
我从命令行运行:
PS.ps1 Write-IniFile -FilePath C:\ Users \ file.ini -a名字-b Joyce -c 1309
解决方案
I want to use function for my script. If I use function is not working, but if it is not using function is working.
The INI file:
[Name]
Joyce=2006
James=1102
What I have tried:
This code without function works
Param( [Parameter(Mandatory=$true)] [string]$FilePath, $a, $b, $c ) Import-Module PsIni $ff = Get-IniContent $FilePath $ff["$a"]["$b"] = "$c" $ff | Out-IniFile -FilePath $FilePath -Force
I run this from the command line:
PS.ps1 -FilePath C:\Users\file.ini -a Name -b Joyce -c 1309
This code with function does not work:
function Write-IniFile { Param( [Parameter(Mandatory=$true)] [string]$FilePath, $a, $b, $c ) Import-Module PsIni $ff = Get-IniContent $FilePath $ff["$a"]["$b"] = "$c" $ff | Out-IniFile -FilePath $FilePath -Force } Write-File -FilePath $FilePath -a $a -b $b -c $c
I run this from the command line:
PS.ps1 Write-IniFile -FilePath C:\Users\file.ini -a Name -b Joyce -c 1309
解决方案
这篇关于带功能的Powershell脚本无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!