lework 4 years ago
parent
commit
084272675e
  1. 680
      bat/vmware-batch.bat
  2. 16523
      powershell/exchange/ADDS_Inventory_V2.ps1
  3. 1454
      powershell/exchange/Get-ExchangeEnvironmentReport.ps1
  4. 4086
      powershell/exchange/Get-ExchangeTracking.ps1
  5. 5839
      powershell/exchange/HealthChecker.ps1
  6. 507
      powershell/exchange/MessageTrackingLogGUI.ps1
  7. 252
      powershell/exchange/Set-Webserver.ps1
  8. 31
      powershell/exchange/enable-ad-user-mailbox.ps1
  9. 176
      shell/get_proc_mem.sh
  10. 2
      shell/k8s/k8s-app-info.sh

680
bat/vmware-batch.bat

@ -1,333 +1,349 @@ @@ -1,333 +1,349 @@
@echo off
Setlocal enabledelayedexpansion
::CODER BY lework
title VMware Workstation 虚拟机批量管理
IF EXIST "%PROGRAMFILES%\VMWare\VMWare Workstation\vmrun.exe" SET VMwarePath=%PROGRAMFILES%\VMWare\VMWare Workstation
IF EXIST "%PROGRAMFILES(X86)%\VMWare\VMWare Workstation\vmrun.exe" SET VMwarePath=%PROGRAMFILES(X86)%\VMWare\VMWare Workstation
IF EXIST "%PROGRAMFILES%\VMware\VMware VIX\vmrun.exe" SET VMwarePath=%PROGRAMFILES%\VMware\VMware VIX
IF EXIST "%PROGRAMFILES(X86)%\VMware\VMware VIX\vmrun.exe" SET VMRUN=%PROGRAMFILES(X86)%\VMware\VMware VIX
:: VMware安装地址
# set VMwarePath="C:\Program Files (x86)\VMware\VMware Workstation"
:: 虚拟机存放目录
set VMpath="D:\Virtual Machines"
:: 虚拟机名称
set VMname=CentOS_7.8_x64_node
:: 虚拟机快照名称
set VMSnapshot=init
:: 新建虚拟机数目
set VMcount=5
:: 虚拟机owa模板位置
set VMowa="D:\vmware owa\CentOS_7.8_x64_base.ova"
:: 模板系统用户名
set VMuser=root
:: 模板系统密码
set VMpass=123456
:: 虚拟机网络
set VMnetwork=192.168.77
:: 虚拟机ip开始地址
set VMipStart=130
:init
cls
echo.
echo. VMware Workstation 虚拟机批量管理
echo.
echo ==============================
echo.
echo. 输入 0 一键初始化(包含1,2,3步骤)
echo. 输入 1 创建虚拟机
echo. 输入 2 设置ip地址
echo. 输入 3 创建快照
echo. 输入 4 查看启动的虚拟机
echo. 输入 5 启动虚拟机
echo. 输入 6 关闭虚拟机
echo. 输入 7 重启虚拟机
echo. 输入 8 恢复虚拟机快照
echo. 输入 9 删除虚拟机
echo. 输入 10 挂起虚拟机
echo. 输入 11 暂停虚拟机
echo. 输入 12 恢复虚拟机
echo. 输入 q 退出
echo.
echo ==============================
echo.
cd /d "%VMwarePath%"
set "input="
set /p input=请输入您的选择:
echo.
if "%input%"=="q" goto exit
if "%input%"=="0" goto oneKey
if "%input%"=="1" goto create
if "%input%"=="2" goto setip
if "%input%"=="3" goto snapshot
if "%input%"=="4" goto list
if "%input%"=="5" goto start
if "%input%"=="6" goto stop
if "%input%"=="7" goto restart
if "%input%"=="8" goto revertToSnapshot
if "%input%"=="9" goto delete
if "%input%"=="10" goto suspend
if "%input%"=="11" goto pausevm
if "%input%"=="12" goto unpausevm
:wait
echo.
echo 执行完毕, 等待中...
for /l %%a in (1,1,5) do (
ping /n 2 127.1>nul
set /p a=^><nul
)
cls
goto init
:oneKey
echo [创建虚拟机...]
set "cname="
set "ccount="
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
set /p VMuser=请输入用户名(默认:%VMuser%):
set /p VMpass=请输入密码(默认:%VMpass%):
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%):
echo.
echo =============
echo.
echo. 虚拟机模板: !VMowa!
echo. 虚拟机存放目录: !VMpath!
echo. 虚拟机名称: !VMname!
echo. 虚拟机数量: !VMcount!
echo. 虚拟机初始快照名称: !VMSnapshot!
echo. 虚拟机用户名: !VMuser!
echo. 虚拟机密码: !VMpass!
echo. 虚拟机网段: !VMnetwork!
echo. 虚拟机ip开始地址: !VMipStart!
echo.
echo =============
for /l %%a in (1,1,!VMcount!) do (
echo.
echo 创建虚拟机: !VMname!%%a
cd OVFTool
ovftool --name=!VMname!%%a !VMowa! !VMpath!
cd ..
echo.
echo 启动虚拟机: !VMname!%%a
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx
)
echo.
echo 设置ip:
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
set /a num=%VMipStart%+%%a-1
set ip=!VMnetwork!.!num!
echo !name!:!ip!
vmrun -T ws -gu !VMuser! -gp !VMpass! runProgramInGuest !VMpath!\!name!\!name!.vmx /bin/bash -c "sudo echo 'node!num!' > /etc/hostname; sudo sed -i 's/IPADDR=.*$/IPADDR="!ip!"/g' /etc/sysconfig/network-scripts/ifcfg-e*;/etc/init.d/network restart || sudo sed -i 's/address .*$/address !ip!/g' /etc/network/interfaces;/etc/init.d/network restart" nogui
)
echo.
echo 创建快照:
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui
)
goto wait
:start
echo [启动虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:stop
echo [关闭虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:restart
echo [重启虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:suspend
echo [挂起虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws suspend !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:pausevm
echo [暂停虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws pause !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:unpausevm
echo [恢复虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws unpause !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:revertToSnapshot
echo [恢复虚拟机快照...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws revertToSnapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui
)
goto wait
:list
echo [虚拟机启动列表...]
vmrun list
echo.
pause
goto wait
:create
echo [创建虚拟机...]
set "cname="
set "ccount="
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
echo.
echo =============
echo.
echo. 虚拟机模板: !VMowa!
echo. 虚拟机存放目录: !VMpath!
echo. 虚拟机名称: !VMname!
echo. 虚拟机数量: !VMcount!
echo.
echo =============
for /l %%a in (1,1,!VMcount!) do (
echo.
echo 创建虚拟机: !VMname!%%a
cd OVFTool
ovftool --name=!VMname!%%a !VMowa! !VMpath!
cd ..
echo 启动虚拟机: !VMname!%%a
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx
)
goto wait
:delete
echo [删除虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set is=no
set /p is=确定删除么?(yes/no, 默认:%is%):
if "%is%" NEQ "yes" (
echo 已取消
goto wait
)
echo 关闭vmware
taskkill /f /t /im vmware.exe
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo 删除: !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun deleteVM !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:snapshot
echo [创建快照...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui
)
goto wait
:setip
echo [设置ip地址...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMuser=请输入用户名(默认:%VMuser%):
set /p VMpass=请输入密码(默认:%VMpass%):
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
set /a num=%VMipStart%+%%a-1
set ip=!VMnetwork!.!num!
echo !name!:!ip!
vmrun -T ws -gu !VMuser! -gp !VMpass! runProgramInGuest !VMpath!\!name!\!name!.vmx /bin/bash -c "sudo sed -i 's/IPADDR=.*$/IPADDR="!ip!"/g' /etc/sysconfig/network-scripts/ifcfg-e*;/etc/init.d/network restart || sudo sed -i 's/address .*$/address !ip!/g' /etc/network/interfaces;/etc/init.d/network restart" nogui
)
goto wait
:exit
echo 退出...
ping /n 5 127.1>nul
@echo off
Setlocal enabledelayedexpansion
::CODER BY lework
:: 虚拟机需安装vmtool
title VMware Workstation 虚拟机批量管理
IF EXIST "%PROGRAMFILES%\VMWare\VMWare Workstation\vmrun.exe" SET VMwarePath=%PROGRAMFILES%\VMWare\VMWare Workstation
IF EXIST "%PROGRAMFILES(X86)%\VMWare\VMWare Workstation\vmrun.exe" SET VMwarePath=%PROGRAMFILES(X86)%\VMWare\VMWare Workstation
IF EXIST "%PROGRAMFILES%\VMware\VMware VIX\vmrun.exe" SET VMwarePath=%PROGRAMFILES%\VMware\VMware VIX
IF EXIST "%PROGRAMFILES(X86)%\VMware\VMware VIX\vmrun.exe" SET VMRUN=%PROGRAMFILES(X86)%\VMware\VMware VIX
:: VMware安装地址
# set VMwarePath="C:\Program Files (x86)\VMware\VMware Workstation"
:: 虚拟机存放目录
set VMpath="D:\Virtual Machines"
:: 虚拟机名称
set VMname=Debian_10.2_x64_node
:: 虚拟机快照名称
set VMSnapshot=init
:: 新建虚拟机数目
set VMcount=5
:: 虚拟机owa模板位置
set VMowa="D:\vmware owa\Debian_10.2_x64_base.ova"
:: 模板系统用户名
set VMuser=root
:: 模板系统密码
set VMpass=123456
:: 虚拟机网络
set VMnetwork=192.168.77
:: 虚拟机ip开始地址
set VMipStart=180
:init
cls
echo.
echo. VMware Workstation 虚拟机批量管理
echo.
echo ==============================
echo.
echo. 输入 0 一键初始化(包含1,2,3步骤)
echo. 输入 1 创建虚拟机
echo. 输入 2 设置ip地址
echo. 输入 3 创建快照
echo. 输入 4 查看启动的虚拟机
echo. 输入 5 启动虚拟机
echo. 输入 6 关闭虚拟机
echo. 输入 7 重启虚拟机
echo. 输入 8 恢复虚拟机快照
echo. 输入 9 删除虚拟机
echo. 输入 10 挂起虚拟机
echo. 输入 11 暂停虚拟机
echo. 输入 12 恢复虚拟机
echo. 输入 13 删除快照
echo. 输入 q 退出
echo.
echo ==============================
echo.
cd /d "%VMwarePath%"
set "input="
set /p input=请输入您的选择:
echo.
if "%input%"=="q" goto exit
if "%input%"=="0" goto oneKey
if "%input%"=="1" goto create
if "%input%"=="2" goto setip
if "%input%"=="3" goto snapshot
if "%input%"=="4" goto list
if "%input%"=="5" goto start
if "%input%"=="6" goto stop
if "%input%"=="7" goto restart
if "%input%"=="8" goto revertToSnapshot
if "%input%"=="9" goto delete
if "%input%"=="10" goto suspend
if "%input%"=="11" goto pausevm
if "%input%"=="12" goto unpausevm
if "%input%"=="13" goto delsnapshot
:wait
echo.
echo 执行完毕, 等待中...
for /l %%a in (1,1,5) do (
ping /n 2 127.1>nul
set /p a=^><nul
)
cls
goto init
:oneKey
echo [创建虚拟机...]
set "cname="
set "ccount="
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
set /p VMuser=请输入用户名(默认:%VMuser%):
set /p VMpass=请输入密码(默认:%VMpass%):
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%):
echo.
echo =============
echo.
echo. 虚拟机模板: !VMowa!
echo. 虚拟机存放目录: !VMpath!
echo. 虚拟机名称: !VMname!
echo. 虚拟机数量: !VMcount!
echo. 虚拟机初始快照名称: !VMSnapshot!
echo. 虚拟机用户名: !VMuser!
echo. 虚拟机密码: !VMpass!
echo. 虚拟机网段: !VMnetwork!
echo. 虚拟机ip开始地址: !VMipStart!
echo.
echo =============
for /l %%a in (1,1,!VMcount!) do (
echo.
echo 创建虚拟机: !VMname!%%a
cd OVFTool
ovftool --name=!VMname!%%a !VMowa! !VMpath!
cd ..
echo.
echo 启动虚拟机: !VMname!%%a
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx
)
echo.
echo 设置ip:
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
set /a num=%VMipStart%+%%a-1
set ip=!VMnetwork!.!num!
echo !name!:!ip!
vmrun -T ws -gu !VMuser! -gp !VMpass! runProgramInGuest !VMpath!\!name!\!name!.vmx -noWait /bin/bash -c "echo 'node!num!' > /etc/hostname && echo '127.0.0.1 node!num!' >> /etc/hosts; sudo sed -i 's/IPADDR=.*$/IPADDR="!ip!"/g' /etc/sysconfig/network-scripts/ifcfg-e* || sudo sed -i 's/address .*$/address !ip!/g' /etc/network/interfaces; init 6" nogui
)
echo.
echo 创建快照:
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui
)
goto wait
:start
echo [启动虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:stop
echo [关闭虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:restart
echo [重启虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:suspend
echo [挂起虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws suspend !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:pausevm
echo [暂停虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws pause !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:unpausevm
echo [恢复虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws unpause !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:revertToSnapshot
echo [恢复虚拟机快照...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws revertToSnapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui
)
goto wait
:list
echo [虚拟机启动列表...]
vmrun list
echo.
pause
goto wait
:create
echo [创建虚拟机...]
set "cname="
set "ccount="
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
echo.
echo =============
echo.
echo. 虚拟机模板: !VMowa!
echo. 虚拟机存放目录: !VMpath!
echo. 虚拟机名称: !VMname!
echo. 虚拟机数量: !VMcount!
echo.
echo =============
for /l %%a in (1,1,!VMcount!) do (
echo.
echo 创建虚拟机: !VMname!%%a
cd OVFTool
ovftool --name=!VMname!%%a !VMowa! !VMpath!
cd ..
echo 启动虚拟机: !VMname!%%a
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx
)
goto wait
:delete
echo [删除虚拟机...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set is=no
set /p is=确定删除么?(yes/no, 默认:%is%):
if "%is%" NEQ "yes" (
echo 已取消
goto wait
)
echo 关闭vmware
taskkill /f /t /im vmware.exe
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo 删除: !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun deleteVM !VMpath!\!name!\!name!.vmx nogui
)
goto wait
:snapshot
echo [创建快照...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui
)
goto wait
:delsnapshot
echo [删除快照...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
echo !name!
vmrun -T ws deleteSnapshot !VMpath!\!name!\!name!.vmx !VMSnapshot!
)
goto wait
:setip
echo [设置ip地址...]
set /p VMname=请输入虚拟机名称(默认:%VMname%):
set /p VMcount=请输入虚拟机数量(默认:%VMcount%):
set /p VMuser=请输入用户名(默认:%VMuser%):
set /p VMpass=请输入密码(默认:%VMpass%):
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%):
for /l %%a in (1,1,%VMcount%) do (
set name=!VMname!%%a
set /a num=%VMipStart%+%%a-1
set ip=!VMnetwork!.!num!
echo !name!:!ip!
vmrun -T ws -gu !VMuser! -gp !VMpass! runProgramInGuest !VMpath!\!name!\!name!.vmx -noWait /bin/bash -c "echo 'node!num!' > /etc/hostname && echo '127.0.0.1 node!num!' >> /etc/hosts; sudo sed -i 's/IPADDR=.*$/IPADDR="!ip!"/g' /etc/sysconfig/network-scripts/ifcfg-e* || sudo sed -i 's/address .*$/address !ip!/g' /etc/network/interfaces; init 6" nogui
)
goto wait
:exit
echo 退出...
ping /n 5 127.1>nul
exit

16523
powershell/exchange/ADDS_Inventory_V2.ps1

File diff suppressed because it is too large Load Diff

1454
powershell/exchange/Get-ExchangeEnvironmentReport.ps1

File diff suppressed because it is too large Load Diff

4086
powershell/exchange/Get-ExchangeTracking.ps1

File diff suppressed because it is too large Load Diff

5839
powershell/exchange/HealthChecker.ps1

File diff suppressed because it is too large Load Diff

507
powershell/exchange/MessageTrackingLogGUI.ps1

@ -0,0 +1,507 @@ @@ -0,0 +1,507 @@
function GenerateForm {
###############################################################################################################
# Version History:
#
# 1.1 - 18/07/2012 : https://gallery.technet.microsoft.com/office/MessageTrackingLog-search-72a5dbc7
# 2.0 - 12/19/2015 : Nicolas PRIGENT - www.get-cmd.com
# New features : search by subject / send results by email / export results in csv file
# Existing feature corrected : search by event ID did not work. Global variable was not created.
# Code optimized
#
# Description:
# This script searches the MessageTrackingLog in your Organization.
# You have to enter valid From Addr or To Addr or the subject and select the date.
# You can also select a specific event ID. You can leave the blank entry to search the whole TrackingLog.
#
###############################################################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
#endregion
#region Generated Form Objects
$formTrackLog = New-Object System.Windows.Forms.Form
$labEventID = New-Object System.Windows.Forms.Label
$comboBoxEventID = New-Object System.Windows.Forms.ComboBox
$labEndDate = New-Object System.Windows.Forms.Label
$labStartDate = New-Object System.Windows.Forms.Label
$labFrom = New-Object System.Windows.Forms.Label
$dgResults = New-Object System.Windows.Forms.DataGrid
$dateTimePickerEnd = New-Object System.Windows.Forms.DateTimePicker
$dateTimePickerStart = New-Object System.Windows.Forms.DateTimePicker
$txtBoxRecipients = New-Object System.Windows.Forms.TextBox
$txtBoxSenders = New-Object System.Windows.Forms.TextBox
$buttonGo = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$labTo = New-Object System.Windows.Forms.Label
$labSubject = New-Object System.Windows.Forms.Label
$txtBoxSubject = New-Object System.Windows.Forms.TextBox
$txtBoxMail = New-Object System.Windows.Forms.TextBox
$txtBoxCSV = New-Object System.Windows.Forms.TextBox
$chkBoxCSV = New-Object System.Windows.Forms.CheckBox
$chkBoxMail = New-Object System.Windows.Forms.CheckBox
$txtBoxFromMail = New-Object System.Windows.Forms.TextBox
$txtBoxToMail = New-Object System.Windows.Forms.TextBox
$txtBoxCSV = New-Object System.Windows.Forms.TextBox
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
Add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
$processData=
{
#This section determine the date and puts it in a working format
$array = New-Object System.Collections.ArrayList
$date1 = get-Date -date $dateTimePickerStart.value -uformat "%m/%d/%Y 00:00:01"
$date3 = [System.DateTime]$date1
$date2 = get-Date -date $dateTimePickerEnd.value -uformat "%m/%d/%Y 23:59:59"
$date4 = [System.DateTime]$date2
$Sort = "TimeStamp"
if ($ChoiceEventID -eq "BADMAIL" -or $ChoiceEventID -eq "DEFER" -or $ChoiceEventID -eq "DELIVER" -or $ChoiceEventID -eq "SEND" -or $ChoiceEventID -eq "DSN" -or $ChoiceEventID -eq "FAIL" -or $ChoiceEventID -eq "POISONMESSAGE" -or $ChoiceEventID -eq "RECEIVE" -or $ChoiceEventID -eq "REDIRECT" -or $ChoiceEventID -eq "RESOLVE" -or $ChoiceEventID -eq "SUBMIT" -or $ChoiceEventID -eq "TRANSFER" -or $ChoiceEventID -eq "EXPAND")
{
$EventID = $ChoiceEventID
}
else
{
$EventID = ""
}
if ( $EventID -ne "")
{
if(($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq "") -and ($txtBoxSubject.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -start $date3 -end $date4 -EventID $EventID -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif (($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -MessageSubject $txtBoxSubject.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxSenders.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxRecipients.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif ($txtBoxRecipients.text -eq "")
{
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -MessageSubject $txtBoxSubject.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif ($txtBoxSenders.text -eq "")
{
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -MessageSubject $txtBoxSubject.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif ($txtBoxSubject.text -eq "")
{
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -sender $txtBoxSenders.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
}
else
{
if(($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq "") -and ($txtBoxSubject.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif (($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -MessageSubject $txtBoxSubject.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxSenders.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject,EventID, serverhostname | sort $sort
}
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxRecipients.text -eq ""))
{
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif ($txtBoxRecipients.text -eq "")
{
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -MessageSubject $txtBoxSubject.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif ($txtBoxSenders.text -eq "")
{
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -MessageSubject $txtBoxSubject.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
elseif ($txtBoxSubject.text -eq "")
{
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -sender $txtBoxSenders.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort
}
}
if ($ausgabe) {
$array.addrange($ausgabe)
$dgResults.datasource = $array
$array | export-csv "MessageTrackingGUI.log"
if ($chkBoxCSV.Checked)
{
$array | export-csv $txtBoxCSV.text
}
if ($chkBoxMail.Checked)
{
$Date = Get-Date
$SubjectDate = "Exchange Message Tracking " + $Date.Tostring('HH:mm-MM.dd.yyyy')
send-mailmessage -to $txtBoxToMail.text -from $txtBoxFromMail.text -subject $SubjectDate -body "Attached is the message tracking" -Attachments 'MessageTrackingGUI.log' -BodyAsHTML -SmtpServer $txtBoxMail.text
}
$formTrackLog.refresh()
} else {
write-host "No results found!" -ForegroundColor white -BackgroundColor Red
}
}
$handler_comboBoxEventID_SelectedIndexChanged=
{
# Get the Event ID when item is selected
$Global:ChoiceEventID = $comboBoxEventID.selectedItem.ToString()
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$formTrackLog.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 550
$System_Drawing_Size.Width = 1000
$formTrackLog.ClientSize = $System_Drawing_Size
$formTrackLog.DataBindings.DefaultDataSourceUpdateMode = 0
$formTrackLog.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$formTrackLog.Name = "formTrackLog"
$formTrackLog.Text = "Message Tracking Log GUI - By Nicolas PRIGENT [www.get-cmd.com]"
$formTrackLog.add_Load($handler_formTrackLog_Load)
$labEventID.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 570
$System_Drawing_Point.Y = 5
$labEventID.Location = $System_Drawing_Point
$labEventID.Name = "labEventID"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 60
$labEventID.Size = $System_Drawing_Size
$labEventID.TabIndex = 18
$labEventID.Text = "Event ID:"
$labEventID.add_Click($handler_labEventID_Click)
$formTrackLog.Controls.Add($labEventID)
$comboBoxEventID.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBoxEventID.FormattingEnabled = $True
$comboBoxEventID.Items.Add("")|Out-Null
$comboBoxEventID.Items.Add("SEND")|Out-Null
$comboBoxEventID.Items.Add("DELIVER")|Out-Null
$comboBoxEventID.Items.Add("RECEIVE")|Out-Null
$comboBoxEventID.Items.Add("FAIL")|Out-Null
$comboBoxEventID.Items.Add("DSN")|Out-Null
$comboBoxEventID.Items.Add("RESOLVE")|Out-Null
$comboBoxEventID.Items.Add("EXPAND")|Out-Null
$comboBoxEventID.Items.Add("REDIRECT")|Out-Null
$comboBoxEventID.Items.Add("TRANSFER")|Out-Null
$comboBoxEventID.Items.Add("SUBMIT")|Out-Null
$comboBoxEventID.Items.Add("POISONMESSAGE")|Out-Null
$comboBoxEventID.Items.Add("DEFER")|Out-Null
$System_Drawing_PointComboEVentID = New-Object System.Drawing.Point
$System_Drawing_PointComboEVentID.X = 630
$System_Drawing_PointComboEVentID.Y = 3
$comboBoxEventID.Location = $System_Drawing_PointComboEVentID
$comboBoxEventID.Name = "comboBoxEventID"
$System_Drawing_SizeComboEVentID = New-Object System.Drawing.Size
$System_Drawing_SizeComboEVentID.Height = 21
$System_Drawing_SizeComboEVentID.Width = 121
$comboBoxEventID.Size = $System_Drawing_SizeComboEVentID
$comboBoxEventID.TabIndex = 17
$comboBoxEventID.add_SelectedIndexChanged($handler_comboBoxEventID_SelectedIndexChanged)
$formTrackLog.Controls.Add($comboBoxEventID)
$labEndDate.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 300
$System_Drawing_Point.Y = 33
$labEndDate.Location = $System_Drawing_Point
$labEndDate.Name = "labEndDate"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 54
$labEndDate.Size = $System_Drawing_Size
$labEndDate.TabIndex = 12
$labEndDate.Text = "End"
$formTrackLog.Controls.Add($labEndDate)
$labStartDate.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 300
$System_Drawing_Point.Y = 5
$labStartDate.Location = $System_Drawing_Point
$labStartDate.Name = "labStartDate"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 54
$labStartDate.Size = $System_Drawing_Size
$labStartDate.TabIndex = 11
$labStartDate.Text = "Start"
$labStartDate.add_Click($handler_labStartDate_Click)
$formTrackLog.Controls.Add($labStartDate)
$dgResults.AllowSorting = $true
$dgResults.Anchor = 15
$dgResults.DataBindings.DefaultDataSourceUpdateMode = 0
$dgResults.DataMember = ""
$dgResults.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 9
$System_Drawing_Point.Y = 108
$dgResults.Location = $System_Drawing_Point
$dgResults.Name = "dgResults"
$dgResults.PreferredColumnWidth = 200
$dgResults.ReadOnly = $True
$dgResults.RowHeadersVisible = $false
$dgResults.RowHeaderWidth = 60
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 500
$System_Drawing_Size.Width = 990
$dgResults.Size = $System_Drawing_Size
$dgResults.TabIndex = 9
$dgResults.add_Navigate($handler_dgResults_Navigate)
$formTrackLog.Controls.Add($dgResults)
$dateTimePickerEnd.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 360
$System_Drawing_Point.Y = 33
$dateTimePickerEnd.Location = $System_Drawing_Point
$dateTimePickerEnd.Name = "dateTimePicker2"
$System_Drawing_SizeEnd = New-Object System.Drawing.Size
$System_Drawing_SizeEnd.Height = 20
$System_Drawing_SizeEnd.Width = 200
$dateTimePickerEnd.Size = $System_Drawing_SizeEnd
$dateTimePickerEnd.TabIndex = 8
$formTrackLog.Controls.Add($dateTimePickerEnd)
$dateTimePickerStart.CustomFormat = "MM/DD/YYYY 00:00:01"
$dateTimePickerStart.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 360
$System_Drawing_Point.Y = 3
$dateTimePickerStart.Location = $System_Drawing_Point
$dateTimePickerStart.Name = "dateTimePicker1"
$System_Drawing_SizeStart = New-Object System.Drawing.Size
$System_Drawing_SizeStart.Height = 20
$System_Drawing_SizeStart.Width = 200
$dateTimePickerStart.Size = $System_Drawing_SizeStart
$dateTimePickerStart.TabIndex = 7
$formTrackLog.Controls.Add($dateTimePickerStart)
$txtBoxRecipients.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 40
$System_Drawing_Point.Y = 30
$txtBoxRecipients.Location = $System_Drawing_Point
$txtBoxRecipients.Name = "txtBoxRecipients"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 250
$txtBoxRecipients.Size = $System_Drawing_Size
$txtBoxRecipients.TabIndex = 4
$txtBoxRecipients.Text = ""
$formTrackLog.Controls.Add($txtBoxRecipients)
$txtBoxSubject.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 65
$System_Drawing_Point.Y = 65
$txtBoxSubject.Location = $System_Drawing_Point
$txtBoxSubject.Name = "txtBoxSubject"
$System_Drawing_SizeSubject = New-Object System.Drawing.Size
$System_Drawing_SizeSubject.Height = 20
$System_Drawing_SizeSubject.Width = 495
$txtBoxSubject.Size = $System_Drawing_SizeSubject
$txtBoxSubject.TabIndex = 4
$txtBoxSubject.Text = ""
$formTrackLog.Controls.Add($txtBoxSubject)
$txtBoxSenders.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 40
$System_Drawing_Point.Y = 3
$txtBoxSenders.Location = $System_Drawing_Point
$txtBoxSenders.Name = "txtBoxSenders"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 250
$txtBoxSenders.Size = $System_Drawing_Size
$txtBoxSenders.TabIndex = 3
$txtBoxSenders.Text = ""
$formTrackLog.Controls.Add($txtBoxSenders)
$buttonGo.DataBindings.DefaultDataSourceUpdateMode = 0
$buttonGo.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 755
$System_Drawing_Point.Y = 3
$buttonGo.Location = $System_Drawing_Point
$buttonGo.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 25
$System_Drawing_Size.Width = 240
$buttonGo.Size = $System_Drawing_Size
$buttonGo.TabIndex = 1
$buttonGo.Text = ">>> Run <<<"
$buttonGo.UseVisualStyleBackColor = $True
$buttonGo.add_Click($processData)
$formTrackLog.Controls.Add($buttonGo)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 3
$System_Drawing_Point.Y = 5
$labFrom.Location = $System_Drawing_Point
$labFrom.Name = "labFrom"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 54
$labFrom.Size = $System_Drawing_Size
$labFrom.TabIndex = 11
$labFrom.Text = "From:"
$formTrackLog.Controls.Add($labFrom)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 3
$System_Drawing_Point.Y = 32
$labTo.Location = $System_Drawing_Point
$labTo.Name = "labTo"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 54
$labTo.Size = $System_Drawing_Size
$labTo.TabIndex = 11
$labTo.Text = "To:"
$formTrackLog.Controls.Add($labTo)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 3
$System_Drawing_Point.Y = 67
$labSubject.Location = $System_Drawing_Point
$labSubject.Name = "labSubject"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 54
$labSubject.Size = $System_Drawing_Size
$labSubject.TabIndex = 11
$labSubject.Text = "Subject:"
$formTrackLog.Controls.Add($labSubject)
$System_Drawing_SizeCSV = New-Object System.Drawing.Size
$System_Drawing_SizeCSV.Width = 84
$System_Drawing_SizeCSV.Height = 24
$chkBoxCSV.Size = $System_Drawing_SizeCSV
$chkBoxCSV.TabIndex = 1
$chkBoxCSV.Text = "Export CSV"
$System_Drawing_PointCSV = New-Object System.Drawing.Point
$System_Drawing_PointCSV.X = 570
$System_Drawing_PointCSV.Y = 64
$chkBoxCSV.Location = $System_Drawing_PointCSV
$chkBoxCSV.DataBindings.DefaultDataSourceUpdateMode = 0
$chkBoxCSV.Name = "chkBoxCSV"
$formTrackLog.Controls.Add($chkBoxCSV)
$System_Drawing_SizeMail = New-Object System.Drawing.Size
$System_Drawing_SizeMail.Width = 90
$System_Drawing_SizeMail.Height = 24
$chkBoxMail.Size = $System_Drawing_SizeMail
$chkBoxMail.TabIndex = 1
$chkBoxMail.Text = "Send by mail"
$System_Drawing_PointMail = New-Object System.Drawing.Point
$System_Drawing_PointMail.X = 570
$System_Drawing_PointMail.Y = 34
$chkBoxMail.Location = $System_Drawing_PointMail
$chkBoxMail.DataBindings.DefaultDataSourceUpdateMode = 0
$chkBoxMail.Name = "chkBoxMail"
$formTrackLog.Controls.Add($chkBoxMail)
$txtBoxMail.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_PointMail = New-Object System.Drawing.Point
$System_Drawing_PointMail.X = 660
$System_Drawing_PointMail.Y = 34
$txtBoxMail.Location = $System_Drawing_PointMail
$txtBoxMail.Name = "txtBoxMail"
$System_Drawing_SizeMail = New-Object System.Drawing.Size
$System_Drawing_SizeMail.Height = 20
$System_Drawing_SizeMail.Width = 110
$txtBoxMail.Size = $System_Drawing_SizeMail
$txtBoxMail.TabIndex = 3
$txtBoxMail.Text = "SMTP Server"
$formTrackLog.Controls.Add($txtBoxMail)
$txtBoxFromMail.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_PointFromMail = New-Object System.Drawing.Point
$System_Drawing_PointFromMail.X = 775
$System_Drawing_PointFromMail.Y = 34
$txtBoxFromMail.Location = $System_Drawing_PointFromMail
$txtBoxFromMail.Name = "txtBoxFromMail"
$System_Drawing_SizeFromMail = New-Object System.Drawing.Size
$System_Drawing_SizeFromMail.Height = 20
$System_Drawing_SizeFromMail.Width = 110
$txtBoxFromMail.Size = $System_Drawing_SizeFromMail
$txtBoxFromMail.TabIndex = 3
$txtBoxFromMail.Text = "From"
$formTrackLog.Controls.Add($txtBoxFromMail)
$txtBoxToMail.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_PointToMail = New-Object System.Drawing.Point
$System_Drawing_PointToMail.X = 890
$System_Drawing_PointToMail.Y = 34
$txtBoxToMail.Location = $System_Drawing_PointToMail
$txtBoxToMail.Name = "txtBoxToMail"
$System_Drawing_SizeToMail = New-Object System.Drawing.Size
$System_Drawing_SizeToMail.Height = 20
$System_Drawing_SizeToMail.Width = 110
$txtBoxToMail.Size = $System_Drawing_SizeToMail
$txtBoxToMail.TabIndex = 3
$txtBoxToMail.Text = "To"
$formTrackLog.Controls.Add($txtBoxToMail)
$txtBoxCSV.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_PointTXTCSV = New-Object System.Drawing.Point
$System_Drawing_PointTXTCSV.X = 660
$System_Drawing_PointTXTCSV.Y = 65
$txtBoxCSV.Location = $System_Drawing_PointTXTCSV
$txtBoxCSV.Name = "txtBoxCSV"
$System_Drawing_SizeTXTCSV = New-Object System.Drawing.Size
$System_Drawing_SizeTXTCSV.Height = 20
$System_Drawing_SizeTXTCSV.Width = 250
$txtBoxCSV.Size = $System_Drawing_SizeTXTCSV
$txtBoxCSV.TabIndex = 3
$txtBoxCSV.Text = "Path to csv file"
$formTrackLog.Controls.Add($txtBoxCSV)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $formTrackLog.WindowState
#Init the OnLoad event to correct the initial state of the form
$formTrackLog.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$formTrackLog.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm

252
powershell/exchange/Set-Webserver.ps1

@ -0,0 +1,252 @@ @@ -0,0 +1,252 @@
<#
.SYNOPSIS
Configures IIS log file settings
Thomas Stensitzki
THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
Version 1.1, 2016-07-28
Ideas, comments and suggestions to support@granikos.eu
Some parts (c) Michel de Rooij, michel@eightwone.com
.LINK
http://www.granikos.eu/en/scripts
.DESCRIPTION
This script reconfigures the IIS log folder to target a different folder besides the
default C:\inetpub\logs folder. Additionally the log settings can be adjusted as well.
The script changes the default log file location and settings on a server level. By
default the settings are inherited by websites. If manual changes have been made on
a webite level, not all settings will be inherited.
.NOTES
Requirements
- Windows Server 2008 R2 SP1, Windows Server 2012 or Windows Server 2012 R2
Revision History
--------------------------------------------------------------------------------
1.0 Initial community release
1.1 PowerShell hygiene applied, some typo fixes
.PARAMETER LogFolderPath
New IIS log folder path, i.e. D:\IISLogs. Default is an empty string.
.PARAMETER LogFilePeriod
Log file period (interval), Hourly|Daily|Weekly|Monthly|MaxSize
MaxSize configuration not yet implemented
.PARAMETER LocalTimeRollover
Boolean parameter indicating, if the local time shall be used for filenames and rollover
Default $FALSE
.EXAMPLE
Change the IIS log file location to D:\IISLogs
.\Set-Webserver.ps1 -LogFolderPath D:\IISLogs
.EXAMPLE
Change the IIS log period to an hourly period
.\Set-Webserver.ps1 -LogFilePeriod Hourly
.EXAMPLE
Use the local time for filenames and log file rollover
.\Set-Webserver.ps1 -LocalTimeRollover $true
#>
Param(
[parameter(Position=0,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='New IIS log folder path, i.e. D:\IISLogs')]
[string]$LogFolderPath = '',
[parameter(Position=1,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='Log file period (Hourly|Daily|Weekly|Monthly|MaxSize)')]
[string]$LogFilePeriod = '',
[parameter(Position=2,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='$true/$false indicating, if the local time shall be used for filenames and rollover')]
[bool]$LocalTimeRollover=$false
)
process{
# log file property settings
$lfpDirectory = 'directory'
$lfpPeriod = 'period'
$lfpLocalTimeRollover = 'localTimeRollover'
# Check if folder exists, otherwise create folder
function Create-Folder
{
param
(
[string]
$folderPath
)
Write-Verbose "Evaluating IIS folder path: $folderPath"
if(-not ($folderPath -eq ''))
{
if(-not (Test-Path $folderPath))
{
Write-Host "Creating IIS log folder path: $folderPath"
New-Item -Path $folderPath -ItemType directory | Out-Null
}
else
{
Write-Host "Folder $folderPath already exsists"
}
}
}
# Change IIS log file setting
function ChangeIisLogSetting
{
param
(
[string]
$settingName,
[string]
$settingValue
)
try
{
Write-Verbose "Configuring IIS log setting $settingsName to value $settingsValue"
$logConfig = @{$settingName=$settingValue}
Set-WebConfigurationProperty 'system.applicationHost/sites/siteDefaults' -Name logFile -Value $logConfig
}
catch [system.exception]
{
Write-Host 'An error occured while trying to write IIS settings. Please check permissions of your account and ensure that PowerShell is running from an elevated prompt.' -ForegroundColor Red
}
}
# Change IIS default log location and other IIS log settings
function ChangeIisLogPath
{
param
(
[string]
$folderPath
)
Write-Verbose "IIS Log Folder Path to configure: $folderPath"
Write-Host "Configuring IIS default log location to '$folderPath'"
if(Test-Path $folderPath)
{
ChangeIisLogSetting $lfpDirectory $folderPath
}
else
{
Write-Host "New IIS log folder $folderPath does not exist. IIS log file folder configuration has not been changed" -ForegroundColor Red
}
}
# Change IIS log period
function ChangeIisLogPeriod
{
param
(
[string]
$logPeriod
)
if($AllowedLogFilePeriod -contains $logPeriod)
{
Write-Verbose "Changing IIS log periog to: $logPeriod"
ChangeIisLogSetting $lfpPeriod $logPeriod
}
}
# Change IIS LocalTimeRollover setting
function ChangeLocalTimeRollover
{
param
(
[bool]
$logLocalTimeRollover
)
Write-Verbose "Changing IIS log local time rollover to: $logLocalTimeRollover"
ChangeIisLogSetting $lfpLocalTimeRollover $logLocalTimeRollover
}
function CheckWindowsFeature
{
param
(
[string]
$MajorOSVersion
)
$featureInstalled = $false
If ($MajorOSVersion -eq '6.1')
{
Import-Module ServerManager
If(!(Get-Module ServerManager))
{
Write-Error 'Problem loading ServerManager module'
Exit 'ServerManager module could not be loaded!'
}
}
Write-Verbose "Checking, if Windows Feature 'Web-Server' is installed"
$feature = Get-WindowsFeature Web-Server
$featureInstalled = [bool]($feature.Installed)
Write-Verbose "Feature 'Web-Server' installed: $featureInstalled"
return( $featureInstalled )
}
## Main
Write-Verbose 'Script started'
$MajorOSVersion= [string](Get-WmiObject Win32_OperatingSystem | Select-Object Version | Select-Object @{n='Major';e={($_.Version.Split('.')[0]+'.'+$_.Version.Split('.')[1])}}).Major
$AllowedLogFilePeriod = @('Hourly','Daily','Weekly','Monthly') # MaxSize not yet implemented
if( CheckWindowsFeature($MajorOSVersion) )
{
Write-Verbose 'Configuring IIS log file settings'
if($LogFolderPath -ne '')
{
# Create IIS Log File Folder, independent from server role
Create-Folder $LogFolderPath
#Change log file settings
ChangeIisLogPath $LogFolderPath $LogFilePeriod
}
if($LogFilePeriod -ne '')
{
ChangeIisLogPeriod $LogFilePeriod
}
if($LocalTimeRollover -ne $null)
{
ChangeLocalTimeRollover $LocalTimeRollover
}
}
else
{
Write-Host 'IIS is currently not installed. Either add the windows feature manually or install Exchange first and adjust the IIS log file location afterwards.' -ForegroundColor Red
}
Write-Verbose 'Script ended'
} #Process

31
powershell/exchange/enable-ad-user-mailbox.ps1

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
$LogFile="C:\add_ad_user_mail-$((Get-Date).ToString('yyyy-MM-dd')).log"
Start-Transcript -path $LogFile -append
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [Start]"
Import-module activedirectory
# $since=(Get-Date).AddDays(-4).ToUniversalTime().ToString('yyyyMMddHHmmss.fZ')
$since=(Get-Date).AddMinutes(-20).ToUniversalTime().ToString('yyyyMMddHHmmss.fZ')
$users=Get-ADUser -LDAPfilter "(&(objectCategory=person)(objectClass=user)(Name=*)(!(!UserPrincipalName=*))(whenCreated>=$since))" -searchBase 'CN=Users,DC=bloks,DC=local'
foreach($user in $users)
{
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [User] $($user.SamAccountName)"
if (Get-Mailbox -Identity $user.SamAccountName 2>$null)
{
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [User] $($user.SamAccountName): It's alive"
}
else
{
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [User] $($user.SamAccountName): enable mailbox"
Enable-Mailbox -Identity $user.SamAccountName
}
}
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [End]"
Stop-Transcript

176
shell/get_proc_mem.sh

@ -32,6 +32,164 @@ COLOR_GRAY="${COLOR_GRAY:-\e[1;90m}" @@ -32,6 +32,164 @@ COLOR_GRAY="${COLOR_GRAY:-\e[1;90m}"
COLOR_OFF="${COLOR_OFF:-\e[0m}"
NOCOLOR="${NOCOLOR:-false}"
time_data=""
mem_total_data=""
mem_free_data=""
mem_available_data=""
mem_rss_data=""
mem_pss_data=""
mem_uss_data=""
cpu_used_data=""
trap trap::info 1 2 3 15 EXIT
######################################################################################################
# function
######################################################################################################
function trap::info() {
cat << EOF > pid_${PID}_line.json
option = {
title: {
text: '内存监控',
subtext: 'PID: ${PID}'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['mem_total', 'mem_free', 'mem_available', 'pid_mem_rss', 'pid_mem_pss', 'pid_mem_uss', 'pid_cpu_used']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: [${time_data/,}]
},
yAxis: [
{
type: "value",
name: "内存 / MB",
nameLocation: 'center',
nameGap: 45
},
{
type: "value",
name: "CPU使用率 / %",
nameLocation: 'center',
nameGap: 45
}
],
series: [
{
name: 'mem_total',
type: 'line',
smooth: true,
data: [${mem_total_data/,}],
markPoint: {
data: [{
name: '最大值',
type: 'max'
}]
}
},
{
name: 'mem_free',
type: 'line',
smooth: true,
data: [${mem_free_data/,}],
markPoint: {
data: [{
name: '最小值',
type: 'min'
}]
}
},
{
name: 'mem_available',
type: 'line',
smooth: true,
data: [${mem_available_data/,}],
markPoint: {
data: [{
name: '最小值',
type: 'min'
}]
}
},
{
name: 'pid_mem_rss',
type: 'line',
smooth: true,
data: [${mem_rss_data/,}],
markPoint: {
data: [{
name: '最大值',
type: 'max'
}]
}
},
{
name: 'pid_mem_pss',
type: 'line',
smooth: true,
data: [${mem_pss_data/,}],
markPoint: {
data: [{
name: '最大值',
type: 'max'
}]
}
},
{
name: 'pid_mem_uss',
type: 'line',
smooth: true,
data: [${mem_uss_data/,}],
markPoint: {
data: [{
name: '最大值',
type: 'max'
}]
}
},
{
name: 'pid_cpu_used',
type: 'line',
smooth: true,
yAxisIndex: 1,
data: [${cpu_used_data/,}],
markPoint: {
data: [{
name: '最大值',
type: 'max'
}]
}
}
]
};
EOF
echo -e "
\n${COLOR_GREEN}
Config File: pid_${PID}_line.json
GO TO URL: https://echarts.apache.org/next/examples/en/editor.html
${COLOR_OFF}
"
trap '' EXIT
exit
}
######################################################################################################
# function
######################################################################################################
@ -43,6 +201,7 @@ function get::meminfo() { @@ -43,6 +201,7 @@ function get::meminfo() {
pid_smaps=$(cat /proc/${PID}/smaps)
[ "$pid_smaps" == "" ] && { echo -e "${COLOR_RED}[Error]${COLOR_OFF} /proc/${PID}/smaps is empty!"; exit 1; }
cpu_used=$(ps -opcpu= -p "${PID}")
mem_info=$(cat /proc/meminfo)
mem_total=$(printf "%s" "${mem_info}"| awk '/^MemTotal:/ {print $2}')
@ -77,7 +236,22 @@ function get::meminfo_loop() { @@ -77,7 +236,22 @@ function get::meminfo_loop() {
get::pidinfo
while [ $count -lt $RETRIES ] ; do
get::meminfo
echo -e "Date: $(date +'%Y-%m-%d %T') ${COLOR_PURPLE}MemTotal: $((mem_total/1024))MB${COLOR_OFF} ${COLOR_GREEN}MemFree: $((mem_free/1024))MB${COLOR_OFF} ${COLOR_BLUE}MemAvailable: $((mem_available/1024))MB${COLOR_OFF} ${COLOR_YELLOW}RSS: $((${rss}/1024))MB${COLOR_OFF} ${COLOR_CYAN}PSS: $((${pss}/1024))MB${COLOR_OFF} ${COLOR_RED}USS: $(( (${private_clean} + ${private_dirty}) /1024 ))MB${COLOR_OFF}"
d=$(date +'%Y-%m-%d %T')
mem_total=$((mem_total/1024))
mem_free=$((mem_free/1024))
mem_available=$((mem_available/1024))
mem_rss=$((${rss}/1024))
mem_pss=$((${pss}/1024))
mem_uss=$(( (${private_clean} + ${private_dirty}) /1024 ))
echo -e "Date: ${d} ${COLOR_PURPLE}MemTotal: ${mem_total}MB${COLOR_OFF} ${COLOR_GREEN}MemFree: ${mem_free}MB${COLOR_OFF} ${COLOR_BLUE}MemAvailable: ${mem_available}MB${COLOR_OFF} ${COLOR_YELLOW}RSS: ${mem_rss}MB${COLOR_OFF} ${COLOR_CYAN}PSS: ${mem_pss}MB${COLOR_OFF} ${COLOR_RED}USS: ${mem_uss}MB${COLOR_OFF} CPU: ${cpu_used}%"
time_data="${time_data},'${d}'"
mem_total_data="${mem_total_data},'${mem_total}'"
mem_free_data="${mem_free_data},'${mem_free}'"
mem_available_data="${mem_available_data},'${mem_available}'"
mem_rss_data="${mem_rss_data},'${mem_rss}'"
mem_uss_data="${mem_uss_data},'${mem_uss}'"
mem_pss_data="${mem_pss_data},'${mem_pss}'"
cpu_used_data="${cpu_used_data},'${cpu_used}'"
sleep $WAIT
count=$(($count + 1))
done

2
shell/k8s/k8s-app-info.sh

@ -61,7 +61,7 @@ function get::selector { @@ -61,7 +61,7 @@ function get::selector {
echo -ne "Get Selector"
if [[ "${SELECTOR}" == "" ]]; then
selflink=$(kubectl -n $NAMESPACE get deployment $APPNAME -o yaml --ignore-not-found 2>/dev/null | awk '/selfLink:/ {print $2}')
SELECTOR=$(kubectl get --raw "${selflink}/scale" 2>/dev/null | sed 's/.*selector":"\(.*\)".*/\1/g')
SELECTOR=$(kubectl get --raw "${selflink}/scale" 2>/dev/null | sed 's/.*[S|s]elector":"\(.*\)".*/\1/g')
fi
if [[ "${SELECTOR}" == "" ]]; then

Loading…
Cancel
Save