天天看点

Powershell与运维之系统管理(一)磁盘管理

对于Windows管理来说视图话的磁盘管理工具大家已经习惯使用了,查看磁盘和分区大小,创建分区、格式化、管理Raid等等是磁盘管理常用的一些操作。但是如果你的Windows服务器规模足够大的话,虽然现版本的大多数可视化控制台都已经支持远程管理,但是在做一些服务器磁盘的批量操作或针对磁盘自定义监控的时候依然是不方便的。

所以Powershell针对磁盘的管理对一个Windows运维工程师来说显的尤为重要,下面就通过几个例子来学习一下:

1 获取磁盘和分区参数

在Powershell4.0之前没有关于磁盘管理的专用cmdlets,所以只能通过WMI来获取:

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115007Pba2.png" target="_blank"></a>

获取所有类型分区:

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115007kCWi.png" target="_blank"></a>

获取某个分区:

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_14091150086ESW.png" target="_blank"></a>

其实这些都不是我们需要的,我们只要最终的分区结果数值。

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115008j9Hp.png" target="_blank"></a>

但是这个数值看着太大了我们直接通过数学计算它处理成GB单位,

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115009LzFQ.png" target="_blank"></a>

但Powershell有更人性化的功能,不用去做那些无聊的单位换算。

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115018Zafb.png" target="_blank"></a>

虽然3.0之前的Powershell能获取到一些磁盘的参数,但实际的管理比如Raid或者给磁盘分区还需要依靠原有的命令行工具。但

Powershell4.0之后增加了专有的磁盘管理的cmdlets和Function,磁盘的类型可以支持VirtualDISK和ISCSI存储等并且依然支持早起的命令行的磁盘管理工具。

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115019Na16.png" target="_blank"></a>

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115021q4K9.png" target="_blank"></a>

参数获取更加方便:

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115022s79O.png" target="_blank"></a>

二 远程计算机的磁盘管理。关于Windows的Powershell远程管理现在是Windows自动化最好的工具,尤其是借助Windows的活动目录实现的kerberos验证后变的更加方便。所以这个功能我会在接下来一系列文章里都会提到。

powershell 4.0之前:

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115023TVRN.png" target="_blank"></a>

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115247s6k1.png" target="_blank"></a>

Powershell 4.0:

<a href="http://lixiaosong.blog.51cto.com/attachment/201408/27/705126_1409115025lF2F.png" target="_blank"></a>

本文转自handsome7038 51CTO博客,原文链接:http://blog.51cto.com/lixiaosong/1545572

继续阅读