2015-11-01 47 views
0

当我把Function {}放在我的powershell脚本上时,要更改注册表项,脚本似乎不在括号内运行。当我取出Function {}时,脚本运行良好。我在这里错过了什么?Powershell脚本 - 通过函数组织脚本

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

'Function'刚刚创建(不执行)功能。 – PetSerAl

+0

如何执行该功能?我大概有十个,我会一个接一个。 –

+0

如何在脚本中调用你的函数?当你打电话给“ClearePageFile”会发生什么? – kekimian

回答

0

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

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

#call the function 
ClearPageFile