Powershell
Contents
- 1 Send an Email from Powershell
- 2 Summarise each folder with number of files in each
- 3 Count number of zero byte files in folder
- 4 List zero byte files in folder
- 5 List zero byte files in folder and create file of output
- 6 Find xmls in a folder
- 7 EVRestart
- 8 Install net3.5 on Windows 2019
- 9 Running powershell script
Send an Email from Powershell
Send-MailMessage -To “<recipient’s email address>” -From “<sender’s email address>” -Subject “Your message subject” -Body “Some important plain text!” -Credential (Get-Credential) -SmtpServer “<smtp server>” -Port 587
Summarise each folder with number of files in each
get-childitem \\localhost\c$\temp| ?{ $_.PSIsContainer }|foreach-object -Process { write-host $_.Fullname ; (get-childitem $_.Fullname -Recurse |? { ! $_.PSIsContainer} ).Count }
Count number of zero byte files in folder
get-childitem \\localhost\c$\temp| ?{ $_.PSIsContainer }|foreach-object -Process { write-host $_.Fullname ; (get-childitem $_.Fullname -Recurse |? { ( ! $_.PSIsContainer ) -and ( $_.length -eq 0 ) } ).Count }
List zero byte files in folder
get-childitem \\localhost\c$\temp| ?{ $_.PSIsContainer }|foreach-object -Process { write-host $_.Fullname ; (get-childitem $_.Fullname -Recurse |? { ( ! $_.PSIsContainer ) -and ( $_.length -eq 0 ) } )}
List zero byte files in folder and create file of output
get-childitem \\localhost\c$\temp| ?{ $_.PSIsContainer }|foreach-object -Process { write-host $_.Fullname ; (get-childitem $_.Fullname -Recurse |? { ( ! $_.PSIsContainer ) -and ( $_.length -eq 0 ) } )} |Tee-Object -FilePath "C:\Temp\ZeroByteListPowershell.txt"
get-childitem \\?\UNC\computer.local\DFSRoot | ?{ $_.PSIsContainer }|foreach-object -Process { write-host $_.Fullname ; (get-childitem $_.Fullname -Recurse |? { ( ! $_.PSIsContainer ) -and ( $_.length -eq 0 ) } )} |Tee-Object -FilePath "C:/\Temp/\ZeroByteListPowershell-long2.txt"
get-childitem \\?\UNC\computer.local\DFSRoot
Find xmls in a folder
get-childitem c:\temp -Recurse |foreach-object -Process { if ( $_.Fullname -like "*.xml" ) { write-host $_.Fullname } }
EV Backup Service restart
call "F:\Enterprise Vault\Scripts\prebackup.bat" robocopy \\wgserver1\ev \\wgserver2\ev /mir /r:0 /w:0 /mt /a-:a call "F:\Enterprise Vault\Scripts\postbackup.bat" attrib -a "F:\Enterprise Vault\Store\*.*" /s call "F:\Enterprise Vault\Scripts\evrestart.bat"
Prebackup
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "C:\Program Files (x86)\Enterprise Vault\EVShell.psc1" -command "& {Set-VaultStoreBackupMode -Name WG -EVServerName vault.wggroup.com -EVObjectType Site}"
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "C:\Program Files (x86)\Enterprise Vault\EVShell.psc1" -command "& {Set-IndexLocationBackupMode -EVServerName vault.wggroup.com -EVSiteName WG}"
Postbackup
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "C:\Program Files (x86)\Enterprise Vault\EVShell.psc1" -command "& {Clear-VaultStoreBackupMode -Name WG -EVServerName vault.wggroup.com -EVObjectType Site}" C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "C:\Program Files (x86)\Enterprise Vault\EVShell.psc1" -command "& {Clear-IndexLocationBackupMode -EVServerName vault.wggroup.com -EVSiteName WG}"
EVRestart
net stop /Y "Enterprise Vault Shopping Service"
net stop /Y "Enterprise Vault Indexing Service" net stop /Y "Enterprise Vault Task Controller Service" net stop /Y "Enterprise Vault Storage Service" net stop /Y "Enterprise Vault Directory Service" net stop /Y "Enterprise Vault Admin Service" net stop /Y "World Wide Web Publishing Service" net stop /Y "IIS Admin Service" net stop /Y "Message Queuing"
net start /Y "Message Queuing"
net start /Y "Enterprise Vault Admin Service" net start /Y "Enterprise Vault Directory Service" net start /Y "Enterprise Vault Storage Service" net start /Y "Enterprise Vault Indexing Service" net start /Y "Enterprise Vault Shopping Service" net start /Y "Enterprise Vault Task Controller Service"
net start /Y "IIS Admin Service"
net start /Y "World Wide Web Publishing Service"
Install net3.5 on Windows 2019
1. Open an elevated command prompt. 2. Type the following command: Dism /online /Enable-Feature /FeatureName:"NetFx3" /All /Source:X:\sources\sxs /LimitAccess 3. Once you press Enter, Windows will download and install .NET Framework 3.5.
netsh int ipv4 set subinterface “Ethernet” mtu=1428 store=persistent
Running powershell script
powershell.exe -noprofile -executionpolicy bypass -file c:\wgtech\getinfo.ps1