robie2011
4/30/2014 - 1:57 PM

Powershell Systemadmin Tasks

Powershell Systemadmin Tasks

$DDrive = GWMI -CL Win32_LogicalDisk | Where {$_.DeviceId -Eq "D:"}
if($DDrive){
	Echo "ERROR: Es existiert bereits ein D-Laufwerk. Vorgang wird abgebrochen." 
	Exit
}

$drive = GWMI -CL Win32_LogicalDisk | Where {$_.DeviceId -Eq "C:"}
$sizeGB=$drive.Size/1024/1024/1024
$sizeGB
if([int]$sizeGB -gt 160){
    # Festplatte kann partitioniert werden
    $t="C:\diskpart.tmp"
    "select disk=system" | set-content -Encoding ASCII $t
    "select volume=c" | Add-content -Encoding ASCII $t
    "shrink"| Add-content -Encoding ASCII $t
    "create partition primary"| Add-content -Encoding ASCII $t
    "assign letter=D"| Add-content -Encoding ASCII $t
    "format fs=ntfs quick"| Add-content -Encoding ASCII $t
    
    "Diskpart File erstellt"    
    echo "-----------------------"    
    gc $t
    start-process -wait -FilePath cmd.exe -ArgumentList "/c diskpart /s $t"
    
    del $t
	
	$drive = gwmi win32_volume -Filter "DriveLetter='D:'"
	Set-WmiInstance -InputObject $drive -Arguments @{Label="DATA"}
}else{
    echo "failed"
}