为什么可以';我不能在批处理文件中运行此powershell脚本吗?
因此,当我在powershell ise上以管理员身份运行此脚本时,它可以完美地工作为什么可以';我不能在批处理文件中运行此powershell脚本吗?,powershell,batch-file,Powershell,Batch File,因此,当我在powershell ise上以管理员身份运行此脚本时,它可以完美地工作 $ComputerSystem = Get-WmiObject -ClassName Win32_ComputerSystem $ComputerSystem.AutomaticManagedPagefile = $false $ComputerSystem.Put() $PageFileSetting = Get-WmiObject -ClassName Win32_PageFileSetting $Page
$ComputerSystem = Get-WmiObject -ClassName Win32_ComputerSystem
$ComputerSystem.AutomaticManagedPagefile = $false
$ComputerSystem.Put()
$PageFileSetting = Get-WmiObject -ClassName Win32_PageFileSetting
$PageFileSetting.InitialSize = 12000
$PageFileSetting.MaximumSize = 32000
$PageFileSetting.Put()
但是当我运行下面的批处理文件来运行脚本时,它不起作用。我做错了什么
powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file "Memory.ps1"
试图改变这一点
对此您可能可以使用a中的这两行,而不必考虑:
@%\uuuuu AppDir\uuuuu%wbem\WMIC.exe ComputerSystem,其中“名称=“%ComputerName%”设置AutomaticManagedPagefile=False
@%__AppDir\uuu%wbem\WMIC.exe页面文件集,其中“Name='C:\\pagefile.sys'”设置InitialSize=12000,MaximumSize=32000
如果需要,您甚至可以使用
/User
和/Password
选项运行这两行代码。您可能会使用a中的这两行代码,而忘记:
@%\uuuuu AppDir\uuuuu%wbem\WMIC.exe ComputerSystem,其中“名称=“%ComputerName%”设置AutomaticManagedPagefile=False
@%__AppDir\uuu%wbem\WMIC.exe页面文件集,其中“Name='C:\\pagefile.sys'”设置InitialSize=12000,MaximumSize=32000
如果需要,您甚至可以使用
/User
和/Password
选项运行这两行。请展开“它不工作”-是否引发错误?出口代码是什么?电脑着火了吗?:)@由于您显然没有调用提升的powershell脚本,我假设您以管理员身份运行批处理文件,对吗?那么回到最初的评论,“请展开“它不工作”。我这样问是因为我的假设是,为了让新设置正常工作,您需要重新启动系统。另外,您可能会使用批处理文件中的这两行代码,而忘记powershell:@%\uuuuuu AppDir\uuuu%wbem\WMIC.exe ComputerSystem,其中“Name='%ComputerName%'”设置AutomaticManagedPagefile=False
,而@%\uuuuuuuu AppDir\uuuwbem\WMIC.exe PageFileSet,其中“Name='C:\\pagefile.sys'。设置InitialSize=12000,MaximumSize=32000
。如果需要,您甚至可以使用/User
和/Password
选项运行这两行。我只给了你一个批处理文件@randomguy2443,我只是提供了所有的行(总共两行),就可以了!我现在添加了这些作为回答,请扩展到“它不工作”-是否抛出了错误?出口代码是什么?电脑着火了吗?:)@由于您显然没有调用提升的powershell脚本,我假设您以管理员身份运行批处理文件,对吗?那么回到最初的评论,“请展开“它不工作”。我这样问是因为我的假设是,为了让新设置正常工作,您需要重新启动系统。另外,您可能会使用批处理文件中的这两行代码,而忘记powershell:@%\uuuuuu AppDir\uuuu%wbem\WMIC.exe ComputerSystem,其中“Name='%ComputerName%'”设置AutomaticManagedPagefile=False
,而@%\uuuuuuuu AppDir\uuuwbem\WMIC.exe PageFileSet,其中“Name='C:\\pagefile.sys'。设置InitialSize=12000,MaximumSize=32000
。如果需要,您甚至可以使用/User
和/Password
选项运行这两行。我只给了你一个批处理文件@randomguy2443,我只是提供了所有的行(总共两行),就可以了!我现在已经添加了这些作为答案