In SCCM 2012 Applications you can have a detection method set for MSU with KB numbers.
You can use the Powershell or VBScript to do this. Here is an example of both.
Powershell Script:
get-hotfix | Where-Object {$_.HotFixID -match "KB981603"}
VBScript:
'Returns info if Windows 'KB981603' in installed
' ----------------------------------------------------------'
Option Explicit
Dim objWMIService, strComputer
strComputer = "."
'Run the query
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Dim QFEs
Dim QFE
Set QFEs = objWMIService.ExecQuery ("Select * from win32_QuickFixEngineering where HotFixID like 'KB981603'")
For Each QFE in QFEs
Wscript.echo "Update KB981603 was installed by " & QFE.InstalledBy & " on " & QFE.InstalledOn
Next
WScript.Quit
This Blog is for all people working or related to the MSI and App-V. There are lots of issues we face in everyday work regarding the technology. The sole purpose of my blog is to help others with whatever I learn. All you people out there, please help by commenting, voting, propagating and sharing my blog with your friends and colleagues but with due credit and acknowledgement to the material posted here with my name and blog url as I still do hold the copyright of the posts here.
Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts
Monday, February 25, 2013
Wednesday, April 04, 2012
VBScript to copy file and Powershell Script to copy file
VBScript to copy file:
dim filesys, oShell
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
sup = oShell.ExpandEnvironmentStrings ("%APPDATA%")
des = oShell.ExpandEnvironmentStrings ("%ProgramFiles(x86)%")
destfile= sup & "\AR System\HOME\AR"
sourcefile= des & "\AR System\User\AR"
If filesys.FileExists(sourcefile) Then
filesys.CopyFile sourcefile, destfile
End If
Powershell Script to copy file:
$SourceFile = "c:\foo\Test.txt";
$NewFile = "c:\foo\Test2.txt";
# Now - check to see if $Sourcefile exists, and if so,
# copy it to $newfile
if ([System.IO.File]::Exists($SourceFile)) {
[System.IO.File]::Copy($SourceFile, $NewFile)
"Source File ($SourceFile) copied to ($newFile)"
}
else {
"Source file ($Sourcefile) does not exist."
}
dim filesys, oShell
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
sup = oShell.ExpandEnvironmentStrings ("%APPDATA%")
des = oShell.ExpandEnvironmentStrings ("%ProgramFiles(x86)%")
destfile= sup & "\AR System\HOME\AR"
sourcefile= des & "\AR System\User\AR"
If filesys.FileExists(sourcefile) Then
filesys.CopyFile sourcefile, destfile
End If
Powershell Script to copy file:
$SourceFile = "c:\foo\Test.txt";
$NewFile = "c:\foo\Test2.txt";
# Now - check to see if $Sourcefile exists, and if so,
# copy it to $newfile
if ([System.IO.File]::Exists($SourceFile)) {
[System.IO.File]::Copy($SourceFile, $NewFile)
"Source File ($SourceFile) copied to ($newFile)"
}
else {
"Source file ($Sourcefile) does not exist."
}
Wednesday, January 11, 2012
My First Powershell script
Seems that Powershell is the way to go forward as it is well supported with Windows 7 and Microsoft. It is a powerful script. I think it will revolutionize the way we script today.
I just wrote my first powershell script and thought it would be good to share with all. I am not going to give any tutorial for Powershell as there are a lot of them available.
There are a few things which are worth noting in this script:
1) You can get the script directory from the below script in Get-ScriptDirectory function.
2) You can suppress the remote exe installation prompt by command: $env:SEE_MASK_NOZONECHECKS = 1
code
Remove-Item env:\SEE_MASK_NOZONECHECKS
3) Installation of setup.exe with parameters can be seen in function InstallPackage
4) Permissions can be set in Powershell script using the GivePermissions function below.
Here is the code:
------------------------------------------------------
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$env:SEE_MASK_NOZONECHECKS = 1
$val1 = Get-ScriptDirectory
$CurrentPath = $val1.ToString()
$Setup = $CurrentPath + "\setup.exe"
$Config = " "
function InstallPackage
{
# Write-host $Setup
# Write-host $Config
$process = [Diagnostics.Process]::Start($Setup,$Config)
$process.WaitForExit()
}
function GivePermissions
{
$acl = Get-Acl "C:\Program Files\PLSQL"
$acl.SetAccessRuleProtection($True, $True)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl "C:\Program Files\PLSQL" $acl
}
# -Main ----------------------------------
InstallPackage
GivePermissions
Remove-Item env:\SEE_MASK_NOZONECHECKS
I just wrote my first powershell script and thought it would be good to share with all. I am not going to give any tutorial for Powershell as there are a lot of them available.
There are a few things which are worth noting in this script:
1) You can get the script directory from the below script in Get-ScriptDirectory function.
2) You can suppress the remote exe installation prompt by command: $env:SEE_MASK_NOZONECHECKS = 1
code
Remove-Item env:\SEE_MASK_NOZONECHECKS
3) Installation of setup.exe with parameters can be seen in function InstallPackage
4) Permissions can be set in Powershell script using the GivePermissions function below.
Here is the code:
------------------------------------------------------
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$env:SEE_MASK_NOZONECHECKS = 1
$val1 = Get-ScriptDirectory
$CurrentPath = $val1.ToString()
$Setup = $CurrentPath + "\setup.exe"
$Config = " "
function InstallPackage
{
# Write-host $Setup
# Write-host $Config
$process = [Diagnostics.Process]::Start($Setup,$Config)
$process.WaitForExit()
}
function GivePermissions
{
$acl = Get-Acl "C:\Program Files\PLSQL"
$acl.SetAccessRuleProtection($True, $True)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl "C:\Program Files\PLSQL" $acl
}
# -Main ----------------------------------
InstallPackage
GivePermissions
Remove-Item env:\SEE_MASK_NOZONECHECKS
Subscribe to:
Posts (Atom)