2016-08-02 25 views
0

こんにちはドライブ名を割り当て、ドライブをフォーマットし、必要な割り当て単位サイズでドライブに貼り付けるPSスクリプトを作成しようとしました。値 ""を "System.Char"に変換できません

CSVファイル(Storage_Data_Input.txtが)のようである:

DiskNumber,DriveLetter,NewFileSystemLabel,AllocationUnitSize 
7,N,Drive_N,4096 
7,N,Drive_N,4096 

スクリプトはこのように書きます:

Cannot process argument transformation on parameter 'DriveLetter'. Cannot convert value "" to type "System.Char". Error: "String must be exactly one character long." 
+ CategoryInfo   : InvalidData: (:) [New-Partition], ParameterBindin...mationException 
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,New-Partition 
+ PSComputerName  : Servername 
+0

私はこれをテストしたhaventはしかし、私はそうどうもありがとうございました、だけではなく、「Drive_N」 – Kiran

答えて

3

をあなた場合:実行するとき

######################## 
# New Partition/Drive letter/Format/Label/Allocation 
Measure-Command{ 

Clear 


$Datalist = Import-Csv "H:\My Documents\My Powershell\Storage_Data_Input.txt" 
$ServerList = Get-Content "H:\My Documents\My Powershell\serverlist.txt" 

ForEach ($Item in $Datalist){ 
$DiskNumber=$($Item.DiskNumber) 
$driveletter=$($Item.DriveLetter) 
$NewFileSystemLabel=$($Item.NewFileSystemLabel) 
$AllocationUnitSize=$($Item.AllocationUnitSize) 


$c=Get-Credential Domain\Userid 

foreach ($ServerName in $ServerList){ 
Write-Host "Setting Drive_"$DriveLetter" on server "$ServerName"" 
Invoke-Command -ComputerName $ServerName -Credential $c -ScriptBlock { 

Stop-Service -Name ShellHWDetection 

New-Partition -DiskNumber "$DiskNumber" -UseMaximumSize -DriveLetter "$driveletter" | Format-Volume -FileSystem NTFS -NewFileSystemLabel "$NewFileSystemLabel" -AllocationUnitSize "$AllocationUnitSize" -Force -Confirm:$false 

Start-Service -Name ShellHWDetection 

}}}} 

には、次のエラーを取得しますリモート変数を実行するには、引数リストとして渡すか、 "using"プロバイダを使用して参照する必要があります。

Invoke-Command -ComputerName $ServerName -Credential $c -ScriptBlock { 
    Stop-Service -Name ShellHWDetection 
    New-Partition -DiskNumber "$using:DiskNumber" -UseMaximumSize -DriveLetter "$using:driveletter" | Format-Volume -FileSystem NTFS -NewFileSystemLabel "$using:NewFileSystemLabel" -AllocationUnitSize "$using:AllocationUnitSize" -Force -Confirm:$false 
    Start-Service -Name ShellHWDetection 
} 
+0

こんにちはクリスのドライブレター「N」が含まれている必要があり、あなたのCSVドライブ文字列に思います。エラーなしでスクリプトを実行することができました。 –

関連する問題