私は PowerShell を初めて使用し、スクリプトを機能させてパラレル ポートを一覧表示しようとしています。ここから PowerShell スクリプトを取得しました。
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ParallelPort")
For Each objItem in colItems
Wscript.Echo "Availability: " & objItem.Availability
For Each strCapability in objItem.Capabilities
Wscript.Echo "Capability: " & strCapability
Next
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "OS Auto Discovered: " & objItem.OSAutoDiscovered
Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
Next
スクリプトを実行すると、次のようになります。
PS C:\> .\script.ps1
Unexpected token '_' in expression or statement.
At C:\script.ps1:4 char:44
+ Set objWMIService = GetObject("winmgmts:" _ <<<<
+ CategoryInfo : ParserError: (_:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
このスクリプトでもわかるように、変更&
を試みましたが、これも機能しません。問題は PowerShell にありますか、それともスクリプトが問題の原因ですか?$
PS: Windows XP 32 ビットで PowerShell v2.0 を使用しています。
前もって感謝します!
編集:
答えによると、PowerShell スクリプトではなく vbscript です。したがって、私の質問は、実際に PowerShell スクリプトである場合、このスクリプトが機能しない理由です。
$strComputer = "."
$colItems = get-wmiobject -class "Win32_ParallelPort" -namespace "root\CIMV2" `
-computername $strComputer
foreach ($objItem in $colItems) {
write-host "Availability: " $objItem.Availability
write-host "Capabilities: " $objItem.Capabilities
write-host "Capability Descriptions: " $objItem.CapabilityDescriptions
write-host "Caption: " $objItem.Caption
write-host "Configuration Manager Error Code: " $objItem.ConfigManagerErrorCode
write-host "Configuration Manager User Configuration: " $objItem.ConfigManagerUserConfig
write-host "Creation Class Name: " $objItem.CreationClassName
write-host "Description: " $objItem.Description
write-host "Device ID: " $objItem.DeviceID
write-host "DMA Support: " $objItem.DMASupport
write-host "Error Cleared: " $objItem.ErrorCleared
write-host "Error Description: " $objItem.ErrorDescription
write-host "Installation Date: " $objItem.InstallDate
write-host "Last Error Code: " $objItem.LastErrorCode
write-host "Maximum Number Controlled: " $objItem.MaxNumberControlled
write-host "Name: " $objItem.Name
write-host "Operating System Auto-Discovered: " $objItem.OSAutoDiscovered
write-host "PNP DeviceID: " $objItem.PNPDeviceID
write-host "Powe rManagement Capabilities: " $objItem.PowerManagementCapabilities
write-host "Power Management Supported: " $objItem.PowerManagementSupported
write-host "ProtocolS upported: " $objItem.ProtocolSupported
write-host "Status: " $objItem.Status
write-host "Status Information: " $objItem.StatusInfo
write-host "System Creation Class Name: " $objItem.SystemCreationClassName
write-host "System Name: " $objItem.SystemName
write-host "Time Of Last Reset: " $objItem.TimeOfLastReset
write-host
}
このエラーが発生しています:
Missing expression after unary operator '-'.
At C:\script.ps1:4 char:2
+ - <<<< computername $strComputer
+ CategoryInfo : ParserError: (-:String) [], ParseException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator