none
Failure 0x80070001 running a script

    General discussion

  • Hello,

    I am running a baseline/CI on a collection and all machines are giving the same error

    Setting Discovery Error 0x80070001 Incorrect function. Windows

    The script is from this article...

    https://sccm-zone.com/create-bitlocker-encryption-compliance-reports-for-c-drive-in-sccm-764dc097bc9c

    When running the script locally I have also an error

    PS C:\source> ./Get-BitLockerstatus.ps1
    You must provide a value expression on the right-hand side of the '-' operator.
    At C:\source\Get-BitlockerStatus.ps1:105 char:30
    +             If ($_.DeviceID - <<<< notin $Result.Drive) { 
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : ExpectedValueExpression
    tried with driveletter switch...
    PS C:\source> ./Get-BitLockerstatus.ps1 -DriveLetter 'C'
    You must provide a value expression on the right-hand side of the '-' operator.
    At C:\source\Get-BitlockerStatus.ps1:105 char:30
    +             If ($_.DeviceID - <<<< notin $Result.Drive) { 
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : ExpectedValueExpression
     
    
    Same error..

     Any clue?

    Thanks,

    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Saturday, November 11, 2017 3:43 AM

All replies

  • Hello,

    Apparently it could be a powershell issue as the command CIMInstance used at the beginning does not exist in Powershell 2.0...

    ##  Get the local drives from WMI 
            $LocalDrives = Get-CimInstance -Namespace 'root\CIMV2' -ClassName 'CIM_LogicalDisk' | Where-Object { $_.DriveType -eq '3' } 
    
             ## Get the BitLocker Status for all drives from WMI 
            Get-CimInstance  -Namespace 'root\CIMV2\Security\MicrosoftVolumeEncryption'  -ClassName 'Win32_EncryptableVolume' -ErrorAction 'Stop' | ForEach-Object { 
    

    How could it be replaced?

    Thanks,

    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Saturday, November 11, 2017 6:25 AM
  • Hi,

    Get-WmiObject is your friend.

    Get-WmiObject -Namespace 'root\CIMV2' -Class 'CIM_LogicalDisk'  | Where-Object { $_.DriveType -eq '3' } 



    Saturday, November 11, 2017 2:59 PM
  • Hello,

    Thanks,

    I did the changes on the two lines involving the "Get-CIMInstance'

    ##  Get the local drives from WMI 
            ##  $LocalDrives = Get-CimInstance -Namespace 'root\CIMV2' -ClassName 'CIM_LogicalDisk' | Where-Object { $_.DriveType -eq '3' } 
            $LocalDrives = Get-WmiObject -Namespace 'root\CIMV2' -Class 'CIM_LogicalDisk'  | Where-Object { $_.DriveType -eq '3' } 
     
            ## Get the BitLocker Status for all drives from WMI 
            ## Get-CimInstance  -Namespace 'root\CIMV2\Security\MicrosoftVolumeEncryption'  -ClassName 'Win32_EncryptableVolume' -ErrorAction 'Stop' | ForEach-Object { 
            Get-WmiObject -Namespace 'root\CIMV2\Security\MicrosoftVolumeEncryption'  -ClassName 'Win32_EncryptableVolume' -ErrorAction 'Stop' | ForEach-Object {
     
                #  Create the Result Props and make the ProtectionStatus more report friendly 
                $ResultProps = [ordered]@{ 
                    'Drive' = $_.DriveLetter 
                    'ProtectionStatus' = $( 
                        Switch ($_.ProtectionStatus) { 
                            0 { 'PROTECTION OFF' } 
                            1 { 'PROTECTION ON' } 
                            2 { 'PROTECTION UNKNOWN' } 
                        } 
                    ) 
                } 
    
     
                #  Adding ResultProps hash table to result object 
                $Result += New-Object PSObject -Property $ResultProps 
            } 
    
            #  Workaround for some Windows 7 computers not reporting BitLocker protection status for all drives 
            #  Create the ResultProps array 
            $LocalDrives | ForEach-Object { 
                If ($_.DeviceID -notin $Result.Drive) { 
                    $ResultProps = [ordered]@{ 
                        'Drive' = $_.DeviceID 
                         'ProtectionStatus' = 'PROTECTION OFF' 
                     } 
     

    but I am getting an error on line 105 Char 30

    PS C:\source> C:\source\Get-BitlockerStatus.ps1
    You must provide a value expression on the right-hand side of the '-' operator.
    At C:\source\Get-BitlockerStatus.ps1:105 char:30
    +             If ($_.DeviceID - <<<< notin $Result.Drive) { 
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : ExpectedValueExpression

    Thanks,

    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Saturday, November 11, 2017 10:34 PM
  • Hi,

    I am not getting that error but I noticed there are a couple of closing brackets missing from your post.

    This seems to work ok for me

    https://codeshare.io/ayP3Xw

    Sunday, November 12, 2017 12:36 AM
  • Hi,

    Did you use Powershell v2 with "Get-WmiObject" or Powershell v3 with "Get-CimInstance"?

    Thanks,

    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Sunday, November 12, 2017 3:03 AM
  • Sorry I was using v3 like an idiot :)

    I just tried on a clean vm with V2, a few issues.

    OK maybe this might point you in the right direction.

    $ResultProps = $null
    ##  Get the local drives from WMI 
    ##  $LocalDrives = Get-CimInstance -Namespace 'root\CIMV2' -ClassName 'CIM_LogicalDisk' | Where-Object { $_.DriveType -eq '3' } 
    $LocalDrives = Get-WmiObject -Namespace 'root\CIMV2' -Class 'CIM_LogicalDisk'  | Where-Object { $_.DriveType -eq '3' } 
     
    ## Get the BitLocker Status for all drives from WMI 
    ## Get-CimInstance  -Namespace 'root\CIMV2\Security\MicrosoftVolumeEncryption'  -ClassName 'Win32_EncryptableVolume' -ErrorAction 'Stop' | ForEach-Object { 
    $Result = @()
    Get-WmiObject -Namespace 'root\CIMV2\Security\MicrosoftVolumeEncryption'  -Class 'Win32_EncryptableVolume' -ErrorAction 'Stop' | ForEach-Object {    
        #  Create the Result Props and make the ProtectionStatus more report friendly 
        $ResultProps = @{ 
            'Drive'            = $_.DriveLetter 
            'ProtectionStatus' = $( 
                Switch ($_.ProtectionStatus) { 
                    0 { 'PROTECTION OFF' } 
                    1 { 'PROTECTION ON' } 
                    2 { 'PROTECTION UNKNOWN' } 
                } 
            ) 
        }
        #  Adding ResultProps hash table to result object 
        $Result += New-Object PSObject -Property $ResultProps 
    } 
     
    #  Workaround for some Windows 7 computers not reporting BitLocker protection status for all drives 
    #  Create the ResultProps array 
    $LocalDrives | ForEach-Object { 
        If ($_.DeviceID -notmatch ($Result | Select-Object -Property Drive).Drive) { 
            $ResultProps = @{ 
                'Drive'            = $_.DeviceID 
                'ProtectionStatus' = 'PROTECTION OFF'
            }
        }
    }

    Ordered and -notin are both V3 commands.

    https://mcpmag.com/articles/2012/12/11/pshell-order.aspx

    https://ss64.com/ps/syntax-compare.html

    If you stick the code in the ISE you will see a difference in colour to indicate something is accepted or not.



    Sunday, November 12, 2017 8:03 AM
  • Thanks a lot... I will have to check as I have a new message

    Script Execution - Error!
     A parameter cannot be found that matches parameter name 'ClassName'.

    "Win32_EncryptableVolume"

    ....


    Let see if the Inventory has been picked the new class..

    Thanks,

    Dom


    • Edited by Felyjos Sunday, November 12, 2017 7:52 PM
    Sunday, November 12, 2017 7:39 PM
  • Hi,

    I fixed that in the last version of the script I pasted.

    In PowerShell V2 you need to use -class not -classname with Get-WmiObject

    get-help Get-WmiObject -Full

    Monday, November 13, 2017 11:05 AM
  • Hello,

    Thanks excellent I passed this step...

    now looking at the next error after line 89...:

    Script Execution - Error!
     Unable to find type [ordered]: make sure that the assembly containing this type is loaded.

    Thanks,
    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Monday, November 13, 2017 9:38 PM
  • Hello,

    I found it problem of version again as I still have v2 [ordered] is not recognized...

    now the script is working locally...

    Now trying to use SCCM to push it...

    two steps:

    - getting the execution policy to unrestricted

    - having the correct script tested running

    Thanks,
    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Tuesday, November 14, 2017 1:17 AM
  • lol I put that info in the previous post, glad you got it working.

    "Ordered and -notin are both V3 commands."

    Tuesday, November 14, 2017 6:46 AM
  • By the way, you can install Powershell 3.0 on Windows 7, it's called KB2506143. There's tons of improvements in it, I put it in all of my images.
    Wednesday, November 15, 2017 8:26 AM
  • Hello,

    But does the version of powershell need to be the same on all Clients wher I am collecting information through this script, isn't it?

    Thanks,

    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Wednesday, November 15, 2017 3:16 PM
  • No, if something works in V2 it will work in later versions.

    You are going to make things a lot easier in the future if you deploy the latest version of PowerShell to all clients.

    Wednesday, November 15, 2017 3:34 PM
  • Agreeing with Richard:  you may want to consider deploying the latest version of WinRM (aka, powershell, aka Windows Management Framework) to your devices.  Start here in your research for accomplishing that:  https://docs.microsoft.com/en-us/powershell/wmf/readme 

    Standardize. Simplify. Automate.

    Thursday, November 16, 2017 6:52 PM
  • Thank you all I place a request for this deployment ... waiting responde from the various team(4) to respond..

    Dom


    Security / System Center Operations Manager 2012 / System Center Configuration Manager 2012 / SQL System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Friday, November 17, 2017 3:42 PM