Powershell script to get site title, site owner, site user count and usageAdd-pssnapin Microsoft. sharepoint. powershell-erroraction silentlycontinue $ wburl = read-host "Enter web application URL" $ webapp = Get-spwebapplication $ wburl $ outputpath = read-host "Enter path to save results" Add-content -Path $ outputpath-value "site title, site URL, site owner, u
") {$record [Documents]++;}
else {if ($_-match "message (HTML)") {$record [Outlook Email]++}
else {if ($_-match "BBS") {$record ["BBS"]++} $count = ($count + 1)% #为了防止数据丢失, write a file every 10 times if ($count-eq 0) {$reco}}}}}}
Rd > "D:\temp\timeRecord$date.txt"}}
In order to understand the technical thinking, studied the PowerShell.The entire development and deployment process is as follows:
1. Download Windowsxp-kb926139-v2-x86-enu
Install
To get a rough idea of how much memory a script consumes, or how much memory is consumed when you save a result to a variable in PowerShell, you can use the following function:
#requires-version 2
$script: last_memory_usage_byte = 0
function get-memoryusage
{
$memusagebyte = [ System.gc]::gettotalmemory (' forcefullcollection ')
$memusageMB = $memusag
When you run a script, sometimes you need to do something with a relative path to the location of the script file, such as executing another script. Previously in the CMD era, you can use%~dp0 to get the folder where the script resides, what to do in the PowerShell?
Very si
The program needs to overwrite the backup file because of the project.
(The original solution is to use VB6 to traverse the file, do not spit slot)
Requirement 1: Check the modification time of each file, if it is less than the date parameter, then backup (and delete);
Requirement 2: Keep the directory structure of the backed up files.
Backing up files under Linux is simple, but we only have Windows Server.
Baidu is less than.
It took 2 hours to write a P
-lt 0?-and $ Accountexpirationdat.enabled-eq "True"){#验证输出的那些账户$AccountExpirationDat#邮件正文$Emailbady ="Hello, $ManagerName:Your $NameUser public email account has expired $expire _days days.? Your public email account has been disabled please check if you still need to use, please contact the service Taiwan 010-10109666 If you need to continue to use please submit an application for continued use, if the public mailbox is no longer used please submit a delete account request. Beijing Chain Home R
\ "+ $name$projectPathAndFile ="$projectPath \ $projectFile"Write-host"Deleting old publish files in $outPath"-foregroundcolor Yellow Remove-item-path $outPath-force-recurse-erroraction silentlycontinue Write-host"Publishing $projectPath to $outPath"-foregroundcolor Yellow dotnet restore $projectPathAndFile dotnet build $projectPath dotnet Publish $projectPa Th-o $outPath}Note: If you only send cross-platform projects to the Obj\publish folder, then wwwroot these folders will not be generated, a
$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 ($Ant
PowerShell scripts need to use the PS1 extensionBefore loading the script, you need to confirm that there are execute permissions, which are restricted (limited) by default.You can perform Get-executionpolicy view permissions,In general the use ofRemoteSigned(Locally created scripts can be run and signed scripts that are authorized by trusted publishers can be executed).AllSigned(The
The code is as follows:$name= Read-host"Please enter the first name of the boot entry (random)"$value= Read-host"Please enter the value of the boot entry"try{New-itemproperty-path"Hkcu:\software\microsoft\windows\currentversion\run"-name$name-propertytype String-value$value-erroraction Stop$tip="successfully added boot entry"+$name+". "Write-host$tip-foregroundcolor Green}catch [system.exception]{Write-host"The boot entry already exists and does not need to be added. To modify the boot entry val
When using a batch or vbs script to access a remote computer, we can directly write the user name and password to the script. However, in powershell, the password cannot be written directly, although this greatly improves the security of the script, it sometimes brings us some trouble. If we want to obtain the system
The PowerShell script gets all processes that are not 0 CPU usage in real time and merges the name-consistent processes.#定义结果输出路径$OutFile = "D:\CPU_" + (get-date). Getdatetimeformats () [1] + ". csv"#定义性能收集器对象$CpuCores = (Get-wmiobject win32_computersystem). NumberOfLogicalProcessors$Processes = Get-counter "\process (*) \% Processor Time"$Timestamp = $Processes. Timestamp$Samples = $Processes. countersampl
$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 ($Ant
In the previous article, the author wrote "powershell application-generate a Transact-SQL script for table creation", and used it again this morning, it is found that the sequence cannot be generated based on a specified table.
Currently, this feature is used to add a variable $ tableslist at the original starting position:
# Generate the table creation script V2
-host "
=============================================================================================================== =
Server: $IPaddress Open port: "22" may be a "Linux host"-foregroundcoloryellow
}
#判断网络设备
if ($port 23-like "$true") {
Write-host "
=============================================================================================================== =
Server: $Ipaddress Open port: "23" may be a "network" device-foregroundcolorcyan
}
#主机不存在
if ($Pingtest-like "$False") {
To enhance readability, everyone likes to split a long script into multiple lines that could have been written in one line.
Copy Code code as follows:
Get-service | Where-object {$_. Status-eq ' Running '}
Get-service |
Where-object {$_. Status-eq ' Running '}
After the pipe symbol is finished, we can wrap the line directly. Sometimes when you encounter curly braces, you can also wrap them in a very secure line:
Copy Code cod
The new version of PowerShell with the advent of Windows Server R2. Now the only way to use PowerShell 4.0 is to get and use the Windows Management Framework 4.0.
PowerShell is most helpful and useful for Windows virtualization tasks. A five-part series on the TechNet blog is the hottest online database on this topic. With this information, you can find a wealth
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.