/build/static/layout/Breadcrumb_cap_w.png

Noob needs help with Powershell script to automate USB boot media

I keep getting error:
PS H:\> C:\USB_Boot\QueryDiskpartv2.ps1
Unexpected token ‘and’ in expression or statement.
At C:\USB_Boot\QueryDiskpartv2.ps1:39 char:76
+ .\QueryDiskpartv2.ps1 | where { $_.Type –eq $Type –and $_.Size –gt $Min and <<<< $Size –lt $Max }
+ CategoryInfo : ParserError: (and:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

_________________________________________________

Here is the script I copied from this site:

new-item -Name listdisk.txt -Itemtype file -force | out-null
add-content -path listdisk.txt “list disk”
$listdisk=(diskpart /s listdisk.txt)
$totaldisk=$listdisk.count-9
for ($d=0;$d -le $totaldisk;$d++)
{
new-item -Name detail.txt -ItemType file -force | out-null
add-content -Path detail.txt “select disk $d”
add-content -Path detail.txt “detail disk”

$Detail=(diskpart /s detail.txt)
$Model=$detail[8]
$type=$detail[10].substring(9)
$size=$listdisk[8+$d].substring(25,9).replace(” “,”")

$length=$size.length
$multiplier=$size.substring($length-2,2)
$intsize=$size.substring(0,$length-2)
switch($multiplier)
{
KB { $mult=1KB }
MB { $mult=1MB }
GB { $mult=1GB }
}
$disktotal=([convert]::ToInt16($intsize,10))*$mult
[pscustomobject]@{DiskNum=$d;Model=$model;Type=$type;DiskSize=$disktotal}

}

.\QueryDiskpartv2.ps1 | where { $_.Type –eq ‘USB’ }
get-wmiobject -query “SELECT * from win32_diskdrive where Interfacetype = ‘USB’” | Select-object Model,InterfaceType,Size

$TYPE=’USB’

$MIN=8GB

$MAX=64GB

.\QueryDiskpartv2.ps1 | where { $_.Type –eq $Type –and $_.Size –gt $Min and $Size –lt $Max }

SELECT DISK 1
CLEAN
CREATE PARTITION PRIMARY
FORMAT FS=FAT32 QUICK
ASSIGN
ACTIVE

$TYPE=’USB’

$MIN=8GB

$MAX=64GB

$DRIVELIST=(.\QueryDiskpartv2.ps1 | where { $_.Type –eq $Type –and $_.Size –gt $Min and $Size –lt $Max })

NEW-ITEM -Path bootemup.txt -ItemType file -force | OUT-NULL

$DRIVELIST | FOREACH {

$DISKNUM=$_.DiskNum
ADD-CONTENT –path bootemup.txt –Value “SELECT DISK $DISKNUM”
ADD-CONTENT –path bootemup.txt –Value “CLEAN”
ADD-CONTENT –path bootemup.txt –Value “CREATE PARTITION PRIMARY”
ADD-CONTENT –path bootemup.txt –Value “FORMAT FS=FAT32 QUICK”
ADD-CONTENT –path bootemup.txt –Value “ASSIGN”
ADD-CONTENT –path bootemup.txt –Value “ACTIVE”

}
$DriveLetter=$detail[-1].substring(15,1)

$TYPE=’USB’
$MIN=8GB
$MAX=64GB
$letters=(./QUERYDISKPARTV2.PS1 | Where { $_.Type –eq $Type –and $_.Disksize –gt $Min –and $_.Disksize –lt $Max } | SELECT-Object DriveLetter)

$Source=”Z:\PE_Boot_Only_x64”

$letters { FOREACH { $Destination=$_.DriveLetter+”`:”; START-PROCESS ROBOCOPY.EXE –ArgumentList “$Source $Destination /E /S”} }

$Source=”Z:\PE_Boot_Only_x64”

$letters { FOREACH { $Destination=$_.DriveLetter+”`:”; START-PROCESS ROBOCOPY.EXE –ArgumentList “$Source $Destination /E /S”} }

 

If I can get help to also map the drive to the location with a selection letting me choose between the folders \\houmgmt49\bootmedia$\PE_Boot_Only_x86 or \\houmgmt49\bootmedia$\PE_Boot_Only_x64 to be mapped. I am a noob and want to automate the USB boot media process.


0 Comments   [ + ] Show comments

Answers (1)

Posted by: garneyflanch 7 years ago
White Belt
0

The second 'and' should be -and but right after that you are using avariable that I acn't tell if you really intend to. You are using the variable $size for the second '-and' in the previous you use the piped object's property .size. that might be what you intend but I wanted to draw attention to it. You are potentially comparint two different values to $min and $max.

 

Good luck and happy powershelling!

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ