mirror of https://github.com/lework/script
lework
4 years ago
10 changed files with 29216 additions and 334 deletions
@ -1,333 +1,349 @@ |
|||||||
@echo off |
@echo off |
||||||
Setlocal enabledelayedexpansion |
Setlocal enabledelayedexpansion |
||||||
::CODER BY lework |
::CODER BY lework |
||||||
|
:: 虚拟机需安装vmtool |
||||||
title VMware Workstation 虚拟机批量管理 |
|
||||||
|
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 Workstation\vmrun.exe" SET VMwarePath=%PROGRAMFILES%\VMWare\VMWare Workstation |
||||||
IF EXIST "%PROGRAMFILES%\VMware\VMware VIX\vmrun.exe" SET VMwarePath=%PROGRAMFILES%\VMware\VMware VIX |
IF EXIST "%PROGRAMFILES(X86)%\VMWare\VMWare Workstation\vmrun.exe" SET VMwarePath=%PROGRAMFILES(X86)%\VMWare\VMWare Workstation |
||||||
IF EXIST "%PROGRAMFILES(X86)%\VMware\VMware VIX\vmrun.exe" SET VMRUN=%PROGRAMFILES(X86)%\VMware\VMware VIX |
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" |
:: VMware安装地址 |
||||||
:: 虚拟机存放目录 |
# set VMwarePath="C:\Program Files (x86)\VMware\VMware Workstation" |
||||||
set VMpath="D:\Virtual Machines" |
:: 虚拟机存放目录 |
||||||
:: 虚拟机名称 |
set VMpath="D:\Virtual Machines" |
||||||
set VMname=CentOS_7.8_x64_node |
:: 虚拟机名称 |
||||||
:: 虚拟机快照名称 |
set VMname=Debian_10.2_x64_node |
||||||
set VMSnapshot=init |
:: 虚拟机快照名称 |
||||||
:: 新建虚拟机数目 |
set VMSnapshot=init |
||||||
set VMcount=5 |
:: 新建虚拟机数目 |
||||||
:: 虚拟机owa模板位置 |
set VMcount=5 |
||||||
set VMowa="D:\vmware owa\CentOS_7.8_x64_base.ova" |
:: 虚拟机owa模板位置 |
||||||
:: 模板系统用户名 |
set VMowa="D:\vmware owa\Debian_10.2_x64_base.ova" |
||||||
set VMuser=root |
:: 模板系统用户名 |
||||||
:: 模板系统密码 |
set VMuser=root |
||||||
set VMpass=123456 |
:: 模板系统密码 |
||||||
:: 虚拟机网络 |
set VMpass=123456 |
||||||
set VMnetwork=192.168.77 |
:: 虚拟机网络 |
||||||
:: 虚拟机ip开始地址 |
set VMnetwork=192.168.77 |
||||||
set VMipStart=130 |
:: 虚拟机ip开始地址 |
||||||
|
set VMipStart=180 |
||||||
|
|
||||||
|
|
||||||
:init |
|
||||||
cls |
:init |
||||||
echo. |
cls |
||||||
echo. VMware Workstation 虚拟机批量管理 |
echo. |
||||||
echo. |
echo. VMware Workstation 虚拟机批量管理 |
||||||
echo ============================== |
echo. |
||||||
echo. |
echo ============================== |
||||||
echo. 输入 0 一键初始化(包含1,2,3步骤) |
echo. |
||||||
echo. 输入 1 创建虚拟机 |
echo. 输入 0 一键初始化(包含1,2,3步骤) |
||||||
echo. 输入 2 设置ip地址 |
echo. 输入 1 创建虚拟机 |
||||||
echo. 输入 3 创建快照 |
echo. 输入 2 设置ip地址 |
||||||
echo. 输入 4 查看启动的虚拟机 |
echo. 输入 3 创建快照 |
||||||
echo. 输入 5 启动虚拟机 |
echo. 输入 4 查看启动的虚拟机 |
||||||
echo. 输入 6 关闭虚拟机 |
echo. 输入 5 启动虚拟机 |
||||||
echo. 输入 7 重启虚拟机 |
echo. 输入 6 关闭虚拟机 |
||||||
echo. 输入 8 恢复虚拟机快照 |
echo. 输入 7 重启虚拟机 |
||||||
echo. 输入 9 删除虚拟机 |
echo. 输入 8 恢复虚拟机快照 |
||||||
echo. 输入 10 挂起虚拟机 |
echo. 输入 9 删除虚拟机 |
||||||
echo. 输入 11 暂停虚拟机 |
echo. 输入 10 挂起虚拟机 |
||||||
echo. 输入 12 恢复虚拟机 |
echo. 输入 11 暂停虚拟机 |
||||||
echo. 输入 q 退出 |
echo. 输入 12 恢复虚拟机 |
||||||
echo. |
echo. 输入 13 删除快照 |
||||||
echo ============================== |
echo. 输入 q 退出 |
||||||
echo. |
echo. |
||||||
|
echo ============================== |
||||||
cd /d "%VMwarePath%" |
echo. |
||||||
|
|
||||||
set "input=" |
cd /d "%VMwarePath%" |
||||||
set /p input=请输入您的选择: |
|
||||||
echo. |
set "input=" |
||||||
if "%input%"=="q" goto exit |
set /p input=请输入您的选择: |
||||||
if "%input%"=="0" goto oneKey |
echo. |
||||||
if "%input%"=="1" goto create |
if "%input%"=="q" goto exit |
||||||
if "%input%"=="2" goto setip |
if "%input%"=="0" goto oneKey |
||||||
if "%input%"=="3" goto snapshot |
if "%input%"=="1" goto create |
||||||
if "%input%"=="4" goto list |
if "%input%"=="2" goto setip |
||||||
if "%input%"=="5" goto start |
if "%input%"=="3" goto snapshot |
||||||
if "%input%"=="6" goto stop |
if "%input%"=="4" goto list |
||||||
if "%input%"=="7" goto restart |
if "%input%"=="5" goto start |
||||||
if "%input%"=="8" goto revertToSnapshot |
if "%input%"=="6" goto stop |
||||||
if "%input%"=="9" goto delete |
if "%input%"=="7" goto restart |
||||||
if "%input%"=="10" goto suspend |
if "%input%"=="8" goto revertToSnapshot |
||||||
if "%input%"=="11" goto pausevm |
if "%input%"=="9" goto delete |
||||||
if "%input%"=="12" goto unpausevm |
if "%input%"=="10" goto suspend |
||||||
|
if "%input%"=="11" goto pausevm |
||||||
:wait |
if "%input%"=="12" goto unpausevm |
||||||
echo. |
if "%input%"=="13" goto delsnapshot |
||||||
echo 执行完毕, 等待中... |
|
||||||
for /l %%a in (1,1,5) do ( |
:wait |
||||||
ping /n 2 127.1>nul |
echo. |
||||||
set /p a=^><nul |
echo 执行完毕, 等待中... |
||||||
) |
for /l %%a in (1,1,5) do ( |
||||||
|
ping /n 2 127.1>nul |
||||||
cls |
set /p a=^><nul |
||||||
goto init |
) |
||||||
|
|
||||||
:oneKey |
cls |
||||||
echo [创建虚拟机...] |
goto init |
||||||
set "cname=" |
|
||||||
set "ccount=" |
:oneKey |
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
echo [创建虚拟机...] |
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
set "cname=" |
||||||
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
set "ccount=" |
||||||
set /p VMuser=请输入用户名(默认:%VMuser%): |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
set /p VMpass=请输入密码(默认:%VMpass%): |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%): |
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
||||||
|
set /p VMuser=请输入用户名(默认:%VMuser%): |
||||||
echo. |
set /p VMpass=请输入密码(默认:%VMpass%): |
||||||
echo ============= |
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%): |
||||||
echo. |
|
||||||
echo. 虚拟机模板: !VMowa! |
echo. |
||||||
echo. 虚拟机存放目录: !VMpath! |
echo ============= |
||||||
echo. 虚拟机名称: !VMname! |
echo. |
||||||
echo. 虚拟机数量: !VMcount! |
echo. 虚拟机模板: !VMowa! |
||||||
echo. 虚拟机初始快照名称: !VMSnapshot! |
echo. 虚拟机存放目录: !VMpath! |
||||||
echo. 虚拟机用户名: !VMuser! |
echo. 虚拟机名称: !VMname! |
||||||
echo. 虚拟机密码: !VMpass! |
echo. 虚拟机数量: !VMcount! |
||||||
echo. 虚拟机网段: !VMnetwork! |
echo. 虚拟机初始快照名称: !VMSnapshot! |
||||||
echo. 虚拟机ip开始地址: !VMipStart! |
echo. 虚拟机用户名: !VMuser! |
||||||
echo. |
echo. 虚拟机密码: !VMpass! |
||||||
echo ============= |
echo. 虚拟机网段: !VMnetwork! |
||||||
|
echo. 虚拟机ip开始地址: !VMipStart! |
||||||
for /l %%a in (1,1,!VMcount!) do ( |
echo. |
||||||
echo. |
echo ============= |
||||||
echo 创建虚拟机: !VMname!%%a |
|
||||||
cd OVFTool |
for /l %%a in (1,1,!VMcount!) do ( |
||||||
ovftool --name=!VMname!%%a !VMowa! !VMpath! |
echo. |
||||||
cd .. |
echo 创建虚拟机: !VMname!%%a |
||||||
echo. |
cd OVFTool |
||||||
echo 启动虚拟机: !VMname!%%a |
ovftool --name=!VMname!%%a !VMowa! !VMpath! |
||||||
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx |
cd .. |
||||||
) |
echo. |
||||||
|
echo 启动虚拟机: !VMname!%%a |
||||||
echo. |
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx |
||||||
echo 设置ip: |
) |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
|
||||||
set name=!VMname!%%a |
echo. |
||||||
set /a num=%VMipStart%+%%a-1 |
echo 设置ip: |
||||||
set ip=!VMnetwork!.!num! |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
echo !name!:!ip! |
set name=!VMname!%%a |
||||||
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 |
set /a num=%VMipStart%+%%a-1 |
||||||
) |
set ip=!VMnetwork!.!num! |
||||||
|
echo !name!:!ip! |
||||||
echo. |
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 创建快照: |
) |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
|
||||||
set name=!VMname!%%a |
echo. |
||||||
echo !name! |
echo 创建快照: |
||||||
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui |
set name=!VMname!%%a |
||||||
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui |
echo !name! |
||||||
) |
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
||||||
|
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui |
||||||
goto wait |
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui |
||||||
|
) |
||||||
|
|
||||||
:start |
goto wait |
||||||
echo [启动虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:start |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo [启动虚拟机...] |
||||||
set name=!VMname!%%a |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo !name! |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
) |
set name=!VMname!%%a |
||||||
goto wait |
echo !name! |
||||||
|
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:stop |
goto wait |
||||||
echo [关闭虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:stop |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo [关闭虚拟机...] |
||||||
set name=!VMname!%%a |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo !name! |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
) |
set name=!VMname!%%a |
||||||
goto wait |
echo !name! |
||||||
|
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:restart |
goto wait |
||||||
echo [重启虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:restart |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo [重启虚拟机...] |
||||||
set name=!VMname!%%a |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo !name! |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui |
set name=!VMname!%%a |
||||||
) |
echo !name! |
||||||
goto wait |
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
||||||
|
vmrun -T ws start !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:suspend |
goto wait |
||||||
echo [挂起虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:suspend |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo [挂起虚拟机...] |
||||||
set name=!VMname!%%a |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo !name! |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
vmrun -T ws suspend !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
) |
set name=!VMname!%%a |
||||||
goto wait |
echo !name! |
||||||
|
vmrun -T ws suspend !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:pausevm |
goto wait |
||||||
echo [暂停虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:pausevm |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo [暂停虚拟机...] |
||||||
set name=!VMname!%%a |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo !name! |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
vmrun -T ws pause !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
) |
set name=!VMname!%%a |
||||||
goto wait |
echo !name! |
||||||
|
vmrun -T ws pause !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:unpausevm |
goto wait |
||||||
echo [恢复虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:unpausevm |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo [恢复虚拟机...] |
||||||
set name=!VMname!%%a |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo !name! |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
vmrun -T ws unpause !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
) |
set name=!VMname!%%a |
||||||
goto wait |
echo !name! |
||||||
|
vmrun -T ws unpause !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:revertToSnapshot |
goto wait |
||||||
echo [恢复虚拟机快照...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:revertToSnapshot |
||||||
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
echo [恢复虚拟机快照...] |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
set name=!VMname!%%a |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
echo !name! |
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
||||||
vmrun -T ws revertToSnapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
) |
set name=!VMname!%%a |
||||||
goto wait |
echo !name! |
||||||
|
vmrun -T ws revertToSnapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui |
||||||
:list |
) |
||||||
echo [虚拟机启动列表...] |
goto wait |
||||||
vmrun list |
|
||||||
echo. |
:list |
||||||
pause |
echo [虚拟机启动列表...] |
||||||
goto wait |
vmrun list |
||||||
|
echo. |
||||||
|
pause |
||||||
:create |
goto wait |
||||||
echo [创建虚拟机...] |
|
||||||
set "cname=" |
|
||||||
set "ccount=" |
:create |
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
echo [创建虚拟机...] |
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
set "cname=" |
||||||
|
set "ccount=" |
||||||
echo. |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo ============= |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
echo. |
|
||||||
echo. 虚拟机模板: !VMowa! |
echo. |
||||||
echo. 虚拟机存放目录: !VMpath! |
echo ============= |
||||||
echo. 虚拟机名称: !VMname! |
echo. |
||||||
echo. 虚拟机数量: !VMcount! |
echo. 虚拟机模板: !VMowa! |
||||||
echo. |
echo. 虚拟机存放目录: !VMpath! |
||||||
echo ============= |
echo. 虚拟机名称: !VMname! |
||||||
|
echo. 虚拟机数量: !VMcount! |
||||||
for /l %%a in (1,1,!VMcount!) do ( |
echo. |
||||||
echo. |
echo ============= |
||||||
echo 创建虚拟机: !VMname!%%a |
|
||||||
cd OVFTool |
for /l %%a in (1,1,!VMcount!) do ( |
||||||
ovftool --name=!VMname!%%a !VMowa! !VMpath! |
echo. |
||||||
cd .. |
echo 创建虚拟机: !VMname!%%a |
||||||
echo 启动虚拟机: !VMname!%%a |
cd OVFTool |
||||||
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx |
ovftool --name=!VMname!%%a !VMowa! !VMpath! |
||||||
) |
cd .. |
||||||
goto wait |
echo 启动虚拟机: !VMname!%%a |
||||||
|
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx |
||||||
|
) |
||||||
:delete |
goto wait |
||||||
echo [删除虚拟机...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:delete |
||||||
set is=no |
echo [删除虚拟机...] |
||||||
set /p is=确定删除么?(yes/no, 默认:%is%): |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
|
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
if "%is%" NEQ "yes" ( |
set is=no |
||||||
echo 已取消 |
set /p is=确定删除么?(yes/no, 默认:%is%): |
||||||
goto wait |
|
||||||
) |
if "%is%" NEQ "yes" ( |
||||||
|
echo 已取消 |
||||||
echo 关闭vmware |
goto wait |
||||||
taskkill /f /t /im vmware.exe |
) |
||||||
|
|
||||||
for /l %%a in (1,1,%VMcount%) do ( |
echo 关闭vmware |
||||||
set name=!VMname!%%a |
taskkill /f /t /im vmware.exe |
||||||
echo 删除: !name! |
|
||||||
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
vmrun deleteVM !VMpath!\!name!\!name!.vmx nogui |
set name=!VMname!%%a |
||||||
) |
echo 删除: !name! |
||||||
goto wait |
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
||||||
|
vmrun deleteVM !VMpath!\!name!\!name!.vmx nogui |
||||||
|
) |
||||||
:snapshot |
goto wait |
||||||
echo [创建快照...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
|
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
:snapshot |
||||||
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
echo [创建快照...] |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
set name=!VMname!%%a |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
echo !name! |
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
||||||
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
for /l %%a in (1,1,%VMcount%) do ( |
||||||
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui |
set name=!VMname!%%a |
||||||
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui |
echo !name! |
||||||
) |
vmrun -T ws stop !VMpath!\!name!\!name!.vmx nogui |
||||||
goto wait |
vmrun -T ws snapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! nogui |
||||||
|
vmrun -T ws start !VMpath!\!VMname!%%a\!VMname!%%a.vmx nogui |
||||||
|
) |
||||||
:setip |
goto wait |
||||||
echo [设置ip地址...] |
|
||||||
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
:delsnapshot |
||||||
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
echo [删除快照...] |
||||||
set /p VMuser=请输入用户名(默认:%VMuser%): |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
set /p VMpass=请输入密码(默认:%VMpass%): |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
set /p VMipStart=请输入ip开始地址(默认:%VMipStart%): |
set /p VMSnapshot=请输入快照名称(默认:%VMSnapshot%): |
||||||
|
for /l %%a in (1,1,%VMcount%) do ( |
||||||
for /l %%a in (1,1,%VMcount%) do ( |
set name=!VMname!%%a |
||||||
set name=!VMname!%%a |
echo !name! |
||||||
set /a num=%VMipStart%+%%a-1 |
vmrun -T ws deleteSnapshot !VMpath!\!name!\!name!.vmx !VMSnapshot! |
||||||
set ip=!VMnetwork!.!num! |
) |
||||||
echo !name!:!ip! |
goto wait |
||||||
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 |
|
||||||
|
:setip |
||||||
|
echo [设置ip地址...] |
||||||
:exit |
set /p VMname=请输入虚拟机名称(默认:%VMname%): |
||||||
echo 退出... |
set /p VMcount=请输入虚拟机数量(默认:%VMcount%): |
||||||
ping /n 5 127.1>nul |
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 |
exit |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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 |
@ -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 |
@ -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 |
Loading…
Reference in new issue