PowerTip of the Day from powershell.com上周汇总(三)

 

降低进程优先级

Lowering Process Priority

http://app.en25.com/e/es.aspx?s=1403&e=7006&elq=d22c2238899d4fc7a2952a7e42ab8c81

以下命令将当前进程中为notepad的(记事本)的进程优先级降低为BelowNormal。默认进程的优先级为Normal。

Get-Process notepad | ForEach-Object { $_.PriorityClass = "BelowNormal" }

 

 

添加新的事件日志源

&

写入日志

Adding New Event Log Sources

&

Writing Your Own Event Log Entries

http://app.en25.com/e/es.aspx?s=1403&e=7042&elq=f238ef0ee41f4a8cb5ecbd049488bfd1

&

http://app.en25.com/e/es.aspx?s=1403&e=7110&elq=dd228c9d63244a3a99a5d9b652ec047f

如果要使用事件日志首先需要注册一个,需要确认执行的账户具有管理员权限。

New-EventLog Application PowerShellScripts

注册完毕之后就可以用以下的方法写入日志:

Write-EventLog -LogName Application -Source PowerShellScripts -EntryType Warning -EventId 12345 -Message 'This is my message'

日志是写在操作系统下的。

 

 

查看用户桌面的文件夹目录

Finding a User's Desktop Folder

http://app.en25.com/e/es.aspx?s=1403&e=7183&elq=bd457dddf07d405abb3b8936a1d71895

主要通过.NET下的Environment类来获取:

[Environment]::GetFolderPath("Desktop")

另外通过下列命令可以获得所有能获得到的目录:

[Enum]::GetNames([System.Environment+SpecialFolder])

 

 

操作Path下的方法

Working with Path Names

http://app.en25.com/e/es.aspx?s=1403&e=7247&elq=199d2ebb698c4ca28036d31a85661fa5

.NET下的System.IO.Path类拥有很多有用的静态方法,通过下列命令可以获取支持的方法列表:

[System.IO.Path] | Get-Member –Static

下面的方法演示如何更改一个文件的扩展名:

[System.IO.Path]::ChangeExtension("test.txt", "ps1")

 

 

 

以上来自powershell.com

2010年八月份2日到6日的PowerTip of the Day

posted @ 2010-08-10 10:38  哥本哈士奇(aspnetx)  阅读(351)  评论(0编辑  收藏  举报