Last active
August 22, 2024 10:52
-
-
Save giuliocalzolari/8ad1ab693e82f77646d6857cef732de6 to your computer and use it in GitHub Desktop.
AWS IMPORT VM Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################################################################################## | |
# AWS VM Import Instance Checker 1.2 # | |
# # | |
# The script has been implemented to simplify the VM Import process of the virtual # | |
# environment in AWS. # | |
# # | |
# The script checks that the requirements to import a VM in AWS are verified. # | |
# Please make a backup of the VM before to proceed. # | |
# # | |
# This software is provided "as is" without warranty of any kind. # | |
# # | |
# Please be aware that AWS does not accept any responsibility or liability # | |
# for the accuracy, content, completeness, or reliability of the script. # | |
# # | |
# CHANGELOG: # | |
# 1.1 # | |
# Added check for SLES wickedd dhcp. # | |
# Added check on the user running the script. # | |
# Added Centos 7.2 to Supported OS. # | |
# 1.2 # | |
# Fixed check on root filesystem using pivot_root # df -k / | grep '/$' # | |
# 1.3 # | |
# Added check for block device for currently booted kernel root device # | |
# Check for last fsck on root device if ext # | |
# 1.4 # | |
# Added Centos 6.7, 6.8, 6.9 and 7.3 # | |
# Added RHEL 6.7, 6.8, 6.9, 7.2, and 7.3 # | |
# Added Ubuntu 16.04 and 16.10 # | |
# Added sanity check for available filesystem space # | |
# 1.5 # | |
# Added fstab check for secondary volumes # | |
# 1.6 # | |
# Improved ethernet identification # | |
# Move advice to function # | |
########################################################################################## | |
set_defaults() { | |
day=`date +%d` | |
month=`date +%m` | |
year=`date +%Y` | |
hour=`date +%H` | |
minute=`date +%M` | |
OS_RELEASE=`cat /etc/*release|grep PRETTY|awk -F '"' '{ print $2 }'|awk '{ print $1 }'` | |
if [ $TRACE -eq 0 ]; then | |
LOGFILE="/dev/null" | |
else | |
LOGFILE="vm-check-script-$day-$month-$year.$hour.$minute.trace.log" | |
fi | |
} | |
splash_screen() { | |
clear | |
echo " ___ ______ __ ____ __ ___ _ " | |
echo " / \ \ / / ___| \ \ / / \/ | |_ _|_ __ ___ _ __ ___ _ __| |_ " | |
echo " / _ \ \ /\ / /\___ \ \ \ / /| |\/| | | || _ _ \| _ \ / _ \| '__| __|" | |
echo " / ___ \ V V / ___) | \ V / | | | | | || | | | | | |_) | (_) | | | |_ " | |
echo "/_/ \_\_/\_/ |____/ \_/ |_| |_| |___|_| |_| |_| __/ \___/|_| \__|" | |
echo " |_| " | |
echo " ___ _ _ _ " | |
echo "|_ _|_ __ ___| |_ __ _ _ __ ___ ___ ___| |__ ___ ___| | _____ _ __ " | |
echo " | || '_ \/ __| __/ _ | _ \ / __/ _ \ / __| _ \ / _ \/ __| |/ / _ \ __|" | |
echo " | || | | \__ \ || (_| | | | | (_| __/ | (__| | | | __/ (__| < __/ | " | |
echo "|___|_| |_|___/\__\__,_|_| |_|\___\___| \___|_| |_|\___|\___|_|\_\___|_| " | |
echo " " | |
echo " " | |
} | |
check_running_user() { | |
USER_RUNNING=`whoami` | |
if [[ $USER_RUNNING != "root" ]] ; then | |
echo -e "[\033[31mKO\e[0m] Please run the script as root user or using sudo!" | |
exit 1 | |
fi | |
} | |
check_os() { | |
ORACLE_OS_RELEASE=/etc/oracle-release | |
SUSE_OS_RELEASE=/etc/SuSE-release | |
UBUNTU_OS_RELEASE=/etc/lsb-release | |
grep "Ubuntu" /etc/lsb-release >> /dev/null 2>&1 | |
IS_UBUNTU=$? | |
DEBIAN_OS_RELEASE=/etc/debian_version | |
CENTOS_OS_RELEASE=/etc/centos-release | |
FEDORA_OS_RELEASE=/etc/fedora-release | |
REDHAT_OS_RELEASE=/etc/redhat-release | |
grep "Red Hat" /etc/redhat-release >> /dev/null 2>&1 | |
IS_REDHAT=$? | |
if [[ -f $ORACLE_OS_RELEASE ]] ; then | |
ORACLE_REL=`cat /etc/oracle-release|awk '{ print $5 }'` | |
if [[ $ORACLE_REL == 6.1 ]] || [[ $ORACLE_REL == 6.2 ]] || [[ $ORACLE_REL == 6.3 ]] || [[ $ORACLE_REL == 6.4 ]] || [[ $ORACLE_REL == 6.5 ]] || [[ $ORACLE_REL == 6.6 ]] || [[ $ORACLE_REL == 7.0 ]] || [[ $ORACLE_REL == 7.1 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The operating system is Oracle Enterprise Linux release $ORACLE_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
elif [[ -f $SUSE_OS_RELEASE ]] ; then | |
SUSE_VERSION=`cat /etc/SuSE-release |grep VERSION|awk '{ print $3 }'` | |
SUSE_PATCH=`cat /etc/SuSE-release |grep PATCH|awk '{ print $3 }'` | |
SUSE_REL=$SUSE_VERSION"."$SUSE_PATCH | |
if [[ $SUSE_VERSION == 11 ]] || [[ $SUSE_VERSION == 12 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The operating system is SUSE Linux Enterprise Server $SUSE_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
elif [[ -f $UBUNTU_OS_RELEASE ]] && [[ $IS_UBUNTU -eq 0 ]] ; then | |
UBUNTU_REL=`cat /etc/lsb-release |grep DISTRIB_RELEASE|awk -F "=" '{ print $2 }'` | |
if [[ $UBUNTU_REL == 12.04 ]] || [[ $UBUNTU_REL == 12.10 ]] || [[ $UBUNTU_REL == 13.04 ]] || [[ $UBUNTU_REL == 13.10 ]] || [[ $UBUNTU_REL == 14.04 ]] || [[ $UBUNTU_REL == 14.10 ]] || [[ $UBUNTU_REL == 15.04 ]] || [[ $UBUNTU_REL == 16.04 ]] || [[ $UBUNTU_REL == 16.10 ]]; then | |
echo -e "[\033[32mOK\e[0m] The operating system is Ubuntu $UBUNTU_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
elif [[ -f $DEBIAN_OS_RELEASE ]] ; then | |
DEBIAN_REL=`cat /etc/debian_version` | |
if [[ $DEBIAN_REL == 6.0.0 ]] || [[ $DEBIAN_REL == 6.0.1 ]] || [[ $DEBIAN_REL == 6.0.2 ]] || [[ $DEBIAN_REL == 6.0.3 ]] || [[ $DEBIAN_REL == 6.0.4 ]] || [[ $DEBIAN_REL == 6.0.5 ]] || [[ $DEBIAN_REL == 6.0.6 ]] || [[ $DEBIAN_REL == 6.0.7 ]] || [[ $DEBIAN_REL == 6.0.8 ]] || [[ $DEBIAN_REL == 7.0 ]] || [[ $DEBIAN_REL == 7.1 ]] || [[ $DEBIAN_REL == 7.2 ]] || [[ $DEBIAN_REL == 7.3 ]] || [[ $DEBIAN_REL == 7.4 ]] || [[ $DEBIAN_REL == 7.5 ]] || [[ $DEBIAN_REL == 7.6 ]] || [[ $DEBIAN_REL == 7.7 ]] || [[ $DEBIAN_REL == 7.8 ]] || [[ $DEBIAN_REL == 8.0 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The operating system is Debian $DEBIAN_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
elif [[ -f $CENTOS_OS_RELEASE ]] ; then | |
CENTOS_REL=`cat /etc/centos-release|grep CentOS|sed 's/[^0-9.]//g'|awk -F "." '{ print $1"."$2 }'` | |
if [[ $CENTOS_REL == 5.1 ]] || [[ $CENTOS_REL == 5.2 ]] || [[ $CENTOS_REL == 5.3 ]] || [[ $CENTOS_REL == 5.4 ]] || [[ $CENTOS_REL == 5.5 ]] || [[ $CENTOS_REL == 5.6 ]] || [[ $CENTOS_REL == 5.7 ]] || [[ $CENTOS_REL == 5.8 ]] || [[ $CENTOS_REL == 5.9 ]] || [[ $CENTOS_REL == 5.10 ]] || [[ $CENTOS_REL == 5.11 ]] || [[ $CENTOS_REL == 6.1 ]] || [[ $CENTOS_REL == 6.2 ]] || [[ $CENTOS_REL == 6.3 ]] || [[ $CENTOS_REL == 6.4 ]] || [[ $CENTOS_REL == 6.5 ]] || [[ $CENTOS_REL == 6.6 ]] || [[ $CENTOS_REL == 6.7 ]] || [[ $CENTOS_REL == 6.8 ]] || [[ $CENTOS_REL == 6.9 ]] || [[ $CENTOS_REL == 7.0 ]] || [[ $CENTOS_REL == 7.1 ]] || [[ $CENTOS_REL == 7.2 ]] || [[ $CENTOS_REL == 7.3 ]]; then | |
echo -e "[\033[32mOK\e[0m] The operating system is CentOS $CENTOS_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
elif [[ -f $FEDORA_OS_RELEASE ]] ; then | |
FEDORA_REL=`cat /etc/fedora-release|grep Fedora|sed 's/[^0-9]//g'` | |
if [[ $FEDORA_REL == 19 ]] || [[ $FEDORA_REL == 20 ]] || [[ $FEDORA_REL == 21 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The operating system is Fedora $FEDORA_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
elif [[ -f $REDHAT_OS_RELEASE ]] && [[ $IS_REDHAT -eq 0 ]] ; then | |
REDHAT_REL=`cat /etc/redhat-release|grep Red |sed 's/[^0-9.]//g'|awk -F "." '{ print $1"."$2 }'` | |
if [[ $REDHAT_REL == 5.1 ]] || [[ $REDHAT_REL == 5.2 ]] || [[ $REDHAT_REL == 5.3 ]] || [[ $REDHAT_REL == 5.4 ]] || [[ $REDHAT_REL == 5.5 ]] || [[ $REDHAT_REL == 5.6 ]] || [[ $REDHAT_REL == 5.7 ]] || [[ $REDHAT_REL == 5.8 ]] || [[ $REDHAT_REL == 5.9 ]] || [[ $REDHAT_REL == 5.10 ]] || [[ $REDHAT_REL == 5.11 ]] || [[ $REDHAT_REL == 6.1 ]] || [[ $REDHAT_REL == 6.2 ]] || [[ $REDHAT_REL == 6.3 ]] || [[ $REDHAT_REL == 6.4 ]] || [[ $REDHAT_REL == 6.5 ]] || [[ $REDHAT_REL == 6.6 ]] || [[ $REDHAT_REL == 6.7 ]] || [[ $REDHAT_REL == 6.8 ]] || [[ $REDHAT_REL == 6.9 ]] || [[ $REDHAT_REL == 7.0 ]] || [[ $REDHAT_REL == 7.1 ]] || [[ $REDHAT_REL == 7.2 ]] || [[ $REDHAT_REL == 7.3 ]]; then | |
echo -e "[\033[32mOK\e[0m] The operating system is Red Hat $REDHAT_REL..." | |
else echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
else | |
echo -e "[\033[31mKO\e[0m] The operating system is not supported!!!" | |
fi | |
} | |
vm_checks() { | |
uname -a|grep x86_64 > /dev/null 2>&1 | |
OS_X86_64=$? | |
if [[ $OS_X86_64 -eq 0 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The kernel of the OS is x86_64!" | |
echo -e "[\033[33mWARNING\e[0m]: Some restrictions are applied with some specific kernel releases." | |
else echo -e "[\033[31mKO\e[0m] The Operating System is not x86_64!" | |
fi | |
ROOT_DISK_SIZE=`fdisk -l 2>/dev/null|grep -m1 Disk|awk '{print $5}'` | |
if [[ $ROOT_DISK_SIZE -lt 1099511627776 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The root volume disk size is less than 1TB!" | |
else echo -e "[\033[31mKO\e[0m] The root volume disk size is more than 1TB!" | |
fi | |
ROOT_DISK=`fdisk -l 2>/dev/null|grep -m1 Disk|awk '{print $2}'|tr -d ':'` | |
fdisk -l $ROOT_DISK 2>/dev/null |grep gpt > /dev/null 2>&1 | |
IS_GPT=$? | |
if [[ $IS_GPT -eq 0 ]] ; then | |
echo -e "[\033[31mKO\e[0m] The GUID Partition Table (GPT) disk import is not supported!!!" | |
else echo -e "[\033[32mOK\e[0m] The Partition table appears to be MBR." | |
fi | |
ROOT_FS_SPACE_AVAIL=`df -k / |grep "/$"|awk '{ print $4}'` | |
if [[ $ROOT_FS_SPACE_AVAIL == *"%" ]]; then | |
ROOT_FS_SPACE_AVAIL=`df -k / |grep "/$"|awk '{ print $3}'` | |
fi | |
BOOT_FS_SPACE_AVAIL=`df -k /boot|grep "/$" |awk '{ print $4}'` | |
if [[ $BOOT_FS_SPACE_AVAIL == *"%" ]]; then | |
BOOT_FS_SPACE_AVAIL=`df -k /boot |grep "/$"|awk '{ print $3}'` | |
fi | |
ETC_FS_SPACE_AVAIL=`df -k /etc|grep "/$" |awk '{ print $4}'` | |
if [[ $ETC_FS_SPACE_AVAIL == *"%" ]]; then | |
ETC_FS_SPACE_AVAIL=`df -k /etc |grep "/$"|awk '{ print $3}'` | |
fi | |
TMP_FS_SPACE_AVAIL=`df -k /tmp|grep "/$" |awk '{ print $4}'` | |
if [[ $TMP_FS_SPACE_AVAIL == *"%" ]]; then | |
TMP_FS_SPACE_AVAIL=`df -k /tmp |grep "/$"|awk '{ print $3}'` | |
fi | |
VAR_FS_SPACE_AVAIL=`df -k /var|grep "/$" |awk '{ print $4}'` | |
if [[ $VAR_FS_SPACE_AVAIL == *"%" ]]; then | |
VAR_FS_SPACE_AVAIL=`df -k /var |grep "/$"|awk '{ print $3}'` | |
fi | |
USR_FS_SPACE_AVAIL=`df -k /usr|grep "/$" |awk '{ print $4}'` | |
if [[ $USR_FS_SPACE_AVAIL == *"%" ]]; then | |
USR_FS_SPACE_AVAIL=`df -k /usr |grep "/$"|awk '{ print $3}'` | |
fi | |
if [[ $ROOT_FS_SPACE_AVAIL -gt 256000 ]] && [[ $BOOT_FS_SPACE_AVAIL -gt 256000 ]] && [[ $ETC_FS_SPACE_AVAIL -gt 256000 ]] && [[ $TMP_FS_SPACE_AVAIL -gt 256000 ]] && [[ $VAR_FS_SPACE_AVAIL -gt 256000 ]] && [[ $USR_FS_SPACE_AVAIL -gt 256000 ]] ; then | |
echo -e "[\033[32mOK\e[0m] There is enough space to install EC2 drivers!" | |
else echo -e "[\033[31mKO\e[0m] It is needed at least 250MB of space available to install the EC2 drivers!" | |
fi | |
VMWARE_TOOLS_INST=`lsmod|grep vmw` | |
IS_VMWARE_TOOLS_INST=$? | |
if [[ $IS_VMWARE_TOOLS_INST -eq 0 ]] ; then | |
echo -e "[\033[31mKO\e[0m] VMware tools are installed on the system!" | |
else echo -e "[\033[32mOK\e[0m] VMware tools not installed." | |
fi | |
ACTIVE_ETH=`ifconfig -a |grep eth[0-9]|wc -l` | |
ACTIVE_EN=`ifconfig -a|grep en[a-z]|wc -l` | |
if [[ $ACTIVE_ETH == 1 ]] ; then | |
echo -e "[\033[32mOK\e[0m] Only one active eth adapter found!" | |
elif [[ $ACTIVE_EN == 1 ]] ; then | |
echo -e "[\033[32mOK\e[0m] Only one active en adapter found!" | |
else echo -e "[\033[31mKO\e[0m] Only one active adapter should be active to convert the VM!" | |
fi | |
#check for dhclient pid with pidof, if there return code is 0, therefore dhclient is running | |
DHCLIENT_RC=`pidof dhclient >> /dev/null ; echo $?` | |
#SLES using wickedd instead of dhclient | |
WICKEDD_RC=`pidof wickedd-dhcp4 >> /dev/null ; echo $?` | |
#if grep match "0.0.0.0:68 " and the return code is 0 means that dhclient is listening | |
DHCLIENT_NETSTAT=`netstat -na|grep -i '0.0.0.0:68 ' >> /dev/null; echo $?` | |
if [[ $DHCLIENT_RC == 0 || $WICKEDD_RC == 0 ]] && [[ $DHCLIENT_NETSTAT == 0 ]] ; then | |
echo -e "[\033[32mOK\e[0m] DHCP client is running" | |
else echo -e "[\033[31mKO\e[0m] dhcp must be enabled to import the vm correctly!" # enabled | |
fi | |
SSH_RUNNING=`ps aux|grep sshd|grep -v grep` | |
IS_SSH_RUNNING=$? | |
if [[ $IS_SSH_RUNNING -eq 0 ]] ; then | |
echo -e "[\033[32mOK\e[0m] The SSH daemon is up and running!" | |
else echo -e "[\033[31mKO\e[0m] Check the SSH is up and running!" | |
fi | |
IPTABLES_DROP=`iptables -L |grep -i drop` | |
IS_IPTABLES_DROP=$? | |
if [[ $IS_IPTABLES_DROP -eq 0 ]] ; then | |
echo -e "[\033[31mKO\e[0m] Found a drop in the iptables rules!" | |
echo -e "[\033[33mWARNING\e[0m]:Check iptables doesn't block SSH before you start the conversion!" | |
else echo -e "[\033[32mOK\e[0m] Not found any drop in the iptables!" | |
fi | |
CDROM_PRESENT=`dmesg | grep cdrom` | |
IS_CDROM_PRESENT=$? | |
CDRW_PRESENT=`dmesg | grep cd/rw` | |
IS_CDRW_PRESENT=$? | |
DVD_PRESENT=`dmesg | grep dvd` | |
IS_DVD_PRESENT=$? | |
WRITER_PRESENT=`dmesg | grep writer` | |
IS_WRITER_PRESENT=$? | |
if [[ $IS_CDROM_PRESENT -eq 0 ]] || [[ $IS_CDRW_PRESENT -eq 0 ]] || [[ $IS_DVD_PRESENT -eq 0 ]] || [[ $IS_WRITER_PRESENT -eq 0 ]] ; then | |
echo -e "[\033[31mKO\e[0m] CD-ROM or DVD device detected! Please remove it!" | |
else echo -e "[\033[32mOK\e[0m] No CD-ROM or DVD device detected." | |
fi | |
} | |
check_grub() { | |
GRUB_ROOT_DEVICE=$(sudo cat /proc/cmdline | awk 'match($0, /root=.*/) { print substr($0, RSTART, RLENGTH) }' | awk '{print $1}') | |
if [[ $(echo ${GRUB_ROOT_DEVICE} | awk -F'=' '{print NF}') == 3 ]]; then | |
DEV_DEF=$(echo ${GRUB_ROOT_DEVICE} | awk -F'=' {'print $3'}) | |
echo -e "[\033[32mOK\e[0m] The currently active root volume is defined by LABEL or UUID: ${DEV_DEF} which is a good practice for imports." | |
elif [[ $(echo ${GRUB_ROOT_DEVICE} | awk -F'=' '{print NF}') == 2 ]]; then | |
DEV_DEF=$(echo ${GRUB_ROOT_DEVICE} | awk -F'=' {'print $2'}) | |
echo -e "[\033[33mWARNING\e[0m]: The current kernel boot command is referencing the root volume using block device IDs. In some cases, this can cause issues with the import process. We recommend using the UUID instead where possible." | |
fi | |
} | |
check_fs() { | |
ROOT_FS_TYPE=$(df -T / | tail -1 | awk '{print $2}') | |
if [[ ${ROOT_FS_TYPE} == "ext"* ]]; then | |
FS_CHECK_DATE=$(tune2fs -l $(mount | grep 'on / ' | awk '{print $1}') | grep 'Last checked' | awk 'match($0, /Sat.*|Sun.*|Mon.*|Tue.*|Wed.*|Thu.*|Fri.*/) { print substr($0, RSTART, RLENGTH) }') | |
FS_SHORT_DATE=$(date -d "${FS_CHECK_DATE}" +%s) | |
CURR_SHORT_DATE=$(date +%s) | |
DATEDIFF=$(echo \(${CURR_SHORT_DATE}-${FS_SHORT_DATE}\)/60/60/24 | bc) | |
if [[ "${DATEDIFF}" -gt 15 ]]; then | |
echo -e "[\033[33mWARNING\e[0m] Your EXT root filesystem has not been checked in more than 2 weeks - please run fsck before importing your VM." | |
fi | |
else | |
echo -e "[\033[32mOK\e[0m] Please ensure you run a filesystem check against the root volume before importing your VM." | |
fi | |
} | |
check_fstab() { | |
root_dev=$(mount | grep 'on / ' | awk '{print $1}') | |
root_uuid=$(blkid | grep ${root_dev} | grep -ow 'UUID=\S*' | sed s/\"//g) | |
root_label=$(blkid | grep ${root_dev} | grep -ow 'LABEL=\S*' | sed s/\"//g) | |
for block_dev in $(cat /etc/fstab | grep '^/dev' | awk '{print $1}' | sed s/\"//g) | |
do | |
if [[ "${block_dev}" == "${root_dev}" ]]; then | |
true | |
else | |
secondary_dev_array+=" ${block_dev}" | |
fi | |
done | |
for block_label in $(cat /etc/fstab | grep '^LABEL' | awk '{print $1}' | sed s/\"//g) | |
do | |
if [[ "${block_label}" == "${root_label}" ]]; then | |
true | |
else | |
secondary_label_array+=" ${block_label}" | |
fi | |
done | |
for block_uuid in $(cat /etc/fstab | grep '^UUID' | awk '{print $1}' | sed s/\"//g) | |
do | |
if [[ "${block_uuid}" == "${root_uuid}" ]]; then | |
true | |
else | |
secondary_uuid_array+=" ${block_uuid}" | |
fi | |
done | |
if [[ -n ${secondary_dev_array} ]]; then | |
for dev in ${secondary_dev_array[@]} | |
do | |
echo -e "[\033[31mKO\e[0m]: Secondary volume configured in /etc/fstab for this VM: ${dev} - please ensure they are included | |
in the import definition or comment them out of the fstab when preparing the VM for import. " | |
done | |
fi | |
if [[ -n ${secondary_label_array} ]]; then | |
for dev in ${secondary_label_array[@]} | |
do | |
echo -e "[\033[33mWARNING\e[0m]: Secondary volume configured in /etc/fstab for this VM: ${dev} - please ensure they are included | |
in the import definition or comment them out of the fstab when preparing the VM for import. " | |
done | |
fi | |
if [[ -n ${secondary_uuid_array} ]]; then | |
for dev in ${secondary_uuid_array[@]} | |
do | |
echo -e "[\033[33mWARNING\e[0m]: Secondary volume configured in /etc/fstab for this VM: ${dev} - please ensure they are included | |
in the import definition or comment them out of the fstab when preparing the VM for import. " | |
done | |
fi | |
if [[ -z ${secondary_label_array} && -z ${secondary_label_array} && -z ${secondary_uuid_array} ]]; then | |
echo -e "[\033[32mOK\e[0m]: It seems only the root volume is defined in /etc/fstab. " | |
fi | |
} | |
print_advice() { | |
echo " " | |
echo "For further informations about the prerequisites of the VM Import check:" | |
echo "http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/VMImportPrerequisites.html" | |
echo " " | |
} | |
set_defaults | |
splash_screen | |
check_running_user | |
check_os | |
vm_checks | |
check_grub | |
check_fs | |
check_fstab | |
print_advice | |
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Script for checking requirement | |
# https://kb.cloudberry.online/amazon-ec2/ensuring-vm-compatibility-with-ec2 | |
# VM Import Script | |
# Author: Injae Kwak (injakwak@amazon.com) | |
# Maintained by: Injae Kwak (injakwak@amazon.com), Andrea Soria (andsoria@amazon.com) | |
$script:loglevel = "normal" | |
$script:PASSED = "PASSED" | |
$script:FAILED = "FAILED" | |
$script:SuccessLabel = "[SUCCESS]" | |
$script:FailureLabel = "[ FAIL ]" | |
$script:logResults = @() | |
# Check if the script is running as Administrator, otherwise Elevate it | |
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
Write-Warning "Script is not running as Administrator, Elevating Script" | |
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; | |
$newProcess.Arguments = $myInvocation.MyCommand.Definition; | |
$newProcess.Verb = 'runas' | |
[System.Diagnostics.Process]::Start($newProcess) | out-null; | |
exit | |
#Break | |
} | |
function Write-Log | |
{ | |
Param ([string]$logstring) | |
try | |
{ | |
if ($script:loglevel -eq "verbose") | |
{ | |
$currentTime = Get-Date | |
$logstring = "$currentTime $logstring" | |
} | |
Add-content $Logfile -Value "${logstring}" | |
} | |
catch | |
{ | |
# if the logs themselves give an error in logging. Simply, writing to error stream. | |
Write-Error $_.Exception.Message | |
} | |
} | |
function New-LogResult() | |
{ | |
param ($Result, | |
$Test, | |
$ResultValue, | |
$Details) | |
$testResult = new-object PSObject | |
$testResult | add-member -MemberType NoteProperty -Name Result -Value $Result | |
$testResult | add-member -MemberType NoteProperty -Name Test -Value $Test | |
$testResult | add-member -MemberType NoteProperty -Name "Result Value" -Value $ResultValue | |
$testResult | add-member -MemberType NoteProperty -Name Details -Value $Details | |
return $testResult | |
} | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Test functions block | |
function checkPowershellVersion | |
{ | |
$log1 = $PSVersionTable.PSVersion.Major | |
if ($PSVersionTable.psversion.major -ge 2) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) "v $log1" "" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) "v $log1" $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkAdminAccountEnabled | |
{ | |
$script:computerName = get-wmiobject -class win32_computersystem | select-object -expandproperty name | |
$script:localAdminAccount = Get-WmiObject -class win32_useraccount -namespace "root\cimv2" -filter "Domain='$computerName' AND SID like 'S-1-5-%-500'" | |
if ($localAdminAccount.disabled -eq $False) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkAdminAccountLocked | |
{ | |
if ($localAdminAccount.lockout -eq $False) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkAdminAccountPassword | |
{ | |
$log4 = $localAdminAccount.PasswordRequired | |
if ($localAdminAccount.PasswordRequired -eq $False) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $log4 $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $log4 "" | |
return $script:PASSED | |
} | |
} | |
function checkSingleNetworkInterface | |
{ | |
$script:networkAdapters = Get-WmiObject -Class win32_networkadapterconfiguration -filter 'ipenabled = "true"' | |
$log5 = $networkAdapters | Measure-Object | Select-Object -ExpandProperty count | |
Write-Log "Number of active network adapters is - $log5" | |
if (($networkAdapters | Measure-Object | Select-Object -ExpandProperty count) -eq "1") | |
{ | |
return $script:PASSED | |
} | |
else | |
{ | |
return $script:FAILED | |
} | |
} | |
function checkDHCPEnabledInterface | |
{ | |
$script:networkAdapters = Get-WmiObject -Class win32_networkadapterconfiguration -filter 'ipenabled = "true"' | |
$log6 = $networkAdapters.DHCPEnabled | |
if ($networkAdapters.DHCPEnabled -eq $True) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $log6 "" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $log6 $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkIPv6Interface | |
{ | |
$script:ipaddresses = $networkAdapters | Select-Object -ExpandProperty IPAddress | |
foreach ($ip in $ipaddresses) | |
{ | |
if ($ip.contains(':')) | |
{ | |
$ipv6 = "True" | |
} | |
else | |
{ | |
$ipv6 = "False" | |
} | |
} | |
$log7 = $ipv6 | |
if ($ipv6 -eq "True") | |
{ | |
write-log "Network adapter has IPv6? - $log7" | |
return $script:FAILED | |
} | |
else | |
{ | |
Write-Log "${script:SuccessLabel} Network adapter has IPv6? - $log7 " | |
return $script:PASSED | |
} | |
} | |
function checkDiskSpace | |
{ | |
$script:disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object FreeSpace | |
$log8 = [math]::Round($disk.freespace / 1GB,2) | |
if (($disk.FreeSpace / 1GB) -lt 6) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) "$log8 GB" $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) "$log8 GB" "" | |
return $script:PASSED | |
} | |
} | |
function checkForDrives | |
{ | |
$script:drives = Get-WmiObject -class win32_logicaldisk | Select-Object DeviceID, DriveType | |
foreach ($drive in $drives) | |
{ | |
if ($drive.DriveType -eq 2) | |
{ | |
$fail = $true | |
} | |
elseif ($drive.DriveType -eq 4) | |
{ | |
$fail = $true | |
} | |
elseif ($drive.DriveType -eq 5) | |
{ | |
$fail = $true | |
} | |
else | |
{ | |
#do nothing | |
} | |
} | |
if ($fail) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "" | |
return $script:PASSED | |
} | |
} | |
function checkOSRequirements | |
{ | |
# Reference for version https://en.wikipedia.org/wiki/Ver_%28command%29 | |
# Reference for edition numbers https://techontip.wordpress.com/tag/operatingsystemsku/ | |
$script:sysDetails = New-Object -TypeName PSObject | |
$script:os = get-wmiobject -class win32_operatingsystem | |
$script:product = $os.producttype | |
$script:version = $os.version | |
$script:edition = $os.OperatingSystemSKU | |
$script:language = $os.OSLanguage | |
$script:architecture = $os.OSArchitecture | |
if ($os.OSArchitecture) | |
{ $script:architecture = $os.OSArchitecture } | |
else | |
{ | |
#If OSArchitecture property is not present, fall back to PROCESSOR_ARCHITECTURE environment variable | |
switch -wildcard ($env:PROCESSOR_ARCHITECTURE) | |
{ | |
"*86" { $script:architecture = "32-bit" } | |
"*64" { $script:architecture = "64-bit" } | |
} | |
} | |
#checking if desktop or server | |
switch ($product) | |
{ | |
1 { | |
$type = "desktop" | |
$script:typeCaption = "Client OS" | |
} | |
2 { | |
$type = "serverDC" | |
$script:typeCaption = "Domain Controller" | |
} | |
3 { | |
$type = "serverNoDC" | |
$script:typeCaption = "Server OS" | |
} | |
default { $type = "ERROR!" } | |
} | |
switch ($type) | |
{ | |
desktop{ desktopCheck } | |
serverDC{ serverCheck } | |
serverNoDC{ serverCheck } | |
ERROR!{ return $script:FAILED } | |
default { return $script:FAILED } | |
} | |
} | |
function desktopCheck | |
{ | |
loadDesktopDictionaryList | |
#identify OS version | |
switch ($version) | |
{ | |
{ $supportedDesktopOS[$version] } { $script:clientOS = $supportedDesktopOS[$version] } | |
default { $script:clientOS = "OtherOS" } | |
} | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "OS" -Value $clientOS | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Product" -Value $script:typeCaption | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Architecture" -Value $architecture | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Caption" -Value $os.Caption | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Service Pack" -Value $os.ServicePackMajorVersion | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Language Code" -Value $language | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Edition" -Value $edition | |
#check respective OS requirements | |
switch ($clientOS) | |
{ | |
Win7 | |
{ | |
$script:PVcheck = "dism" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Win8 | |
{ | |
$script:PVcheck = "dism" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Win8.1 | |
{ | |
$script:PVcheck = "gwd" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Win10 | |
{ | |
$script:PVcheck = "gwd" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
OtherOS | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
default | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
} | |
function serverCheck | |
{ | |
checkOSRequirements2 | |
} | |
function checkOSRequirements2 | |
{ | |
loadServerDictionaryList | |
switch ($version) | |
{ | |
{ $supportedServerOS[$version] } { $script:clientOS = $supportedServerOS[$version] } | |
default { $script:clientOS = "OtherOS" } | |
} | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "OS" -Value $clientOS | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Product" -Value $script:typeCaption | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Architecture" -Value $architecture | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Caption" -Value $os.Caption | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Service Pack" -Value $os.ServicePackMajorVersion | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Language Code" -Value $language | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Edition" -Value $edition | |
switch ($clientOS) | |
{ | |
Server2003 | |
{ | |
$script:PVcheck = "driverquery" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2008SP1 | |
{ | |
#setting $hotfix for setting up test 19 (hotfix) | |
$script:hotfix = "1" | |
$script:PVcheck = "driverquery" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2008SP2 | |
{ | |
$script:hotfix = "1" | |
$script:PVcheck = "dism" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2008R2 | |
{ | |
$script:hotfix = "1" | |
$script:PVcheck = "dism" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2008R2SP1 | |
{ | |
$script:hotfix = "2" | |
$script:PVcheck = "dism" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2012 | |
{ | |
$script:PVcheck = "dism" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2012R2 | |
{ | |
$script:PVcheck = "gwd" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
Server2016 | |
{ | |
$script:PVcheck = "gwd" | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
OtherOS | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
default | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
} | |
function checkAdditionalOSRequirements | |
{ | |
#check respective OS requirements | |
switch ($clientOS) | |
{ | |
Win7 | |
{ | |
if ($supportedEditionWin7[$edition.tostring()] -eq "Yes") | |
{ | |
#doing below for setting up test 19 (hotfix) | |
$script:hotfix = "1" | |
if ($os.ServicePackMajorVersion -eq 1) | |
{ | |
$script:hotfix = "2" | |
} | |
else | |
{ | |
} | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Win8 | |
{ | |
if ($supportedEditionWin8and81[$edition.tostring()] -eq "Yes") | |
{ | |
if ($language -eq "1033") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Win8.1 | |
{ | |
if ($supportedEditionWin8and81[$edition.tostring()] -eq "Yes") | |
{ | |
if ($language -eq "1033") | |
{ | |
if ($architecture -eq "64-bit") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Win10 | |
{ | |
if ($supportedEditionWin10[$edition.tostring()] -eq "Yes") | |
{ | |
if ($language -eq "1033") | |
{ | |
if ($architecture -eq "64-bit") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2003 #doing some manual checking with caption as server2003 doesnt support operatingsystemsku property | |
{ | |
if ([string]$os.caption.contains("Standard") -or [string]$os.caption.contains("Datacenter") -or [string]$os.caption.contains("Enterprise")) | |
{ | |
if ($os.otherTypeDescription -eq "R2") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
if ($os.servicepackmajorversion -gt 1) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2008SP1 | |
{ | |
if ($supportedEditionServer2008[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2008SP2 | |
{ | |
if ($supportedEditionServer2008[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2008R2 | |
{ | |
if ($supportedEditionServer2008[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2008R2SP1 | |
{ | |
if ($supportedEditionServer2008[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2012 | |
{ | |
if ($supportedEditionServer2012[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2012R2 | |
{ | |
if ($supportedEditionServer2012[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
Server2016 | |
{ | |
if ($supportedEditionServer2016[$edition.tostring()] -eq "Yes") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
default | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
} | |
function checkNETFramework | |
{ | |
$script:netFrameworkList = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | | |
Get-ItemProperty -name Version, Release -ErrorAction 0 | | |
Where-Object { $_.PSChildName -match '^(?!S)\p{L}' } | | |
Select-Object @{ name = "Name"; expression = { $_.PSChildName } }, Version, Release | |
$script:netfwList = $netFrameworkList | Out-String | |
# Check Framework version required according to the OS for PV Drivers installation | |
# Citrix PV Drivers require version 3.51 | |
# AWS PV Drivers require version 4.5 | |
# Version check based on https://blogs.msdn.microsoft.com/rodneyviana/2014/12/23/identifying-the-net-version-you-are-running-2-0-4-5-4-5-1-or-4-5-2/ | |
switch ($clientOS){ | |
Server2003{[version]$requiredVersion = "3.5.30729"} | |
Server2008SP1{[version]$requiredVersion = "3.5.30729"} | |
Server2008SP2{[version]$requiredVersion = "3.5.30729"} | |
default | |
{ | |
[version]$requiredVersion = "4.0.30319.17001" | |
$FailureTexts[$i] = "Please Install .NET Framework 4.5 or Later for VMImport" | |
} | |
} | |
$netFrameworkStatus = "False" | |
foreach ($item in $netFrameworkList) | |
{ | |
if ($netFrameworkStatus -eq "False") | |
{ | |
if ([version]$item.version -gt [version]$requiredVersion) | |
{ | |
$netFrameworkStatus = "True" | |
} | |
else | |
{ | |
$netFrameworkStatus = "False" | |
} | |
} | |
} | |
if ($netFrameworkStatus -eq "True") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkFirewall | |
{ | |
$script:partofDomain = (Get-WmiObject -Class win32_computersystem).partofdomain | |
$location = "Registry::HKLM\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy" | |
$domainFirewall = Get-ItemProperty -path $location\DomainProfile -ErrorAction SilentlyContinue | |
$publicFirewall = Get-ItemProperty -path $location\PublicProfile -ErrorAction SilentlyContinue | |
Add-Member -InputObject $script:sysDetails -MemberType NoteProperty -Name "Domain Joined" -Value $partofDomain | |
if ($partofDomain -eq $true) | |
{ | |
if ($domainFirewall.enablefirewall -eq "1") | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} "Domain Firewall Profile" "ON" "Please disable Domain Firewall Profile" | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} "Domain Firewall Profile" "OFF" "" | |
return $script:PASSED | |
} | |
} | |
#if in workgroup, checking public profile | |
else | |
{ | |
if ($publicFirewall.enablefirewall -eq "1") | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} "Public Firewall Profile" "ON" "Please disable Public Firewall Profile" | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} "Public Firewall Profile" "OFF" "" | |
return $script:PASSED | |
} | |
} | |
} | |
function checkVMWareTools | |
{ | |
$path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' | |
$path2 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | |
$installedApps = Get-ItemProperty $path | Select-Object DisplayName | |
$installedApps2 = Get-ItemProperty $path2 | Select-Object DisplayName | |
foreach ($app in $installedApps) | |
{ | |
if ($app.displayname -eq "VMWare Tools") | |
{ | |
$VMWareToolsInstalled = "True" | |
} | |
else | |
{ | |
$VMWareToolsInstalled = "False" | |
} | |
} | |
foreach ($app in $installedApps2) | |
{ | |
if ($app.displayname -eq "VMWare Tools") | |
{ | |
$VMWareToolsInstalled = "True" | |
} | |
else | |
{ | |
$VMWareToolsInstalled = "False" | |
} | |
} | |
if ($VMWareToolsInstalled -eq "True") | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
} | |
function checkDriveLargerThan1TB | |
{ | |
$drive = Get-WmiObject -Class win32_logicaldisk | |
foreach ($d in $drive) | |
{ | |
if (($d.size / 1TB) -gt 1) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
} | |
} | |
function checkForGPTPartitions | |
{ | |
$script:partitions = Get-WmiObject -Class win32_diskpartition | |
foreach ($partition in $partitions) | |
{ | |
if ($partition.type.startswith("GPT")) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
} | |
} | |
function checkPendingUpdates | |
{ | |
$path2 = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' | |
$path3 = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' # doesnt work for 2003 | |
if (test-path $path2 -ErrorAction SilentlyContinue) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $false | |
return $script:FAILED | |
} | |
elseif (test-path $path3 -ErrorAction SilentlyContinue) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $true $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $false | |
return $script:PASSED | |
} | |
} | |
function checkAutoLogon | |
{ | |
$path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' | |
$result = Get-ItemProperty -path $path | |
if ($result.AutoAdminLogon -eq 1) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "" | |
return $script:PASSED | |
} | |
} | |
function checkHotFixesInstalled | |
{ | |
$OSVersion = [System.Environment]::OSVersion.Version | |
switch ($OSVersion) | |
{ | |
{ ($OSVersion.Major -eq 6) -and ($OSVersion.Minor -eq 0) } { | |
$KB2800213 = [System.Version]"6.0.6002.23" | |
$FailureTexts[$i] = "Install Hotfix 2800213 from Microsoft - http://support.microsoft.com/kb/2800213" | |
$files = @( | |
'System32\ntoskrnl.exe' | |
) | |
} | |
{ ($OSVersion.Major -eq 6) -and ($OSVersion.Minor -eq 1) } { | |
# https://gallery.technet.microsoft.com/scriptcenter/Add-FileVersion-Property-8586449e | |
# (Get-TypeData -TypeName System.IO.FileInfo).Members.ProductVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName) | |
# Does not work in Powershell 2 | |
if (!(Get-TypeData -TypeName System.IO.FileInfo).Members.FileVersion) | |
{ | |
Update-TypeData -TypeName System.IO.FileInfo -MemberType ScriptProperty -MemberName FileVersion -Value { | |
if ($this.VersionInfo.FileVersion) | |
{ | |
[System.Version] ("{0}.{1}.{2}.{3}" -f $this.VersionInfo.FileMajorPart, | |
$this.VersionInfo.FileMinorPart, | |
$this.VersionInfo.FileBuildPart, | |
$this.VersionInfo.FilePrivatePart) | |
} | |
} | |
} | |
if (!(Get-TypeData -TypeName System.IO.FileInfo).Members.ProductVersion) | |
{ | |
Update-TypeData -TypeName System.IO.FileInfo -MemberType ScriptProperty -MemberName ProductVersion -Value { | |
if ($this.VersionInfo.ProductVersion) | |
{ | |
[System.Version] ("{0}.{1}.{2}.{3}" -f $this.VersionInfo.ProductMajorPart, | |
$this.VersionInfo.ProductMinorPart, | |
$this.VersionInfo.ProductBuildPart, | |
$this.VersionInfo.ProductPrivatePart) | |
} | |
} | |
} | |
$KB2800213 = [System.Version]"6.1.7601.22551" | |
$FailureTexts[$i] = "Install Hotfix 2922223 from Microsoft - http://support.microsoft.com/kb/2922223" | |
$files = @( | |
'System32\apisetschema.dll', | |
'System32\drivers\appid.sys', | |
'System32\appidapi.dll', | |
'System32\appidcertstorecheck.exe', | |
'System32\appidpolicyconverter.exe', | |
'System32\appidsvc.dll', | |
'System32\csrsrv.dll', | |
'SysWOW64\ntkrnlpa.exe', | |
'System32\ntoskrnl.exe', | |
'System32\smss.exe' | |
) | |
} | |
default | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "KB2800213 and KB2922223 are not required in this OS version" | |
return $script:PASSED | |
} | |
} | |
foreach ($filename in $files) | |
{ | |
$file = Get-Item -Path (Join-Path -Path $Env:SystemRoot -ChildPath $filename) -ErrorAction SilentlyContinue | |
if ($file) | |
{ | |
switch ($OSVersion) | |
{ | |
{ ($OSVersion.Major -eq 6) -and ($OSVersion.Minor -eq 0) } | |
{ | |
$fileversion = [System.Version] ("{0}.{1}.{2}.{3}" -f $file.VersionInfo.FileMajorPart, | |
$file.VersionInfo.FileMinorPart, | |
$file.VersionInfo.FileBuildPart, | |
$file.VersionInfo.FilePrivatePart) | |
} | |
{ ($OSVersion.Major -eq 6) -and ($OSVersion.Minor -eq 1) } | |
{ | |
$fileversion = [System.Version]$file.FileVersion | |
} | |
} | |
if ($fileversion -lt $KB2800213) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
} | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
function checkRealTimeUniversal | |
{ | |
$path = 'HKLM:\System\CurrentControlSet\Control\TimeZoneInformation' | |
$result = Get-ItemProperty -path $path | |
if ($result.RealTimeIsUniversal) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
if ($script:clientOS -eq "Server2003") | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "RealTimeIsUniversal reg key is not supported in Windows Server 2003" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
} | |
function checkMultipleBootPartition | |
{ | |
$script:partitions = Get-WmiObject -class win32_diskpartition | |
$numberofBootable = 0 | |
foreach ($partition in $partitions) | |
{ | |
if ($partition.bootable -eq "True") | |
{ | |
$numberofBootable++ | |
} | |
else | |
{ | |
#do nothing as not a bootable partition | |
} | |
} | |
if ($numberofBootable -gt 1) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $numberofBootable $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $numberofBootable | |
return $script:PASSED | |
} | |
} | |
function checkWindowsPath | |
{ | |
$strMatch = $env:SystemRoot + "\System32" | |
$strMatch2 = $env:SystemRoot + "\System32\wbem" | |
$regPath = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').Path | |
if (($regPath.Split(";") -eq $strMatch) -and ($regPath.Split(";") -eq $strMatch2)) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkPVDrivers | |
{ | |
if (test-path $env:systemroot\system32\drivers\xen*.sys) | |
{ | |
$PVfail = $true | |
} | |
else | |
{ | |
switch ($script:PVcheck) | |
{ | |
gwd { | |
if (Get-WindowsDriver -Online | Where-Object { $_.OriginalFileName -like "xen*" }) | |
{ $PVfail = $true } | |
else | |
{ $PVfail = $false } | |
} | |
dism { | |
if (dism /online /get-drivers /format:table | Select-String -Pattern "xen") | |
{ $PVfail = $true } | |
else | |
{ $PVfail = $false } | |
} | |
driverquery { | |
if (driverquery | Select-String -Pattern "xen") | |
{ $PVfail = $true } | |
else | |
{ $PVfail = $false } | |
} | |
} | |
} | |
if ($PVfail) | |
{ | |
$PVfiles = @() | |
foreach ($file in (Get-ChildItem -Name "$env:systemroot\system32\drivers\xen*.sys")) | |
{ | |
$PVfiles += ((get-item $file).VersionInfo) | |
} | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $true $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $false | |
return $script:PASSED | |
} | |
} | |
function checkEFISysPartition | |
{ | |
if (Get-WmiObject -Class Win32_DiskPartition | Where-Object { $_.Type -eq "GPT: System" }) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $true $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $false | |
return $script:PASSED | |
} | |
} | |
function checkStorageFilterDrivers | |
# Checks for third party filter drivers referenced in common Storage Devices classes | |
# The function pinpoints the file for the filter driver and checks if it is provided by Microsoft Corporation | |
{ | |
$storageClasses = @( | |
"{4D36E96A-E325-11CE-BFC1-08002BE10318}", | |
"{4D36E967-E325-11CE-BFC1-08002BE10318}", | |
"{4D36E97B-E325-11CE-BFC1-08002BE10318}", | |
"{71A27CDD-812A-11D0-BEC7-08002BE2092F}" | |
) | |
foreach ($storageClass in $storageClasses) | |
{ | |
$class = Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Control\Class\$storageClass | |
$upperFilters = $class.UpperFilters | |
$lowerFilters = $class.LowerFilters | |
if ($upperFilters) | |
{ | |
if (-not (Test-Path variable:script:sfFiles)) | |
{ $script:sfFiles = @() } | |
foreach ($upperFilter in $upperFilters) | |
{ | |
$filePath = "ERROR:File Not found" | |
$service = Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\$upperFilter | |
if ($service.ImagePath) | |
{ | |
$ImagePath = $service.ImagePath | |
if (test-path $ImagePath) | |
{ $filePath = $ImagePath } | |
else | |
{ | |
if ($ImagePath -match "system32.*$") | |
{ $filePath = "$env:SYSTEMROOT\$($matches[0])" } | |
} | |
} | |
else | |
{ | |
if (test-path "$env:SYSTEMROOT\System32\Drivers\$upperFilter.sys") | |
{ $filePath = "$env:SYSTEMROOT\System32\Drivers\$upperFilter.sys" } | |
} | |
if ((Get-Item $filePath).VersionInfo.CompanyName -ne "Microsoft Corporation") | |
{ | |
$sfFile = new-object PSObject | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Class" -Value $storageClass | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Filter Type" -Value "Upper" | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Name" -Value $upperFilter | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Company" -Value (Get-Item $filePath).VersionInfo.CompanyName | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Path" -Value $filePath | |
$script:sfFiles += $sfFile | |
$SFfail = $true | |
} | |
} | |
} | |
if ($lowerFilters) | |
{ | |
foreach ($lowerFilter in $lowerFilters) | |
{ | |
$filePath = "ERROR:File Not found" | |
$service = Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\$lowerFilter | |
if ($service.ImagePath) | |
{ | |
$ImagePath = $service.ImagePath | |
if (test-path $ImagePath) | |
{ $filePath = $ImagePath } | |
else | |
{ | |
if ($ImagePath -match "system32.*$") | |
{ $filePath = "$env:SYSTEMROOT\$($matches[0])" } | |
} | |
} | |
else | |
{ | |
if (test-path "$env:SYSTEMROOT\System32\Drivers\$lowerFilter.sys") | |
{ $filePath = "$env:SYSTEMROOT\System32\Drivers\$lowerFilter.sys" } | |
} | |
if ((Get-Item $filePath).VersionInfo.CompanyName -ne "Microsoft Corporation") | |
{ | |
$sfFile = new-object PSObject | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Class" -Value $storageClass | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Filter Type" -Value "Lower" | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Name" -Value $lowerFilter | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Company" -Value (Get-Item $filePath).VersionInfo.CompanyName | |
Add-Member -InputObject $sfFile -MemberType NoteProperty -Name "Path" -Value $filePath | |
$script:sfFiles += $sfFile | |
$SFfail = $true | |
} | |
} | |
} | |
} | |
if ($SFfail) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $true (($FailureTexts.Get($i)).Split("`n"))[1] | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $false | |
return $script:PASSED | |
} | |
} | |
function checkNetworkFilterDrivers | |
{ | |
# Checks for third party filter drivers referenced in common Storage Devices classes | |
# The function pinpoints the file for the filter driver and checks if it is provided by Microsoft Corporation | |
foreach ($key in (Get-ChildItem hklm:\SYSTEM\CurrentControlSet\Control\Class\"{4d36e972-e325-11ce-bfc1-08002be10318}"\0*\Linkage)) | |
{ | |
$upperBinds = ((Get-ItemProperty -Path $key.PSPath).UpperBind) #-notmatch "RDMANDK" | |
if ($upperBinds) | |
{ | |
if (-not (Test-Path variable:script:nfFiles)) | |
{ $script:nfFiles = @() } | |
foreach ($upperBind in $upperBinds) | |
{ | |
$filePath = $false | |
$service = Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\$upperBind | |
if ($service.ImagePath) | |
{ | |
$ImagePath = $service.ImagePath | |
if (test-path $ImagePath) | |
{ $filePath = $ImagePath } | |
else | |
{ | |
if ($ImagePath -match "system32.*$") | |
{ $filePath = "$env:SYSTEMROOT\$($matches[0])" } | |
} | |
} | |
else | |
{ | |
if (test-path "$env:SYSTEMROOT\System32\Drivers\$upperBind.sys") | |
{ $filePath = "$env:SYSTEMROOT\System32\Drivers\$upperBind.sys" } | |
} | |
# Check the file only if ImagePath is defined in the filter's service, there are internal Windows filters with no imagepath such as RDMANDK or TCPIP6TUNNEL | |
if ($filePath) | |
{ | |
if ((Get-Item $filePath).VersionInfo.CompanyName -ne "Microsoft Corporation") | |
{ | |
$nfFile = new-object PSObject | |
Add-Member -InputObject $nfFile -MemberType NoteProperty -Name "Reg Key" -Value $key | |
Add-Member -InputObject $nfFile -MemberType NoteProperty -Name "Filter Type" -Value "UpperBind" | |
Add-Member -InputObject $nfFile -MemberType NoteProperty -Name "Name" -Value $upperBind | |
Add-Member -InputObject $nfFile -MemberType NoteProperty -Name "Company" -Value (Get-Item $filePath).VersionInfo.CompanyName | |
Add-Member -InputObject $nfFile -MemberType NoteProperty -Name "Path" -Value $filePath | |
$script:nfFiles += $nfFile | |
$NFfail = $true | |
} | |
} | |
} | |
} | |
} | |
if ($NFfail) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $true (($FailureTexts.Get($i)).Split("`n"))[1] | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $false | |
return $script:PASSED | |
} | |
} | |
function checkRDPservice | |
#Checks that RDP service Start is set to Manual or Automatic | |
{ | |
$service = Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\TermService | |
if (($service.Start -eq 3) -or ($service.Start -eq 2)) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkDHCPservice | |
#Checks that DHCP Client service Start is set to Automatic | |
{ | |
$service = Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\Dhcp | |
if ($service.Start -eq 2) | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $true "" | |
return $script:PASSED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $false $FailureTexts.Get($i) | |
return $script:FAILED | |
} | |
} | |
function checkPageFile | |
#Checks if the page file is set to system managed | |
{ | |
$Systempagefile = (Get-WmiObject -Class win32_computersystem).AutomaticManagedPagefile | |
if ($Systempagefile) | |
{ | |
$script:logResults += New-LogResult ${script:FailureLabel} $TestLabelTexts.Get($i) $Systempagefile (($FailureTexts.Get($i)).Split("`n"))[1] | |
return $script:FAILED | |
} | |
else | |
{ | |
$script:logResults += New-LogResult ${script:SuccessLabel} $TestLabelTexts.Get($i) $Systempagefile "" | |
return $script:PASSED | |
} | |
} | |
#Initializing log file location, using the directory the script is in. | |
$CurrentWorkingDirectory = split-path -parent $MyInvocation.MyCommand.Definition; | |
$fileTimestamp = get-Date -Format yyyyMMdd'T'hhmmss | |
$Logname = "VMImportLog_" + $fileTimeStamp | |
$Logfile = "${currentWorkingDirectory}\${Logname}.txt" | |
# in the future, export and store in seperate XML file | |
function loadDesktopDictionaryList | |
{ | |
$script:supportedDesktopOS = @{ | |
# Windows 7 version numbers | |
"6.1.7600" = 'Win7' | |
"6.1.7601" = 'Win7' | |
"6.1.7600.16385" = 'Win7' | |
# Windows 8 version numbers | |
"6.2.9200" = 'Win8' | |
"6.2.9200.16384" = 'Win8' | |
# Windows 8.1 version numbers | |
"6.3.9200" = 'Win8.1' | |
"6.3.9600" = 'Win8.1' | |
#Windows 10 version numbers | |
"6.4.9841" = 'Win10' | |
"6.4.9860" = 'Win10' | |
"6.4.9879" = 'Win10' | |
"10.0.9926" = 'Win10' | |
"10.0.10041" = 'Win10' | |
"10.0.10049" = 'Win10' | |
"10.0.10166" = 'Win10' | |
"10.0.10240" = 'Win10' | |
"10.0.10525" = 'Win10' | |
"10.0.10565" = 'Win10' | |
"10.0.10586" = 'Win10' | |
"10.0.14393" = 'Win10' | |
"10.0.15063" = 'Win10' | |
"10.0.16299" = 'Win10' | |
} | |
$script:supportedEditionWin7 = @{ | |
"1" = "Yes" #Ultimate | |
"28" = "Yes" #Ultimate N | |
"71" = "Yes" #Ultimate E | |
"4" = "Yes" #Enterprise | |
"27" = "Yes" #Enterprise N | |
"70" = "Yes" #Enterprise E | |
"48" = "Yes" #Professional | |
"49" = "Yes" #Professional N | |
"69" = "Yes" #Professional E | |
} | |
$script:supportedEditionWin8and81 = @{ | |
"4" = "Yes" #Enterprise | |
"27" = "Yes" #Enterprise N | |
"70" = "Yes" #Enterprise E | |
"48" = "Yes" #Professional | |
"49" = "Yes" #Professional N | |
"69" = "Yes" #Professional E | |
} | |
$script:supportedEditionWin10 = @{ | |
"4" = "Yes" #Enterprise | |
"27" = "Yes" #Enterprise N | |
"70" = "Yes" #Enterprise E | |
"48" = "Yes" #Professional | |
"49" = "Yes" #Professional N | |
"69" = "Yes" #Professional E | |
} | |
} | |
# in the future, export and store in seperate XML file | |
function loadServerDictionaryList | |
{ | |
$script:supportedServerOS = @{ | |
"5.2.3790" = "Server2003" #Win Server 2003 | |
"6.0.6001" = "Server2008SP1" #Windows Server 2008 SP1 | |
"6.0.6002" = "Server2008SP2" #Windows Server 2008 SP2 | |
"6.1.7600" = "Server2008R2" #Windows Server 2008 R2 | |
"6.1.7601" = "Server2008R2SP1" #Windows Server 2008 R2 SP1 | |
"6.2.9200" = "Server2012" #Windows Server 2012 | |
"6.3.9200" = "Server2012" #Windows Server 2012 | |
"6.3.9600" = "Server2012R2" #Windows Server 2012 R2 | |
"10.0.14393" = "Server2016" #Windows Server 2016 | |
} | |
#not using same logic for server 2003 as it doesn't support operatingsystemsku attribute | |
$script:supportedEditionServer2008 = @{ | |
"7" = "Yes" # Server Standard | |
"8" = "Yes" # Server DataCenter | |
"10" = "Yes" # Server Enterprise | |
"12" = "Yes" # Server DataCenter Core | |
"13" = "Yes" # Server Standard Core | |
"14" = "Yes" # Server Enterprise Core | |
"36" = "Yes" # Server Standard without Hyper V | |
"37" = "Yes" # Server DataCenter without Hyper V | |
"38" = "Yes" # Server Enterprise without Hyper V | |
"39" = "Yes" # Server DataCenter without Hyper V Core | |
"40" = "Yes" # Server Standard without Hyper V Core | |
"41" = "Yes" # Server Enterprise without Hyper V Core | |
} | |
$script:supportedEditionServer2012 = @{ | |
"7" = "Yes" # Server Standard | |
"8" = "Yes" # Server DataCenter | |
"12" = "Yes" # Server DataCenter Core | |
"13" = "Yes" # Server Standard Core | |
"36" = "Yes" # Server Standard without Hyper V | |
"37" = "Yes" # Server DataCenter without Hyper V | |
"39" = "Yes" # Server DataCenter without Hyper V Core | |
"40" = "Yes" # Server Standard without Hyper V Core | |
} | |
$script:supportedEditionServer2016 = @{ | |
"7" = "Yes" # Server Standard | |
"8" = "Yes" # Server DataCenter | |
"12" = "Yes" # Server DataCenter Core | |
"13" = "Yes" # Server Standard Core | |
"36" = "Yes" # Server Standard without Hyper V | |
"37" = "Yes" # Server DataCenter without Hyper V | |
"39" = "Yes" # Server DataCenter without Hyper V Core | |
"40" = "Yes" # Server Standard without Hyper V Core | |
} | |
} | |
# Script for checking requirements | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Display Results of test in the form | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Form section | |
Function Button_Click() | |
{ | |
$global:OutputBox.clear() | |
#place holder text | |
$global:OutputBox.AppendText("Running Tests... This could take a few minutes to complete and the window might become temporarily unresponsive") | |
$FailureTexts = @( | |
"Your Windows OS is not supported. Please check the supported Operating Systems for VM Import", | |
"Your Edition of Windows OS is not supported. Please check the supported Operating Systems for VM Import", | |
"Please upgrade to powershell version 2.0 or higher", | |
"Either the builtin Administrator account(SID ending in -500 https://blogs.technet.microsoft.com/heyscriptingguy/2005/07/22/how-can-i-determine-if-the-local-administrator-account-has-been-renamed-on-a-computer) is currently disabled in SAM database or this server is a domain controller`n`nIf this server is part of a domain, confirm if the administrator account is not disabled", | |
"Either the builtin Administrator account(SID ending in -500 https://blogs.technet.microsoft.com/heyscriptingguy/2005/07/22/how-can-i-determine-if-the-local-administrator-account-has-been-renamed-on-a-computer) is currently locked in SAM database or this server is a domain controller`n`nIf this server is part of a domain, confirm if the administrator account is not locked", | |
"Either the builtin Administrator account(SID ending in -500 https://blogs.technet.microsoft.com/heyscriptingguy/2005/07/22/how-can-i-determine-if-the-local-administrator-account-has-been-renamed-on-a-computer) currently does not require a password in SAM database or this server is a domain controller`n`nIf this server is part of a domain, confirm if the administrator account has a password", | |
"Please disable AutoLogon in Registry", | |
#"You currently have more than 1 enabled network interface", | |
"Your network interface is currently using static address. Change this to use DHCP instead", | |
#"You currently have IPv6 Enabled on your network interface. This may not be supported in your region/check your VPC settings", | |
"You have less than 6GB of free disk space on C: drive", | |
"Please remove All Removable, Network and CD/ISO Drives", | |
"Please Install .NET Framework 3.5 SP1 or Later for VMImport", | |
"Windows Firewall is currently enabled. Check the value of EnableFirewall for both Domain Profile and Public Profile in HKLM\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy", | |
"VMWare Tools is currently installed. Please uninstall for VM Import", | |
"One of your attached disks is larger than 1TB. Please detach or make it smaller", | |
"VM Import can only support MBR partitioned volumes", | |
"Please finish installing pending Windows/Software updates", | |
"Install these Hotfixes from Microsoft - http://support.microsoft.com/kb/2922223 and http://support.microsoft.com/kb/2800213", | |
"Enable RealTimeIsUniversal Registry Key - see http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/windows-set-time.html ", | |
"Disable or delete multiple bootable partitions (you should only have one!)", | |
"Missing $env:SystemRoot\System32 or $env:SystemRoot\System32\WBEM reference in the System PATH Environment Variable.`nThis is required for the installation of the drivers needed to run on EC2.", | |
"Xen PV Drivers have been detected in the Driver Store, please uninstall them for VM Import", | |
"EFI System partition has been detected.`nEFI is not supported in EC2, please ensure your source VM uses legacy BIOS mode", | |
"Third Party storage filter drivers have been detected.`nThis might cause the imported VM to be unable to boot and fail the import.`nReview Log section ""Storage Filter Drivers"" for additional details", | |
"Third Party network filter drivers have been detected.`nThis might cause the imported VM to be unable to achieve network connectivity and fail the import.`nReview Log section ""Network Filter Drivers"" for additional details", | |
"Remote Desktop Service is disabled, the imported VM might not be accessible after the import.", | |
"DHCP Service is disabled, the imported VM might not be able to achieve network connectivity and fail the import.", | |
"The page file is set to system managed.`nThe imported VM might run out of space during binaries installation and fail the import.`nPlease set the page file to a fixed size." | |
) | |
$TestCommands = @( | |
"checkOSRequirements", | |
"checkAdditionalOSRequirements", | |
"checkPowershellVersion", | |
"checkAdminAccountEnabled", | |
"checkAdminAccountLocked", | |
"checkAdminAccountPassword", | |
"checkAutoLogon", | |
#"checkSingleNetworkInterface", | |
"checkDHCPEnabledInterface", | |
#"checkIPv6Interface", | |
"checkDiskSpace", | |
"checkForDrives", | |
"checkNETFramework", | |
"checkFirewall", | |
"checkVMWareTools", | |
"checkDriveLargerThan1TB", | |
"checkForGPTPartitions", | |
"checkPendingUpdates", | |
"checkHotFixesInstalled", | |
"checkRealTimeUniversal", | |
"checkMultipleBootPartition", | |
"checkWindowsPath", | |
"checkPVDrivers", | |
"checkEFISysPartition", | |
"checkStorageFilterDrivers", | |
"checkNetworkFilterDrivers", | |
"checkRDPservice", | |
"checkDHCPservice", | |
"checkPageFile" | |
) | |
$TestResults = New-Object System.Collections.ArrayList | |
For ($i = 0; $i -lt $script:CHECK_COUNT; $i++) | |
{ | |
$ResultLabels.Item($i).forecolor = "Black" | |
$ResultLabels.Item($i).text = "Checking.." | |
$CommandName = $TestCommands.Get($i) | |
if ($script:loglevel -eq "verbose") { Write-Log "Beginning test : ${CommandName}" } | |
try | |
{ | |
$scriptResult = (Get-Item "function:$CommandName").ScriptBlock.Invoke(); | |
} | |
catch | |
{ | |
Write-Log $_ | |
if ($null -eq $scriptResult) | |
{ | |
Write-Log " ${CommandName} failed with an exception" | |
$scriptResult = $script:FAILED; | |
} | |
} | |
if ($script:loglevel -eq "verbose") { Write-Log "Ending test : ${CommandName}" } | |
$TestResults.Add($scriptResult) | |
$progressBar.value = (100/$script:CHECK_COUNT) * ($i + 1) | |
switch ($TestResults.Item($i)) | |
{ | |
PASSED | |
{ | |
$ResultLabels.Item($i).ForeColor = "Green" | |
$ResultLabels.Item($i).Text = $script:PASSED | |
} | |
FAILED | |
{ | |
$ResultLabels.Item($i).ForeColor = "Red" | |
$ResultLabels.Item($i).Text = $script:FAILED | |
$FailureText = $FailureTexts.Get($i) | |
$ClickFunction = { | |
$global:OutputBox.clear() | |
$global:OutputBox.AppendText($FailureText) | |
}.GetNewClosure() | |
$TroubleButtons.Item($i).Visible = $true | |
$TroubleButtons.Item($i).Add_Click($ClickFunction) | |
} | |
Default { $global:OutputBox.AppendText("Unable to return results") } | |
} | |
if ($i -eq ($script:CHECK_COUNT - 1)) | |
{ | |
$global:OutputBox.clear() | |
If ($TestResults -match "FAILED") | |
{ $global:OutputBox.AppendText("Tests Completed with Failures.`nClick on the ""Info..."" buttons besides the failed tests, and review the log file for additional information.") } | |
else | |
{ $global:OutputBox.AppendText("Tests Completed.") } | |
} | |
$script:form.Refresh() | |
} | |
#start writing results to log | |
Write-Log (Get-Date).ToUniversalTime() | |
Write-Log "Test Results" | |
Write-Log "**************************************************************************" | |
Write-Log ($script:logResults | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
Write-Log "OS Details" | |
Write-Log "**************************************************************************" | |
Write-Log ($script:sysdetails | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
Write-Log "Storage Details " | |
Write-Log "**************************************************************************" | |
Write-Log "`nAttached Drive types:" | |
Write-Log ($script:drives | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
Write-Log "`List of Partitions:" | |
Write-Log ($script:partitions | Select-Object Index, Name, BootPartition, PrimaryPartition, Type, Size, NumberofBlocks | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
if ($script:sfFiles) | |
{ | |
Write-Log "Storage Filter Drivers" | |
Write-Log "**************************************************************************" | |
Write-Log ($script:sfFiles | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
} | |
if ($script:nfFiles) | |
{ | |
Write-Log "Network Filter Drivers" | |
Write-Log "**************************************************************************" | |
Write-Log ($script:nfFiles | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
} | |
if ($script:PVFiles) | |
{ | |
Write-Log "ParaVirtualization Drivers" | |
Write-Log "**************************************************************************" | |
Write-Log ($PVfiles | Select-Object Filename, FileDescription, CompanyName, FileVersion | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
} | |
Write-Log "Installed .NET Framework versions" | |
Write-Log "**************************************************************************" | |
Write-Log ($script:netFrameworkList | Format-Table -Wrap -AutoSize | Out-String -Width 4096) | |
} | |
Function Generate-Form | |
{ | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
$TestLabelTexts = @( | |
"Supported Windows Operating System", | |
"Supported Edition/Type of Operating System", | |
"Powershell Version", | |
"Administrator Account Enabled", | |
"Administrator Account Not Locked" | |
"Administrator Account Has Password", | |
"Autologon Disabled", | |
#"Single Network Interface Enabled", | |
"DHCP Enabled on Network Interface", | |
#"IPv6 Disabled on Network Interface", | |
"More than 6GB Free Space on C: Drive", | |
"Only Local Disks Attached", | |
".NET Framework version", | |
"Windows Firewall Disabled", | |
"VMWare Tools Uninstalled", | |
"Attached disks smaller than 1TB", | |
"MBR partitioned volumes only", | |
"Pending Windows/Software Update/Installation", | |
"Hotfixes installed - KB2800213 & KB2922223", | |
"RealTimeIsUniversal Reg Key Enabled", | |
"Multiple Bootable Partitions", | |
"Windows Path Statement", | |
"PV Drivers Installation", | |
"EFI System partition", | |
"Third Party storage filter drivers", | |
"Third Party network filter drivers", | |
"RDP Service Enabled", | |
"DHCP Service Enabled", | |
"System Managed Page file" | |
) | |
$script:CHECK_COUNT = $TestLabelTexts.Count | |
# Build Form | |
$Form = New-Object System.Windows.Forms.Form | |
$Form.Text = "AWS VM Import Prerequisites Checker" | |
$Form.Size = New-Object System.Drawing.Size(470, 880) | |
$Form.MaximumSize = New-Object System.Drawing.Size(470, 880) | |
$form.FormBorderStyle = "Sizable" | |
$Form.StartPosition = "WindowsDefaultLocation" | |
$Form.Topmost = $False | |
$Form.ShowInTaskbar = $True | |
$Form.AutoSizeMode = "GrowAndShrink" | |
$Form.SizeGripStyle = "auto" | |
$Form.AutoScroll = $True | |
$script:form = $Form; | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Main Panel | |
$mainPanel = New-Object Windows.Forms.Panel | |
$mainPanel.Anchor = "top", "left" | |
$mainPanel.Size = New-Object System.Drawing.Size (410, 820) | |
$locX = $mainPanel.Location.X + 5 | |
$locY = $mainPanel.Location.Y + 5 | |
$mainPanel.Location = New-Object System.Drawing.Point $locX, $locY | |
$Form.Controls.Add($mainPanel) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Big buttons | |
#Add big buttons | |
$Button1 = New-Object System.Windows.Forms.Button | |
$Button1.Anchor = "top", "left" | |
$locX = $mainPanel.Location.X + 3 | |
$locY = $mainPanel.Location.Y + 5 | |
$Button1.Location = New-Object System.Drawing.Point $locX, $locY | |
$Button1.Size = New-Object System.Drawing.Size(120, 50) | |
$Button1.Text = "Begin Tests" | |
$progressBarLabel = New-Object System.Windows.Forms.label | |
$progressBarLabel.Anchor = "top", "right" | |
$locX = $mainPanel.Location.X + 0.55 * $mainPanel.Size.Width | |
$locY = $mainPanel.Location.Y | |
$progressBarLabel.Location = New-Object System.Drawing.Point $locX, $locY | |
$progressBarLabel.AutoSize = $True | |
$progressBarLabel.Text = "Progress Bar" | |
$progressBar = New-Object System.Windows.Forms.ProgressBar | |
$progressBar.Anchor = "top", "right" | |
$progressBar.Value = 0 | |
$progressBar.Style = "Continuous" | |
$locX = $mainPanel.Location.X + 0.43 * $mainPanel.Size.Width | |
$locY = $mainPanel.Location.Y + 22 | |
$progressBar.Location = New-Object System.Drawing.Point $locX, $locY | |
$progressBar.Size = New-Object System.Drawing.Size(200, 30) | |
#Add big buttons to form | |
$mainPanel.Controls.Add($Button1) | |
$mainPanel.Controls.Add($progressBarLabel) | |
$mainPanel.Controls.Add($progressBar) | |
#Add Button event | |
$Button1.Add_Click({ Button_Click }) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Output Box | |
$global:OutputBox = New-Object System.Windows.Forms.RichTextBox | |
$locX = $mainPanel.Location.X | |
$locY = $mainPanel.Location.Y + 60 | |
$global:OutputBox.Location = New-Object System.Drawing.Point $locX, $locY | |
$global:OutputBox.Size = New-Object System.Drawing.Size(380, 60) | |
$mainPanel.Controls.Add($global:OutputBox) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Test Labels | |
$TestLabels = New-Object System.Collections.ArrayList | |
For ($i = 0; $i -lt $script:CHECK_COUNT; $i++) | |
{ | |
$TestLabel = New-Object System.Windows.Forms.label | |
$TestLabel.Anchor = "top", "left" | |
$locX = $mainPanel.Location.X | |
$locY = $mainPanel.Location.Y + 100 + ($i + 1) * 22 | |
$TestLabel.Location = New-Object System.Drawing.Point $locX, $locY | |
$TestLabel.Text = $TestLabelTexts.Get($i) | |
$TestLabel.AutoSize = $true | |
$TestLabels.Add($TestLabel) | out-null # Suppressing ArrayList.Add index output | |
$mainPanel.Controls.Add($TestLabel) | |
} | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Results Labels | |
$ResultLabels = New-Object System.Collections.ArrayList | |
#Add results labels | |
For ($i = 0; $i -lt $script:CHECK_COUNT; $i++) | |
{ | |
$ResultLabel = New-Object System.Windows.Forms.label | |
$ResultLabel.Anchor = "top", "right" | |
$locX = $mainPanel.Location.X + 0.70 * $mainPanel.Size.Width | |
$locY = $mainPanel.Location.Y + 100 + ($i + 1) * 22 | |
$ResultLabel.Location = New-Object System.Drawing.Point $locX, $locY | |
$ResultLabel.Text = "N/A" | |
$ResultLabel.AutoSize = $True | |
$ResultLabels.Add($ResultLabel) | out-null # Suppressing ArrayList.Add index output | |
$mainPanel.Controls.Add($ResultLabel) | |
} | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Why? Labels | |
$TroubleButtons = New-Object System.Collections.ArrayList | |
#Add why buttons | |
For ($i = 0; $i -lt $script:CHECK_COUNT; $i++) | |
{ | |
$TroubleButton = New-Object System.Windows.Forms.Button | |
$TroubleButton.Anchor = "top", "right" | |
$locX = $mainPanel.Location.X + 0.85 * $mainPanel.Size.Width | |
$locY = $mainPanel.Location.Y + 97 + ($i + 1) * 22 | |
$TroubleButton.Location = New-Object System.Drawing.Point $locX, $locY | |
$TroubleButton.Size = New-Object System.Drawing.Size(50, 20) | |
$TroubleButton.Text = "Info..." | |
$TroubleButton.Visible = $false | |
$TroubleButtons.Add($TroubleButton) | out-null # Suppressing ArrayList.Add index output | |
$mainPanel.Controls.Add($TroubleButton) | |
} | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#$lastTestLocation = [System.Windows.Forms.label]$TestLabels[-1] # Using -1 to reference the last element of the ArrayList does not work in Powershell 2 | |
$lastTestLocation = [System.Windows.Forms.label]$TestLabels[($script:CHECK_COUNT - 1)] | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Link Labels | |
#Add Link labels | |
$LinkLabel1 = New-Object System.Windows.Forms.LinkLabel | |
$locX = $mainPanel.Location.X | |
$locY = $lastTestLocation.Location.Y + 35 | |
$LinkLabel1.Location = New-Object System.Drawing.Point $locX, $locY | |
$LinkLabel1.AutoSize = $True | |
$LinkLabel1.LinkColor = "BLUE" | |
$LinkLabel1.ActiveLinkColor = "RED" | |
$LinkLabel1.Text = "AWS VM Import Prerequisite Page" | |
$LinkLabel1.add_Click({ [system.Diagnostics.Process]::start("http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/VMImportPrerequisites.html") }) | |
$LinkLabel2 = New-Object System.Windows.Forms.LinkLabel | |
$locX = $mainPanel.Location.X | |
$locY = $lastTestLocation.Location.Y + 60 | |
$LinkLabel2.Location = New-Object System.Drawing.Point $locX, $locY | |
$LinkLabel2.AutoSize = $True | |
$LinkLabel2.LinkColor = "BLUE" | |
$LinkLabel2.ActiveLinkColor = "RED" | |
$LinkLabel2.Text = "Windows Management Framework 2.0 (For Server 2003)" | |
$LinkLabel2.add_Click({ [system.Diagnostics.Process]::start("https://support.microsoft.com/en-us/kb/968929") }) | |
$LinkLabel3 = New-Object System.Windows.Forms.LinkLabel | |
$locX = $mainPanel.Location.X | |
$locY = $lastTestLocation.Location.Y + 85 | |
$LinkLabel3.Location = New-Object System.Drawing.Point $locX, $locY | |
$LinkLabel3.AutoSize = $True | |
$LinkLabel3.LinkColor = "BLUE" | |
$LinkLabel3.ActiveLinkColor = "RED" | |
$LinkLabel3.Text = "Windows Management Framework 4.0 (For All Other Windows OS)" | |
$LinkLabel3.add_Click({ [system.Diagnostics.Process]::start("https://www.microsoft.com/en-au/download/details.aspx?id=40855") }) | |
#Add link labels to form | |
$mainPanel.Controls.Add($LinkLabel1) | |
$mainPanel.Controls.Add($LinkLabel2) | |
$mainPanel.Controls.Add($LinkLabel3) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#Show the Form (do this at the end of the function) | |
$form.ShowDialog() | Out-Null | |
} #End Function | |
Generate-Form |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment