diff --git a/Connect-MSO365.ps1 b/Connect-MSO365.ps1 new file mode 100644 index 0000000..8351e24 --- /dev/null +++ b/Connect-MSO365.ps1 @@ -0,0 +1,32 @@ +#Requires -Version 3.0 + +param([string]$User) + +## Install ExchangeOnlineManagement module if it doesn't already exist +If ( !(Get-Module -ListAvailable -Name ExchangeOnlineManagement) ) +{ + Try { Install-Module -Name ExchangeOnlineManagement -RequiredVersion 1.0.1 } + Catch { Write-Output $_.Exception.Message ; Exit } +} +Import-Module ExchangeOnlineManagement + +Connect-ExchangeOnline -UserPrincipalName $User -ShowProgress $true + + +$Groups = Get-UnifiedGroup -ResultSize Unlimited +$Groups | ForEach-Object { + $group = Get-UnifiedGroupLinks -Identity $_.Name -LinkType Members -ResultSize Unlimited + $group | ForEach-Object { + New-Object -TypeName PSObject -Property @{ + Group = $group.DisplayName + Member = $_.Name + EmailAddress = $_.PrimarySMTPAddress + RecipientType= $_.RecipientType + } + } +} | Export-CSV “${Env:UserProfile}\Desktop\group-export.csv" -NoTypeInformation -Encoding UTF8 + + + + +Disconnect-ExchangeOnline \ No newline at end of file diff --git a/Install-DisplayLink.ps1 b/Install-DisplayLink.ps1 index 17d7d57..09d410c 100644 --- a/Install-DisplayLink.ps1 +++ b/Install-DisplayLink.ps1 @@ -1,4 +1,4 @@ -## Define base URL for getting installers +## Define base URL for getting installer $BaseURL = 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/resources' ## Build URL for Windows 10 diff --git a/Install-ManagementAgent.ps1 b/Install-ManagementAgent.ps1 index 06a67ab..cee914e 100644 --- a/Install-ManagementAgent.ps1 +++ b/Install-ManagementAgent.ps1 @@ -48,13 +48,6 @@ If ( $CUSTOMER_ID ) Catch { Write-Log $_.Exception.Message } } - ### Setup security and certificate parameters to download from untrusted sources - #[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} - #[Net.ServicePointManager]::SecurityProtocol = - # [Net.SecurityProtocolType]::Tls12 -bor ` - # [Net.SecurityProtocolType]::Tls11 -bor ` - # [Net.SecurityProtocolType]::Tls - ## Download the agent installer Write-Log "Downloading agent installer from: ${AGENT_URL}" Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) } diff --git a/Install-SketchUp.ps1 b/Install-SketchUp.ps1 new file mode 100644 index 0000000..3927f66 --- /dev/null +++ b/Install-SketchUp.ps1 @@ -0,0 +1,56 @@ +## Uninstall SketchUp 2016 +If ( Test-Path "${Env:ProgramFiles}\SketchUp\SketchUp 2016\SketchUp.exe" ) +{ + Write-Output "Uninstalling SketchUp 2016..." + Try { Start-Process "msiexec.exe" -ArgumentList '/X{D87EE6DC-32BA-4219-AC75-0A6FD54ED058} /qn /norestart' -Wait } + Catch { Write-Output $_.Exception.Message } +} + +## Uninstall SketchUp 2017 +If ( Test-Path "${Env:ProgramFiles}\SketchUp\SketchUp 2017\SketchUp.exe" ) +{ + Write-Output "Uninstalling SketchUp 2017..." + Try { Start-Process "msiexec.exe" -ArgumentList '/X{E59BD84C-169B-4F3F-AC5D-85127CF67051} /qn /norestart' -Wait } + Catch { Write-Output $_.Exception.Message } +} + +## Uninstall SketchUp 2019 +If ( Test-Path "${Env:ProgramFiles}\SketchUp\SketchUp 2019\SketchUp.exe" ) +{ + Write-Output "Uninstalling SketchUp 2019..." + Try { Start-Process "msiexec.exe" -ArgumentList '/X{06964675-EB01-6D18-6704-429DE73A8319} /qn /norestart' -Wait } + Catch { Write-Output $_.Exception.Message } +} + +## Uninstall SketchUp 2020 +If ( Test-Path "${Env:ProgramFiles}\SketchUp\SketchUp 2020\SketchUp.exe" ) +{ + Write-Output "Uninstalling SketchUp 2020..." + Try { Start-Process "msiexec.exe" -ArgumentList '/X{5778f9a3-781e-16f1-a6bf-08fd59dfa77b} /qn /norestart' -Wait } + Catch { Write-Output $_.Exception.Message } +} + +## Define URL for downloading the installer +$URL = 'https://www.sketchup.com/sketchup/2020/SketchUpPro-exe' +$FILE = '{0}\{1}.exe' -f $Env:TEMP,(Split-Path $URL -Leaf) + +## Remove previous package +If ( Test-Path $FILE ) { Remove-Item -Path $FILE -Force | Out-Null} + +## Download installer +Write-Output "Downloading: ${URL}" +Try { (New-Object System.Net.WebClient).DownloadFile($URL, $FILE) } +Catch { Write-Output $_.Exception.Message } + +## Install package +Write-Output "Installing: ${FILE}" +Try { Start-Process -FilePath $FILE -ArgumentList "/silent" -Wait } +Catch { $_.Exception.Message } + +## Delete installer package +If ( Test-Path $FILE ) +{ + Write-Output "Deleting ${FILE}" + Try { Remove-Item -Path $FILE -Force } + Catch { Write-Output $_.Exception.Message } +} diff --git a/PSModule.old/PSModule.psm1 b/PSModule.old/PSModule.psm1 deleted file mode 100644 index ad2656b..0000000 --- a/PSModule.old/PSModule.psm1 +++ /dev/null @@ -1,158 +0,0 @@ -#Requires -Version 2.0 - -## Set the name of this module -$ModuleName = "PSModule" - -## Define base URL for updating modules and resources -$BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/${ModuleName}" - -## Set the path to this module -$ModulePath = "${Env:MSPDir}\Scripts\${ModuleName}" - -## Define the paths for where we'll place stuff on the endpoint -$MSPRoot = $Env:MSPDir -$MSPScripts = "${MSPRoot}\Scripts" -$MSPTools = "${MSPRoot}\Tools" -$MSPLogs = "${MSPRoot}\Logs" - -## Function to simply import a module and return an error message if it fails -Function Load-Module -{ - param([string]$modulename) - - ## Get a new copy of the module - Get-Module $modulename - - ## Form the local file path to the specified module - $FilePath = "${ModulePath}\${modulename}.psm1" - - ## Import the module - If ( Test-Path $FilePath ) - { - Try { Import-Module -Name $FilePath } - Catch { Write-Output $_.Exception.Message } - } Else { Write-Output "Module does not exist: ${FilePath}" } -} - -## Function to update or install a module -Function Get-Module -{ - param([string]$modulename) - - ## Form the URL to the specified module - $ModuleURL = "${BaseURL}/${modulename}.psm1" - - ## Form the local file path to the specified module - $FilePath = "${ModulePath}\${modulename}.psm1" - - ## Download the new file, overwriting the local copy - If ( IsDownloadable $ModuleURL ) - { - Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, $FilePath) } - Catch { Write-Output $_.Exception.Message } - } Else { Write-Output "Could not download ${ModuleURL}" } -} - -## Determines whether a file can be downloaded or not -Function IsDownloadable -{ - param([string]$url) - - ## Create a web request - $HTTPRequest = [System.Net.WebRequest]::Create($url) - - Try - { - ## Get the response - $HTTPResponse = $HTTPRequest.GetResponse() - - ## Save the status code - $HTTPStatus = [int]$HTTPResponse.StatusCode - } - Catch [System.Net.WebException] { $HTTPResponse = $_.Exception.Response } - - ## Close the connection, because we're done with it - Finally { $HTTPResponse.Close() } - - ## Test to make sure we received a status of 200 "OK" from the resource - If ($HTTPStatus -eq 200) { Return $true } - - ## If the status code is anything other than 200, return $false - Else { Return $false } -} - -## EXPORT FUNCTION -## Function to log activity to the configured log directory -Function global:Log -{ - Begin {} - Process {} - End {} -} - -## EXPORT FUNCTION -## Function to determine if the current user context is an Administrator -Function global:IsAdmin -{ - Begin {} - Process - { - If ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) ) - { Return $true } Else { Return $false } - } - End {} -} - -## EXPORT FUNCTION -## Function to retrieve and run a powershell script -Function Run-PSScript -{ - param( - [string]$Type='management-scripts', - [string]$Name, - [string]$Arguments - ) - - ## Form the URL to the specified script - $URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1" - - If ( IsDownloadable $URL ) - { - $Script = (New-Object Net.WebClient).DownloadString($URL) - $ScriptBlock = [Scriptblock]::Create($Script) - Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } - Catch { Write-Output $_.Exception.Message } - } Else { Write-Output "Could not retrieve ${URL}" } -} - -## Make sure all the management directories exist -If ( !(Test-Path $MSPRoot) ) -{ - Try { New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null } - Catch { Write-Output $_.Exception.Message } -} -If ( !(Test-Path $MSPScripts) ) -{ - Try { New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null } - Catch { Write-Output $_.Exception.Message } -} -If ( !(Test-Path $MSPTools) ) -{ - Try { New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null } - Catch { Write-Output $_.Exception.Message } -} -If ( !(Test-Path $MSPLogs) ) -{ - Try { New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null } - Catch { Write-Output $_.Exception.Message } -} - -## Import all modules -$ListOfModules = @( - "PSModule", - "PSModule-SetWinEvtLog" -) -ForEach ($module in $ListOfModules) { Load-Module $module } - -## Make sure this module exports only the functions that should be exported -Export-ModuleMember -Function Log,IsAdmin,Run-PSScript \ No newline at end of file diff --git a/PSModule.old/PSModule-SetWinEvtLog.psm1 b/PSModule/PSModule-SetWinEvtLog.psm1 similarity index 100% rename from PSModule.old/PSModule-SetWinEvtLog.psm1 rename to PSModule/PSModule-SetWinEvtLog.psm1 diff --git a/PSModule/PSModule.psm1 b/PSModule/PSModule.psm1 index 35d85ff..ad2656b 100644 --- a/PSModule/PSModule.psm1 +++ b/PSModule/PSModule.psm1 @@ -1,27 +1,158 @@ #Requires -Version 2.0 -param( - [string]$Type='management-scripts', - [string]$Name, - [string]$Arguments) +## Set the name of this module +$ModuleName = "PSModule" -## Form the URL to the specified script -$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1" +## Define base URL for updating modules and resources +$BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/${ModuleName}" -## Get the script -Write-Output "Retrieving script: ${Name}" -Try { $Script = (New-Object Net.WebClient).DownloadString($URL) } -Catch { Write-Output $_.Exception.Message } +## Set the path to this module +$ModulePath = "${Env:MSPDir}\Scripts\${ModuleName}" -## Make a script block -Write-Output "Creating scriptblock" -Try { $ScriptBlock = [Scriptblock]::Create($Script) } -Catch { Write-Output $_.Exception.Message } +## Define the paths for where we'll place stuff on the endpoint +$MSPRoot = $Env:MSPDir +$MSPScripts = "${MSPRoot}\Scripts" +$MSPTools = "${MSPRoot}\Tools" +$MSPLogs = "${MSPRoot}\Logs" -## Run the script any any arguments -Write-Output "${Name}.ps1 ${Arguments}" -Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } -Catch { Write-Output $_.Exception.Message } +## Function to simply import a module and return an error message if it fails +Function Load-Module +{ + param([string]$modulename) -## Finish script -Write-Output "${Name}.ps1 has finished" \ No newline at end of file + ## Get a new copy of the module + Get-Module $modulename + + ## Form the local file path to the specified module + $FilePath = "${ModulePath}\${modulename}.psm1" + + ## Import the module + If ( Test-Path $FilePath ) + { + Try { Import-Module -Name $FilePath } + Catch { Write-Output $_.Exception.Message } + } Else { Write-Output "Module does not exist: ${FilePath}" } +} + +## Function to update or install a module +Function Get-Module +{ + param([string]$modulename) + + ## Form the URL to the specified module + $ModuleURL = "${BaseURL}/${modulename}.psm1" + + ## Form the local file path to the specified module + $FilePath = "${ModulePath}\${modulename}.psm1" + + ## Download the new file, overwriting the local copy + If ( IsDownloadable $ModuleURL ) + { + Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, $FilePath) } + Catch { Write-Output $_.Exception.Message } + } Else { Write-Output "Could not download ${ModuleURL}" } +} + +## Determines whether a file can be downloaded or not +Function IsDownloadable +{ + param([string]$url) + + ## Create a web request + $HTTPRequest = [System.Net.WebRequest]::Create($url) + + Try + { + ## Get the response + $HTTPResponse = $HTTPRequest.GetResponse() + + ## Save the status code + $HTTPStatus = [int]$HTTPResponse.StatusCode + } + Catch [System.Net.WebException] { $HTTPResponse = $_.Exception.Response } + + ## Close the connection, because we're done with it + Finally { $HTTPResponse.Close() } + + ## Test to make sure we received a status of 200 "OK" from the resource + If ($HTTPStatus -eq 200) { Return $true } + + ## If the status code is anything other than 200, return $false + Else { Return $false } +} + +## EXPORT FUNCTION +## Function to log activity to the configured log directory +Function global:Log +{ + Begin {} + Process {} + End {} +} + +## EXPORT FUNCTION +## Function to determine if the current user context is an Administrator +Function global:IsAdmin +{ + Begin {} + Process + { + If ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) ) + { Return $true } Else { Return $false } + } + End {} +} + +## EXPORT FUNCTION +## Function to retrieve and run a powershell script +Function Run-PSScript +{ + param( + [string]$Type='management-scripts', + [string]$Name, + [string]$Arguments + ) + + ## Form the URL to the specified script + $URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1" + + If ( IsDownloadable $URL ) + { + $Script = (New-Object Net.WebClient).DownloadString($URL) + $ScriptBlock = [Scriptblock]::Create($Script) + Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } + Catch { Write-Output $_.Exception.Message } + } Else { Write-Output "Could not retrieve ${URL}" } +} + +## Make sure all the management directories exist +If ( !(Test-Path $MSPRoot) ) +{ + Try { New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null } + Catch { Write-Output $_.Exception.Message } +} +If ( !(Test-Path $MSPScripts) ) +{ + Try { New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null } + Catch { Write-Output $_.Exception.Message } +} +If ( !(Test-Path $MSPTools) ) +{ + Try { New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null } + Catch { Write-Output $_.Exception.Message } +} +If ( !(Test-Path $MSPLogs) ) +{ + Try { New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null } + Catch { Write-Output $_.Exception.Message } +} + +## Import all modules +$ListOfModules = @( + "PSModule", + "PSModule-SetWinEvtLog" +) +ForEach ($module in $ListOfModules) { Load-Module $module } + +## Make sure this module exports only the functions that should be exported +Export-ModuleMember -Function Log,IsAdmin,Run-PSScript \ No newline at end of file diff --git a/PSModule.old/old/PSModule-Cleanup.psm1 b/PSModule/old/PSModule-Cleanup.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Cleanup.psm1 rename to PSModule/old/PSModule-Cleanup.psm1 diff --git a/PSModule.old/old/PSModule-Create.psm1 b/PSModule/old/PSModule-Create.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Create.psm1 rename to PSModule/old/PSModule-Create.psm1 diff --git a/PSModule.old/old/PSModule-Fix.psm1 b/PSModule/old/PSModule-Fix.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Fix.psm1 rename to PSModule/old/PSModule-Fix.psm1 diff --git a/PSModule.old/old/PSModule-Get.psm1 b/PSModule/old/PSModule-Get.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Get.psm1 rename to PSModule/old/PSModule-Get.psm1 diff --git a/PSModule.old/old/PSModule-Install.psm1 b/PSModule/old/PSModule-Install.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Install.psm1 rename to PSModule/old/PSModule-Install.psm1 diff --git a/PSModule.old/old/PSModule-Remediation.psm1 b/PSModule/old/PSModule-Remediation.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Remediation.psm1 rename to PSModule/old/PSModule-Remediation.psm1 diff --git a/PSModule.old/old/PSModule-Remove.psm1 b/PSModule/old/PSModule-Remove.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Remove.psm1 rename to PSModule/old/PSModule-Remove.psm1 diff --git a/PSModule.old/old/PSModule-Start.psm1 b/PSModule/old/PSModule-Start.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Start.psm1 rename to PSModule/old/PSModule-Start.psm1 diff --git a/PSModule.old/old/PSModule-Upload.psm1 b/PSModule/old/PSModule-Upload.psm1 similarity index 100% rename from PSModule.old/old/PSModule-Upload.psm1 rename to PSModule/old/PSModule-Upload.psm1 diff --git a/Run-PSScript.ps1 b/Run-PSScript.ps1 new file mode 100644 index 0000000..dd0be62 --- /dev/null +++ b/Run-PSScript.ps1 @@ -0,0 +1,32 @@ +#Requires -Version 2.0 + +param( + [string]$Type='management-scripts', + [string]$Name, + [string]$Arguments) + +## Get rid of null arguments +If ( $Arguments -eq "null" ) { $Arguments = $null } + +## Make sure $Name and $Type are defined +If ( $Name -and $Type ) +{ + ## Form the URL to the specified script + $URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1" + + ## Get the script + Write-Output "Retrieving : ${Name}.ps1" + Try { $Script = (New-Object Net.WebClient).DownloadString($URL) } + Catch { Write-Output $_.Exception.Message } + + ## Make a script block + Try { $ScriptBlock = [Scriptblock]::Create($Script) } + Catch { Write-Output $_.Exception.Message } + + ## Run the script any any arguments + Write-Output "Executing: ${Name}.ps1 ${Arguments}" + Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } + Catch { Write-Output $_.Exception.Message } +} + +Else { Write-Output "No script or type was specified" } \ No newline at end of file diff --git a/test.ps1 b/test.ps1 deleted file mode 100644 index 1695ee0..0000000 --- a/test.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -start-sleep 5 -write-output "test is done" \ No newline at end of file