waar is de beste plaats om te kopen van voorschrift brillen http://hollandpillen.com/lorazepam/ beste otc koud geneeskunde
Jeff Wouters's Blog

Archive for November, 2011

Manage applications on remote systems using PowerShell

by on Nov.30, 2011, under Microsoft, PowerShell, Script, Windows

A few weeks ago I found myself in a community where someone told me that he did an uninstall of an application on 35 workstations.
Now how did he do that? Through SCCM? RES Automation Manager? Altiris?
No, he went to every device and did it by hand because this customer did not have an automation tool in place.

Now, going to every device and do it by hand is something I would very much dislike… and there are days I wouldn’t even let an intern do it. Instead I would give them an objective: Automate the uninstallation of the application without using additional tools and only use what is available to you.

Since I don’t have an intern anymore, and it wasn’t my customer, there was no need for me to do this… but it got me thinking…

I found this nice little script from Ed ‘the scripting guy’ Wilson where he uses PowerShell to make an inventory of all applications installed in his environment.
Since his script only searches on devices specified in a file, I did some tweaking to search all devices from AD and use those instead of the content of the file.

$computers = Get-ADComputer
$array = @()
foreach($pc in $computers){
#Define the variable to hold the location of Currently Installed Programs
#Create an instance of the Registry Object and open the HKLM base key
#Drill down into the Uninstall key using the OpenSubKey Method
#Retrieve an array of string that contain all the subkey names
#Open each Subkey and use GetValue Method to return the required values for each
foreach($key in $subkeys){
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name “ComputerName” -Value $computername
$obj | Add-Member -MemberType NoteProperty -Name “DisplayName” -Value $($thisSubKey.GetValue(“DisplayName”))
$obj | Add-Member -MemberType NoteProperty -Name “DisplayVersion” -Value $($thisSubKey.GetValue(“DisplayVersion”))
$obj | Add-Member -MemberType NoteProperty -Name “InstallLocation” -Value $($thisSubKey.GetValue(“InstallLocation”))
$obj | Add-Member -MemberType NoteProperty -Name “Publisher” -Value $($thisSubKey.GetValue(“Publisher”))
$array += $obj
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft –auto

Now that you know which applications are installed, you can use the following script to uninstall them Glimlach

# Usage: RemoveApplication.ps1 “Microsoft Office 2007”
function Remove-Application ($ApplicationName) { $Application = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “$ApplicationName” } $Application.Uninstall() }

Leave a Comment more...

Getting the PowerShell execution policy for a remote device

by on Nov.30, 2011, under Microsoft, PowerShell, Script, Windows

Sometimes I’m at a customer where an end-user calls while testing the newly build environment and reports that some settings are not applied. Often these settings are applied through Group Policy or PowerShell scripts.
For the PowerShell part, the first thing I check is the execution policy.

Although I could ask the user to provide me the output of the Get-ExecutionPolicy command, they will probably not appreciate me for asking this.
Next to that, most of the times I get a incident ticket with the message and no contact with the end-user myself.
Because of this, I’ve written this PowerShell function to get the execution policy for a remote computer:

#Usage: Get-RemoteExecutionPolicy Laptop1
function Get-RemoteExecutionPolicy ($TargetName)
$RegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $TargetName)
$PSRegKey= $RegKey.OpenSubKey(“SOFTWARE\\Microsoft\\Powershell\\1\\ShellIds\\Microsoft.PowerShell”)
$Policy = ($PSRegKey.getvalue(“ExecutionPolicy”)).tostring()
Return $Policy

It is also possible to invoke a command on the remote machine… like this:

Invoke-Command –Computer Laptop1 –ScriptBlock {Get-ExecutionPolicy}

Another way of doing this, is by using a remote PowerShell session… like this:

New-PSSession –Computer Laptop1 | Get-ExecutionPolicy

For more information about the commands to get the execution policy for specific scopes you can read one of my previous posts: PowerShell and the execution policies explained

4 Comments more...