Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 2.0 Powershell脚本-按函数组织脚本_Powershell 2.0 - Fatal编程技术网

Powershell 2.0 Powershell脚本-按函数组织脚本

Powershell 2.0 Powershell脚本-按函数组织脚本,powershell-2.0,Powershell 2.0,当我将函数{}放在我的powershell脚本周围以更改注册表项时,脚本似乎没有在括号内运行。当我取出函数{}时,脚本运行良好。我错过了什么 Function ClearPageFile { $regpath = "HKLM:\SYSTEM....(rest of path)" $key = "ClearPageFileAtShutdown Set-ItemProperty -Path $regpath -Name $key -Value 0 } 除非你在别的地方调用函数,这

当我将函数
{}
放在我的powershell脚本周围以更改注册表项时,脚本似乎没有在括号内运行。当我取出函数{}时,脚本运行良好。我错过了什么

Function ClearPageFile   
{
  $regpath = "HKLM:\SYSTEM....(rest of path)"
  $key = "ClearPageFileAtShutdown
  Set-ItemProperty -Path $regpath -Name $key -Value 0
}

除非你在别的地方调用函数,这里是你的答案

Function ClearPageFile   
{
  $regpath = "HKLM:\SYSTEM....(rest of path)"
  $key = "ClearPageFileAtShutdown
  Set-ItemProperty -Path $regpath -Name $key -Value 0
}

#call the function
ClearPageFile

函数
只需创建(不执行)函数。如何执行该函数?我有大约十个,我会一个接一个的。你如何在你的脚本中调用你的函数?当你调用“ClearPageFile”时会发生什么?这就是我不知道该怎么做的。如果在一个脚本中有多个类似的函数,如何设置脚本以运行所有函数?