0

I am new to PowerShell and I am trying to get a script to work to list my parallel ports. I took the PowerShell script from here:

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

After executing the script I am getting:

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

I even tried changing & by $ as I can see in this script which also doesn't work. Is a problem with my PowerShell or is the script which is causing the problem?

PS: I am using PowerShell v2.0 in Windows XP 32bit

Thank you in advance!


EDIT:

According to the answer so it isn't a PowerShell script but a vbscript. So my question now would be why this script doesn't work if it is indeed a PowerShell Script:

$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 
} 

I am getting this error:

Missing expression after unary operator '-'.
At C:\script.ps1:4 char:2
+ - <<<< computername $strComputer
    + CategoryInfo          : ParserError: (-:String) [], ParseException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

2 Answers 2

1

In your revised script, there's a space after the backtick on line 3, so the continuation isn't being recognized. When you use the backtick to for a line continuation in PowerShell, it can't be followed by a whitespace character. Eliminate that space, or make it all one line:

$colItems = get-wmiobject -class "Win32_ParallelPort" -namespace "root\CIMV2" -computername $strComputer
Sign up to request clarification or add additional context in comments.

Comments

0

Your example script is not PowerShell, it's vbscript.

PowerShell is much simpler, you would use something like:

Get-WmiObject Win32_ParallelPort

2 Comments

Interesting. This is a PowerShell script: gallery.technet.microsoft.com/scriptcenter/… and also I am getting errors, do you know why?
As alroc pointed out, the backtick was followed by a space. For some reason IE adds this space when you select the text even if the text has no space. I recommend using the "Copy Code" button when copying text from MSDN - you'll avoid issues like this in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.