This commit is contained in:
2020-08-30 23:05:07 -04:00
parent 82adef14b5
commit e38f9bd599
18 changed files with 272 additions and 188 deletions
+32
View File
@@ -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
+1 -1
View File
@@ -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' $BaseURL = 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/resources'
## Build URL for Windows 10 ## Build URL for Windows 10
-7
View File
@@ -48,13 +48,6 @@ If ( $CUSTOMER_ID )
Catch { Write-Log $_.Exception.Message } 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 ## Download the agent installer
Write-Log "Downloading agent installer from: ${AGENT_URL}" Write-Log "Downloading agent installer from: ${AGENT_URL}"
Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) } Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) }
+56
View File
@@ -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 }
}
-158
View File
@@ -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
+151 -20
View File
@@ -1,27 +1,158 @@
#Requires -Version 2.0 #Requires -Version 2.0
param( ## Set the name of this module
[string]$Type='management-scripts', $ModuleName = "PSModule"
[string]$Name,
[string]$Arguments)
## Form the URL to the specified script ## Define base URL for updating modules and resources
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1" $BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/${ModuleName}"
## Get the script ## Set the path to this module
Write-Output "Retrieving script: ${Name}" $ModulePath = "${Env:MSPDir}\Scripts\${ModuleName}"
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
Catch { Write-Output $_.Exception.Message }
## Make a script block ## Define the paths for where we'll place stuff on the endpoint
Write-Output "Creating scriptblock" $MSPRoot = $Env:MSPDir
Try { $ScriptBlock = [Scriptblock]::Create($Script) } $MSPScripts = "${MSPRoot}\Scripts"
Catch { Write-Output $_.Exception.Message } $MSPTools = "${MSPRoot}\Tools"
$MSPLogs = "${MSPRoot}\Logs"
## Run the script any any arguments ## Function to simply import a module and return an error message if it fails
Write-Output "${Name}.ps1 ${Arguments}" Function Load-Module
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } {
Catch { Write-Output $_.Exception.Message } param([string]$modulename)
## Finish script ## Get a new copy of the module
Write-Output "${Name}.ps1 has finished" 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
+32
View File
@@ -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" }
-2
View File
@@ -1,2 +0,0 @@
start-sleep 5
write-output "test is done"