Use of the Powershell Array (c) "script Example a"

Source: Internet
Author: User
Tags powershell array

In the previous two articles, the basic syntax of static arrays and dynamic arrays is briefly introduced, and an example is illustrated in this article for the use of arrays in daily operations.


First, the demand

In the customer organization has replaced the antivirus software vendor, need to scan the server or whether the client installed anti-virus software, or whether the installation of excessive anti-virus software.


Second, the solution of ideas

We put the names of all the antivirus software that may be installed into an array, and then through the WMI interface we can get all the software that is installed on the computer, and determine whether the software is present in the array.


Third, the script


#****************** defines an array of virus libraries, adding all the software names that may be installed to the array ****************


$AntivirusList = New-object System.Collections.ArrayList


#----NOTE: The full name of the soft kill should be added to the actual use, and the full display is not added


$AntivirusList. ADD ("Symentec") | Out-null


$AntivirusList. ADD ("Nod32") | Out-null


$AntivirusList. ADD ("360") | Out-null


#***************************** Gets the software inventory that is currently installed on the computer *****************************


$SoftwareInstalled = Get-wmiobject-class Win32_Product | Select-object-property Name


#---$Count used to measure the number of installed anti-virus software


$Count = 0


#----to cycle through the installed software to check if any software in the antivirus array has been installed-----


Foreach ($Software in $SoftwareInstalled)


{

if ($AntivirusList-contains ($Software. Name)


{$Count + +}


}


#*************** according to the situation of installing anti-virus software pop-up prompt results ********************


$ws = New-object-comobject Wscript.Shell


If ($Count-eq 0) {


$WSR = $ws. Popup ("Your computer does not have antivirus software installed! ", 5," Anti-virus software installation Check ", 0 + 16)


} elseif ($Count-gt 1)


{


$WSR = $ws. Popup ("It is not recommended that you have too many antivirus software installed on your computer. ", 5," Anti-virus software installation Check ", 0 + 48)


} else


{


$WSR = $ws. Popup ("Your computer has anti-virus software installed. ", 5," Anti-virus software installation Check ", 0 + 48)


}


#************************* Script End *******************************


This article is from the "Essence of the" blog, please be sure to keep this source http://simy88.blog.51cto.com/7370552/1680331

Use of the Powershell Array (c) "script Example a"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.