Microsoft Windows PowerShell scripts

insaneYLN

In the zone
Hello Friends, it has been quite a long time since I have visited the Think Digit Forum. I am hoping to catch up and be abreast on majority of the developments, if not all.
:ashamed:

The urgent issue responsible for my sudden visit is, I require some help concerning Microsoft Windows PowerShell scripts.

At this moment, I am looking for a script(s) that will perform the installation of Microsoft Windows Server 2008 R2 on a Virtual Hard Drive (VHD).
The said VHD has already been created and mounted.
:neutral:

Awaiting your responses and your help in any way, and thanking you all in advance.
:smile:
 
OP
I

insaneYLN

In the zone
Hello everybody.
:wave:

I have acquired a Windows PowerShell script that creates and mounts a Virtual Hard Drive (VHD). The source of the script is, *marknic.net/2009/09/02/create...ng-powershell/ and I have cited it entirely below.

Code:
function Check-AvailableDrive {
    param ( $driveLetterToSearch )

    foreach( $driveFound in [System.IO.DriveInfo]::GetDrives()) {
        if ($driveLetterToSearch + ":`\" -eq $driveFound.Name) { return $false }

 }
 
   return $true         

}


function Create-VhdDrive {
    param ( $vdiskPath = $(Throw "vdiskPath was not specified"),
            $vdiskFileName = $(Throw "vdiskFileName was not specified"),
            $vdiskMaximumSize = 20000, $vdiskType = "EXPANDABLE",
            $vdiskDriveLetter = "", $vdiskVolumeName = "NewVHD",
            $vdiskScriptFileName = "CreateVhd.scr" )

 if ($vdiskDriveLetter.length -eq 0)
    {
        $driveAssign = ""
    } else {
        if ($vdiskDriveLetter.length -ne 1) {
            Throw "Error: the variable `"driveLetter`" must be a single letter only."
        } else {
            if ((Check-AvailableDrive $vdiskDriveLetter) -eq $false) {
                $errorResult = "Cannot create drive $vdiskDriveLetter - it already exists."
                Throw $errorResult
            }

            $driveAssign = "LETTER=$vdiskDriveLetter"
        }
    }

 if (($vdiskType -ne "FIXED") -and ($vdiskType -ne "EXPANDABLE")) {
        Throw "Error: vdiskType must be `"FIXED`" or `"EXPANDABLE`""
    }

if (![System.IO.Directory]::Exists($vdiskPath)) {
        Throw "Error: the destination folder does not exist - $vdiskPath"
    }

 $vdiskFullFilePath = [System.IO.Path]::Combine($vdiskPath, $vdiskFileName)

$scriptLineToWrite = "CREATE VDISK FILE=`"$vdiskFullFilePath`" MAXIMUM=$vdiskMaximumSize TYPE=$vdiskType`n"

 $scriptLineToWrite = $scriptLineToWrite + "SELECT VDISK FILE=`"$vdiskFullFilePath`"`n"

 $scriptLineToWrite = $scriptLineToWrite + "ATTACH VDISK`n"

 $scriptLineToWrite = $scriptLineToWrite + "CREATE PARTITION PRIMARY`n"

 $scriptLineToWrite = $scriptLineToWrite + "ASSIGN $driveAssign`n"

 $scriptLineToWrite = $scriptLineToWrite + "FORMAT QUICK LABEL=$vdiskVolumeName"

$scriptPath = [System.IO.Path]::Combine($vdiskPath, $vdiskScriptFileName)

$scriptLineToWrite | out-file -encoding ASCII $scriptPath

diskpart /s $scriptPath

}

How can I combine the installation of Microsoft Windows Server R2 2008 Enterprise with the above script?
:chinscratch:

After a VHD is manually created using the WinPE command console from the bootable disc, the process continues from the general installer. I am looking to automate this process using suitable Windows PowerShell scripts.
:Fingerx:

I am hoping any of you could help and or guide me.
:smile:
 
Top Bottom