Powershell帮助!!! [英] Powershell Help!!!

查看:71
本文介绍了Powershell帮助!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直收到错误:

PS H:\> C:\ USB_Boot\QueryDiskpartv2.ps1

表达式或语句中的意外标记'和'。$
在C:\ USB_Boot \QueryDiskpartv2.ps1:39 char :76

+ .\QueryDiskpartv2.ps1 |其中{$ _。类型-eq $类型 - 和$ _。大小-gt $ Min和<<<< $ size -lt $ Max}

+ CategoryInfo:ParserError :(和:String)[],ParentContainsErrorRecordException

+ FullyQualifiedErrorId:UnexpectedToken


< p style ="margin-bottom:12px; padding-right:0px; font-size:14px; vertical-align:baseline; line-height:1.714285714; color:#444444; font-family:Segoe,Helvetica,Arial,sans -serif">
_________________________________________________



这是我从这个网站复制的脚本:
$
new-item -Name listdisk .txt -Itemtype文件-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 =(转换] :: ToInt16($ intsize,10))* $ MULT

[pscustomobject] @ {DiskNum = $ d; Model = $ model; Type = $ type; DiskSize = $ disktotal}



}



。\ QueryDiskpartv2.ps1 | where {$ _。Type -eq'USB'}

get-wmiobject - 查询"SELECT * from win32_diskdrive,其中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和$ 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"}}



______________________________________________________________________



如果我可以获得帮助,还可以将驱动器映射到位置,并选择让我在文件夹中选择\\houmgmt49\bootmedia $要映射的\PE_Boot_Only_x86或\\houmgmt49\bootmedia $ \PE_Boot_Only_x64。我是一个菜鸟,想要自动化USB启动媒体
进程。

解决方案

此行在第二个"和"前面缺少一个连字符:

。\ QueryDiskpartv2。 ps1 | where {


_。Type -eq


Type -and


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.

解决方案

This line was missing a hyphen in front of the second "and":

.\QueryDiskpartv2.ps1 | where {


_.Type -eq


Type -and


这篇关于Powershell帮助!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆