V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
sx90

必须马克, PowerShell function 太坑了

  •  
  •   sx90 · Jan 2, 2020 · 660 views
    This topic created in 2307 days ago, the information mentioned may be changed or developed.

    About Functions


    这个坑,浪费我一天时间,才填上,蛋疼

    先上错误代码:

    #函数
    function Write-Ini  ($IniKey, $Value)
    {
     $Section = "关机";
     $FilePath = "$PSScriptRoot\Site.ini";
     $Null = [IniFileManager]::WriteToIniFile($FilePath, $Section, $IniKey, $Value); 
    };
    
    #调用
    Write-Ini ( "DownloadSpeed", $dlShutdown);
    

    玩了这么多的鹰,自认为这样写没毛病,可惜他狠狠的啄了我一脸,ini 输出为:

    [关机]
    DownloadSpeed 600=
    

    然后就疯狂改代码,疯狂找资料,各种吐血行为,差点想自编一个算了,最后认认真真拜读微软文档后,才发现我调用出错了

    修改后:

    function Write-Ini
    {
      param ([string]$IniKey, [string]$Value);
      $Section = "关机";
      $FilePath = "$PSScriptRoot\Site.ini";
      $Null = [IniFileManager]::WriteToIniFile($FilePath, $Section, $IniKey, $Value); 
    };
    
    Write-Ini -IniKey "DownloadSpeed" -Value $dlShutdown;
    

    撒花完结,睡觉了(两天一夜没闭眼了)

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4919 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:07 · PVG 09:07 · LAX 18:07 · JFK 21:07
    ♥ Do have faith in what you're doing.