如何执行powershell 脚本

2025-11-07 12:43:17

1、将下列命令保存为test.vbsSet wmi = GetObject("winmgmts:")Set collection = wmi.ExecQuery("select * from Win32_Process")For Each process in collectionWScript.Echo process.getObjectText_Next

执行 .\test.vbs 会遍历当前Win32进程,并把每个进程的详细信息通过窗口显示出来。

如何执行powershell 脚本

2、怎样让VB脚本的通过控制台输出呢?Wscript //H:CScript怎样还原VB脚本通过窗口输出呢?WScript //H:WScript在powershell中执行VB脚本

PS C:\PS> cscript.exe .test.vbs Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. instance of Win32_Process {        Caption = "System Idle Process";        CreationClassName = "Win32_Process";        CSCreationClassName = "Win32_ComputerSystem";        CSName = "test-me-01";        Description = "System Idle Process";        Handle = "0";        HandleCount = 0;       

如何执行powershell 脚本

3、 KernelModeTime = "484113379271";        Name = "System Idle Process";        OSCreationClassName = "Win32_OperatingSystem";        OSName = "Microsoft Windows 7 Enterprise |C:Windows|DeviceHarddisk0Partition2";        OtherOperationCount = "0";        OtherTransferCount = "0";        PageFaults = 0;        PageFileUsage = 0;        ParentProcessId = 0;        PeakPageFileUsage = 0;        PeakVirtualSize = "0";        PeakWorkingSetSize = 0;        Priority = 0;        PrivatePageCount = "0";        ProcessId = 0;     

如何执行powershell 脚本

4、   QuotaNonPagedPoolUsage = 0;        QuotaPagedPoolUsage = 0;        QuotaPeakNonPagedPoolUsage = 0;        QuotaPeakPagedPoolUsage = 0;        ReadOperationCount = "0";        ReadTransferCount = "0";        SessionId = 0;        ThreadCount = 2;        UserModeTime = "0";        VirtualSize = "0";        WindowsVersion = "6.1.7601";        WorkingSetSize = "24576";        WriteOperationCount = "0";        WriteTransferCount = "0"; };

如何执行powershell 脚本

5、执行powershell脚本

Powershell拥有自己的脚本,扩展名为“.ps1”

PS C:\PS> echo "dir;Get-PSProvider;help dir" >test.ps1 PS C:\PS> Get-Content ./test.ps1 dir;Get-PSProvider;help dir PS C:\PS> ./test.ps1

初次执行脚本时,可能会碰到一个异常:File ” C:\PS\test.ps1″ cannot be loaded because theexecution of scripts is disabled on this system. Please see“get-help about_signing” for more details.At line:1 char:10+ .test.ps1 <<<<

这是powershell的默认安全设置禁用了执行脚本,要启用这个功能需要拥有管理员的权限。

如何执行powershell 脚本

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢