Monday, October 31, 2016

File Version Detection Login

$FilePath = "7-Zip"
$FileName = "7zFM.exe"
$DesiredVer = "16"
$FileVerLength = 2

If (Test-Path $env:ProgramFiles\$FilePath\$FileName) {
$AppVer = (Get-Item -Path $env:ProgramFiles\$FilePath\$FileName).VersionInfo
$AppVer = $AppVer.FileVersion.substring(0,$FileVerLength)
if ($AppVer -ge $DesiredVer)

{ write-host "Success" }
}


Reason:
    Performing detection of app deployment type Install_7Zip_16.04.0.0(ScopeId_BEBD3B8D-19A8-422B-BBE9-9ECCE2A830DC/DeploymentType_33465a95-df3e-4cd6-be8c-84afb5629c79, revision 5) for user. AppDiscovery 02/11/2016 10:57:46 15744 (0x3D80)
    In-line script returned error output: Get-Item : Cannot find path 'C:\Program Files\7-Zip\7zFM.exe' because it does not exist.
At C:\WINDOWS\CCM\SystemTemp\91159495-3fce-405a-8392-edadd4f20e36.ps1:6 char:12
+ $AppVer = (Get-Item -Path $env:ProgramFiles\$FilePath\$FileName).Vers ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program Files\7-Zip\7zFM.exe:String) [Get-Item], ItemNotFoundExcepti 
   on
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

You cannot call a method on a null-valued expression.
At C:\WINDOWS\CCM\SystemTemp\91159495-3fce-405a-8392-edadd4f20e36.ps1:7 char:1
+ $AppVer = $AppVer.FileVersion.substring(0,$FileVerLength)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)
A script execution error has occurred. The script has no output in stdout and an error message in stderr. AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)
Script Execution returned error message: Get-Item : Cannot find path 'C:\Program Files\7-Zip\7zFM.exe' because it does not exist.
At C:\WINDOWS\CCM\SystemTemp\91159495-3fce-405a-8392-edadd4f20e36.ps1:6 char:12
+ $AppVer = (Get-Item -Path $env:ProgramFiles\$FilePath\$FileName).Vers ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program Files\7-Zip\7zFM.exe:String) [Get-Item], ItemNotFoundExcepti 
   on
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

You cannot call a method on a null-valued expression.
At C:\WINDOWS\CCM\SystemTemp\91159495-3fce-405a-8392-edadd4f20e36.ps1:7 char:1
+ $AppVer = $AppVer.FileVersion.substring(0,$FileVerLength)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

, ExitCode: 4294967295 AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)
  Script Execution Returned :4294967295, Error Message: Get-Item : Cannot find path 'C:\Program Files\7-Zip\7zFM.exe' because it does not exist.
At C:\WINDOWS\CCM\SystemTemp\91159495-3fce-405a-8392-edadd4f20e36.ps1:6 char:12
+ $AppVer = (Get-Item -Path $env:ProgramFiles\$FilePath\$FileName).Vers ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program Files\7-Zip\7zFM.exe:String) [Get-Item], ItemNotFoundExcepti 
   on
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

You cannot call a method on a null-valued expression.
At C:\WINDOWS\CCM\SystemTemp\91159495-3fce-405a-8392-edadd4f20e36.ps1:7 char:1
+ $AppVer = $AppVer.FileVersion.substring(0,$FileVerLength)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

. [AppDT Id: ScopeId_BEBD3B8D-19A8-422B-BBE9-9ECCE2A830DC/DeploymentType_33465a95-df3e-4cd6-be8c-84afb5629c79, Revision: 5] AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)
CScriptHandler::DiscoverApp failed (0xffffffff). AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)
Deployment type detection failed with error 0xffffffff. AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)

Failed to perform detection of app deployment type Install_7Zip_16.04.0.0(Install_7Zip_16.04.0.0, revision 5) for user. Error 0xffffffff AppDiscovery 02/11/2016 10:57:47 15744 (0x3D80)

Monday, October 10, 2016

User Group to Machine

Query an AD group then match and return computer(s):

Select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client, SMS_R_User.UniqueUserName
FROM SMS_R_System
JOIN SMS_UserMachineRelationship ON SMS_R_System.Name=SMS_UserMachineRelationship.MachineResourceName
JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName=SMS_R_User.UniqueUserName
Where SMS_R_User.UniqueUserName in (select UniqueUserName from SMS_R_User where UserGroupName = "DOMAIN\\GROUPNAME")