Upload files to "/"
This commit is contained in:
commit
4406d0664c
75
Change-OrganizationPolicy.ps1
Normal file
75
Change-OrganizationPolicy.ps1
Normal file
@ -0,0 +1,75 @@
|
||||
#Gets the API token and creates the headers for subsiquent calls
|
||||
$ClientID = ""
|
||||
$ClientSecret = ""
|
||||
|
||||
#Gets Monitoring token to get info
|
||||
$bodyMo = @{
|
||||
grant_type = "client_credentials"
|
||||
client_id = "$ClientID"
|
||||
client_secret = "$ClientSecret"
|
||||
redirect_uri = "https://localhost"
|
||||
scope = "monitoring"
|
||||
}
|
||||
|
||||
$API_AuthHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
|
||||
$API_AuthHeaders.Add("accept", 'application/json')
|
||||
$API_AuthHeaders.Add("Content-Type", 'application/x-www-form-urlencoded')
|
||||
|
||||
$auth_tokenMo = Invoke-RestMethod -Uri https://eu.ninjarmm.com/oauth/token -Method POST -Headers $API_AuthHeaders -Body $bodyMo
|
||||
$access_tokenMo = $auth_tokenMo | Select-Object -ExpandProperty 'access_token' -EA 0
|
||||
|
||||
$headersMo = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
|
||||
$headersMo.Add("Accept", "application/json")
|
||||
$headersMo.Add("Authorization", "Bearer $access_tokenMo")
|
||||
|
||||
#Gets Management token to change info
|
||||
$bodyMa = @{
|
||||
grant_type = "client_credentials"
|
||||
client_id = "$ClientID"
|
||||
client_secret = "$ClientSecret"
|
||||
redirect_uri = "https://localhost"
|
||||
scope = "management"
|
||||
}
|
||||
|
||||
$auth_tokenMa = Invoke-RestMethod -Uri https://eu.ninjarmm.com/oauth/token -Method POST -Headers $API_AuthHeaders -Body $bodyMa
|
||||
$access_tokenMa = $auth_tokenMa | Select-Object -ExpandProperty 'access_token' -EA 0
|
||||
|
||||
$headersMa = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
|
||||
$headersMa.Add("Accept", "application/json")
|
||||
$headersMa.Add("Authorization", "Bearer $access_tokenMa")
|
||||
|
||||
#Gets Control token to change info
|
||||
$bodyC = @{
|
||||
grant_type = "client_credentials"
|
||||
client_id = "$ClientID"
|
||||
client_secret = "$ClientSecret"
|
||||
redirect_uri = "https://localhost"
|
||||
scope = "control"
|
||||
}
|
||||
|
||||
$auth_tokenC = Invoke-RestMethod -Uri https://eu.ninjarmm.com/oauth/token -Method POST -Headers $API_AuthHeaders -Body $bodyC
|
||||
$access_tokenC = $auth_tokenC | Select-Object -ExpandProperty 'access_token' -EA 0
|
||||
|
||||
$headersC = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
|
||||
$headersC.Add("Accept", "application/json")
|
||||
$headersC.Add("Authorization", "Bearer $access_tokenC")
|
||||
|
||||
## Main
|
||||
|
||||
#Gets the detailed info of all organizations
|
||||
$organizations = Invoke-RestMethod 'https://eu.ninjarmm.com/api/v2/organizations-detailed' -Method 'GET' -Headers $headersMo
|
||||
|
||||
# Difine the policy changes
|
||||
#nodeRoleId is the ID of the role you are wanting to change, this can be found by running the /api/v2/roles api call
|
||||
#policyId is the ID of the Policy you want to make default, this can be found by going to the portal and editing the policy and looking at the last number in the URL or by running the /api/v2/policies api call
|
||||
$newPolicy = '[
|
||||
{
|
||||
"nodeRoleId": 1008,
|
||||
"policyId": 64
|
||||
}
|
||||
]'
|
||||
|
||||
ForEach ($org in $organizations){
|
||||
$id = $org.id
|
||||
Invoke-RestMethod -Uri "https://eu.ninjarmm.com/api/v2/organization/$id/policies" -Method PUT -Headers $headersMa -ContentType 'application/json' -Body $newPolicy
|
||||
}
|
15
Check-IsDHCPServer.ps1
Normal file
15
Check-IsDHCPServer.ps1
Normal file
@ -0,0 +1,15 @@
|
||||
try {
|
||||
$DHCP = Get-DhcpServerInDC
|
||||
}
|
||||
catch {
|
||||
$DHCP = $null
|
||||
Write-Host "False"
|
||||
Ninja-Property-Set isdhcpserver "False"
|
||||
}
|
||||
|
||||
$DNSName = ([system.net.dns]::GetHostByName("localhost")).hostname
|
||||
|
||||
if ($DNSName -in $DHCP.DnsName){
|
||||
Write-Host "True"
|
||||
Ninja-Property-Set isdhcpserver "True"
|
||||
}
|
41
Detect-VSS.ps1
Normal file
41
Detect-VSS.ps1
Normal file
@ -0,0 +1,41 @@
|
||||
$ScheduledTasks = Get-ScheduledTask -TaskName "ShadowCopy*"
|
||||
$DefaultTasks = Get-ScheduledTask -TaskName "ShadowCopyVolume{*}"
|
||||
$CustomTasks = Get-ScheduledTask -TaskName "ShadowCopy * drive"
|
||||
|
||||
$CustomTaskLetters = ForEach ($task in $CustomTasks){$task.TaskName[11]}
|
||||
|
||||
$VSS = [PSCustomObject]@{
|
||||
enabled = $false
|
||||
type = $null
|
||||
}
|
||||
|
||||
$Disks = Get-Volume | Where-Object {$_.DriveType -eq "Fixed"} | Where-Object {$_.DriveLetter -ne $null} | Where-Object {$_.Size -gt 5GB}
|
||||
|
||||
$MissingDrives = ForEach ($letter in $Disks.DriveLetter){if ($letter -notin $CustomTaskLetters){$letter}}
|
||||
|
||||
#No Tasks
|
||||
if ($ScheduledTasks -eq $null)
|
||||
{Write-Host "No VSS Tasks"}
|
||||
#Default Tasks
|
||||
elseif ($DefaultTasks.State -ne "Disabled")
|
||||
{Write-Host "Default VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Default"}
|
||||
#Default Tasks Disabled and No Custom Tasks
|
||||
if (($DefaultTasks.State -eq "Disabled") -and ($CustomTasks -eq $null))
|
||||
{Write-Host "Default VSS Tasks Disabled and NO Custom VSS Tasks"; $VSS.enabled = $false; $VSS.type = "Default"}
|
||||
#Default Tasks Disabled and Custom Tasks Enabled
|
||||
if ((($DefaultTasks.State -eq "Disabled") -or ($DefaultTasks -eq $null)) -and ($CustomTasks -ne $null))
|
||||
{Write-Host "Default VSS Tasks Disabled and Custom VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Custom"}
|
||||
#Default Tasks Disabled and Custom Tasks Enabled, but not all drives have been enabled
|
||||
if ($MissingDrives -ne $null)
|
||||
{Write-Host "Default VSS Tasks Disabled and Custom VSS Tasks Enabled, But Not all Drives are Enabled"; $VSS.enabled = $true; $VSS.type = "Custom, Incomplete"}
|
||||
|
||||
|
||||
if ($Host.Version.Major -gt 4){Write-Host $VSS}
|
||||
elseif ($Host.Version.Major -lt 5){$VSS}
|
||||
|
||||
Ninja-Property-Set vssenabled $VSS.enabled
|
||||
Ninja-Property-Set vsstype $VSS.type
|
||||
|
||||
if ($VSS.enabled -eq $false){exit 1}
|
||||
elseif ($VSS.type -ne "Custom"){exit 2}
|
||||
else{exit 0}
|
71
Enable-VSSScheduledTasksV3.2.ps1
Normal file
71
Enable-VSSScheduledTasksV3.2.ps1
Normal file
@ -0,0 +1,71 @@
|
||||
#Script to Enable VSS with Custom Schedule, Disabe Default VSS tasks if there are any, update ninja custom feilds.
|
||||
|
||||
#Setting Varibles
|
||||
$date = Get-Date -Format yyyy-MM-dd
|
||||
|
||||
New-Item -ItemType Directory -Force -Path C:\DiscStuff\Logs
|
||||
|
||||
$ScheduledTasks = @()
|
||||
$DisabledTasks = @()
|
||||
|
||||
#Enable VSS and Set tasks
|
||||
$Disks = Get-Volume | Where-Object {$_.DriveType -eq "Fixed"} | Where-Object {$_.DriveLetter -ne $null} | Where-Object {$_.Size -gt 5GB}
|
||||
|
||||
$offset = New-TimeSpan
|
||||
$offsetInterval = New-TimeSpan -Minutes 15
|
||||
|
||||
foreach ($Disk in $Disks) {
|
||||
# Enable Shadows
|
||||
vssadmin add shadowstorage /for=$($Disk.DriveLetter): /on=$($Disk.DriveLetter): /maxsize=10%
|
||||
# Set Shadow Copy Scheduled Task for C: 06:00, 12:00 and 17:00
|
||||
|
||||
$time1 = New-TimeSpan -Hours 6
|
||||
$time2 = New-TimeSpan -Hours 12
|
||||
$time3 = New-TimeSpan -Hours 17
|
||||
|
||||
$Argument = "-command ""C:\Windows\system32\vssadmin.exe create shadow /for=$($Disk.DriveLetter):"""
|
||||
$Action = new-scheduledtaskaction -execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument $Argument
|
||||
$Trigger1 = new-scheduledtasktrigger -daily -at ($time1 + $offset).ToString()
|
||||
$Trigger2 = new-scheduledtasktrigger -daily -at ($time2 + $offset).ToString()
|
||||
$Trigger3 = new-scheduledtasktrigger -daily -at ($time3 + $offset).ToString()
|
||||
Register-ScheduledTask -TaskName "ShadowCopy $($Disk.DriveLetter) drive" -Trigger $Trigger1,$Trigger2,$Trigger3 -Action $Action -Description "ShadowCopy for $($Disk.DriveLetter) drive" -user "NT AUTHORITY\SYSTEM" -RunLevel Highest -Force
|
||||
$offset = $offset + $offsetInterval
|
||||
}
|
||||
|
||||
#Disable Default tasks
|
||||
$ScheduledTasks = Get-ScheduledTask -TaskName "ShadowCopyVolume{*}"
|
||||
|
||||
$DisabledTasks = foreach ($Task in $ScheduledTasks){Disable-ScheduledTask -TaskName $Task.TaskName}
|
||||
|
||||
$DisabledTasks | ConvertTo-html -Property TaskName, State | Out-File C:\DiscStuff\Logs\$date-Shadows.html
|
||||
|
||||
if (!$DisabledTasks) {Write-Host "No Default VSS Tasks Disabled"}
|
||||
else {Write-Host "Default VSS Tasks have been disabled. Please see log on Device to see details: C:\DiscStuff\Logs"}
|
||||
|
||||
#Update Custom feilds
|
||||
$ScheduledTasks = Get-ScheduledTask -TaskName "ShadowCopy*"
|
||||
$DefaultTasks = Get-ScheduledTask -TaskName "ShadowCopyVolume{*}"
|
||||
$CustomTasks = Get-ScheduledTask -TaskName "ShadowCopy * drive"
|
||||
|
||||
$VSS = [PSCustomObject]@{
|
||||
enabled = $false
|
||||
type = $null
|
||||
}
|
||||
#No Tasks
|
||||
if ($ScheduledTasks -eq $null)
|
||||
{Write-Host "No VSS Tasks"}
|
||||
#Default Tasks
|
||||
elseif ($DefaultTasks.State -ne "Disabled")
|
||||
{Write-Host "Default VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Default"}
|
||||
#Default Tasks Disabled and No Custom Tasks
|
||||
if (($DefaultTasks.State -eq "Disabled") -and ($CustomTasks -eq $null))
|
||||
{Write-Host "Default VSS Tasks Disabled and NO Custom VSS Tasks"; $VSS.enabled = $false; $VSS.type = "Default"}
|
||||
#Default Tasks Disabled and Custom Tasks Enabled
|
||||
if ((($DefaultTasks.State -eq "Disabled") -or ($DefaultTasks -eq $null)) -and ($CustomTasks -ne $null))
|
||||
{Write-Host "Default VSS Tasks Disabled and Custom VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Custom"}
|
||||
|
||||
if ($Host.Version.Major -gt 4){Write-Host $VSS}
|
||||
elseif ($Host.Version.Major -lt 5){$VSS}
|
||||
|
||||
Ninja-Property-Set vssenabled $VSS.enabled
|
||||
Ninja-Property-Set vsstype $VSS.type
|
Loading…
x
Reference in New Issue
Block a user