Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Pass script content directly to detection and requirement script rule functions #168

Open
ITistheworst opened this issue Aug 1, 2024 · 3 comments

Comments

@ITistheworst
Copy link

For functions like New-IntuneWin32AppDetectionRuleScript it would be great if there was the option to pass script content directly instead of only passing a file. This would be useful for building script blocks directly in script, or manipulating scripts before passing them to the function.

@ITistheworst ITistheworst changed the title Feature Request: Pass script content directly to detection and requirement rule functions Feature Request: Pass script content directly to detection and requirement script rule functions Aug 1, 2024
@AlkHacNar
Copy link

AlkHacNar commented Aug 4, 2024

the new-intunewin32apptecetectionrule script is for script files, if you wanna use it directly from your script during the building of the app, here a workaround/ way I use

$Script = @(
'$Reg = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -ilike "Adobe Acrobat*" } | Select-Object -Property DisplayName, DisplayVersion, PSChildName'
'if($Reg){if([Version](Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($Reg.PSChildName)","HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($Reg.PSChildName)" -Name DisplayVersion -ea SilentlyContinue) -ge [version]"'+$($AppInfo.Version)+'"){Write-Host "Installed";Exit 0}else {Exit 0}}else{exit 0}'
)
$Script = $Script | Out-String

$DetectionRule = [ordered]@{
"@odata.type" = "#microsoft.graph.win32LobAppPowerShellScriptDetection"
"enforceSignatureCheck" = $false
"runAs32Bit" = $false
"scriptContent" = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($Script)))
}

and use it with the -DetectionRule $DetectionRule Flag in the Add-Win32App command

But yea, if it could work directly, it would be nice

@AlkHacNar
Copy link

I don't use it with the requirements, but I think it could work as detection, you just need to ajust the $DetectionRule for requirement graph call

@ITistheworst
Copy link
Author

Thanks @AlkHacNar, I was hoping I would be able to do something like this but had not had a chance to get that far. Would be nice to be able to do it natively with the function, but this is a pretty clean workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants