多语言展示
当前在线:146今日阅读:168今日分享:49

如何执行powershell 脚本

今天小编给大家带来的是如何执行powershell 脚本,希望能帮助到大家!
工具/原料

PC

方法/步骤
1

将下列命令保存为test.vbsSet wmi = GetObject('winmgmts:') Set collection = wmi.ExecQuery('select * from Win32_Process') For Each process in collection WScript.Echo process.getObjectText_ Next执行 .\test.vbs 会遍历当前Win32进程,并把每个进程的详细信息通过窗口显示出来。

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;

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;

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'; };

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的默认安全设置禁用了执行脚本,要启用这个功能需要拥有管理员的权限。

注意事项
1

网络虽好,但要注意劳逸结合哦!

2

如果是青少年,小编在这里提示大家千万不能沉迷网络!

推荐信息