在ServerCore下通过以下脚本可以加载、卸载ISCSI设备,脚本内容如下:
Write-Host “
##########################################################”
Write-Host ” #
0、按顺序执行所有操作;
#” -ForegroundColor Green
Write-Host ” #
1、启动服务器ISCS服务,并设置为自动;
#”
Write-Host ” #
2、管理ISCS设备;
#”
Write-Host ” #
3、磁盘加载(创建基本磁盘并设置为主分区);
#”
Write-Host ” #
########################################################”
$Check = Read-Host “请选择您要执行的操作(输入编号即可)”
if(($Check -eq 0) -or ($Check -eq 1))
{
Set-service msiscsi -StartupType Automatic -status
Running
}
if(($Check -eq 0) -or ($Check -eq 2))
{
$iscsOperation = Read-Host “请选择对ISCS设备的操作方式(ADD 添加、DEL
移除)”
if($iscsOperation -eq “add”)
{
$iscsIP = Read-Host “请输入ISCS设备IP地址”
iscsicli qaddtargetportal $iscsIP
iSCSIcli ListTargets
$TargetIQN = Read-Host “请输入需连接设备的IQN地址”
iSCSIcli QloginTarget $TargetIQN
iSCSIcli PersistentLoginTarget $TargetIQN T * *
* * * * * * * * * * * * * 0
}
else
{
#iscsicli ListPersistentTargets
#iscsicli RemovePersistentTarget $iscsIP
$iscsPort
iscsicli ListTargetPortals
$iscsIP = Read-Host “请输入ISCS设备地址和套接字”
$iscsPort = Read-Host “请输入ISCS设备端口号”
iscsicli RemoveTargetPortal $iscsIP
$iscsPort
}
}
if(($Check -eq 0) -or ($Check -eq 3))
{
“List disk” | diskpart #列举当前所有逻辑磁盘
$SelectDisk = Read-Host “请选择需要进行加载的逻辑磁盘”
“Select Disk $SelectDisk `r ATTRIBUTES DISK CLEAR
READONLY `r Online Disk `r CONVERT BASIC `r CREATE PARTITION
PRIMARY” | diskpart
“List VOLUME” | diskpart #列举当前所有逻辑卷
$SelectVolume = Read-Host “请选择需要进行加载的逻辑卷”
$DiskLable = Read-Host “请输入磁盘卷名”
$SelectASSIGN = Read-Host “请为逻辑卷分配一个驱动器号”
“SELECT VOLUME $SelectVolume `r FORMAT FS=NTFS
LABEL=$DiskLable QUICK `r ASSIGN LETTER=$SelectASSIGN” |
diskpart
}
来源URL:http://blog.sina.com.cn/s/blog_6295a25a0100mk71.html