Created
April 30, 2014 13:57
-
-
Save robie2011/11427827 to your computer and use it in GitHub Desktop.
Powershell Systemadmin Tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment