-
Notifications
You must be signed in to change notification settings - Fork 0
/
SE_NoBeacon.ps1
59 lines (50 loc) · 3.51 KB
/
SE_NoBeacon.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$filePath = 'your save path here\SANDBOX_0_0_0_.sbs'
$deletedlogs = "yourlogs path here\Admin Logs\Audits\deleted\"
# ===== only change the above value
$CurrentDateTime = Get-Date -Format "MM-dd-yyyy_HH-mm"
$deletedfilename = "Owned_Audit_" +$CurrentDateTime+ ".log"
$deletedpath = $deletedLogs + $deletedfilename
[xml]$myXML = Get-Content $filePath -Encoding UTF8
$ns = New-Object System.Xml.XmlNamespaceManager($myXML.NameTable)
$ns.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
New-Item -path $deletedpath -type file
Add-Content -path $deletedpath -Value "No-Beacon Check ... "
Add-Content -path $deletedpath -Value "[ ]"
#delete grid if no beacon, then if no wheels, rotor, piston pieces.
$nodes = $myXML.SelectNodes("//SectorObjects/MyObjectBuilder_EntityBase[(@xsi:type='MyObjectBuilder_CubeGrid')]" , $ns)
ForEach($node in $nodes){
$randombeacon = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[(@xsi:type='MyObjectBuilder_Beacon')]/Owner" , $ns)
$beaconcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_Beacon']", $ns).count
IF($beaconcount -eq 0){
$ignoretotal = 0
$rotorcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_MotorRotor']", $ns).count
$pistoncount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_PistonTop']", $ns).count
$wheelcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_Wheel']", $ns).count
$advrotorcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_MotorAdvancedRotor']", $ns).count
$ignoretotal = $ignoretotal + $rotorcount + $pistoncount + $wheelcount + $advrotorcount
IF($ignoretotal -eq 0){
Add-Content -path $deletedpath -Value "[$($node.DisplayName)] Deleted for no beacons"
Add-Content -path $deletedpath -Value "[ ]"
$node.ParentNode.RemoveChild($node)
}
}
#remove the <# and #> at the top and bottom of this section to enable requiring beacons to be owned.
<#
ElseIf(($randombeacon|Get-Random) -eq $null){
$ignoretotal = 0
$rotorcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_MotorRotor']", $ns)
$pistoncount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_PistonTop']", $ns)
$wheelcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_Wheel']", $ns)
$advrotorcount = $node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock[@xsi:type='MyObjectBuilder_MotorAdvancedRotor']", $ns)
$ignoretotal = $ignoretotal + $rotorcount.count + $pistoncount.count + $wheelcount.count + $advrotorcount.count
IF($ignoretotal -eq 0){
Write-Host -ForegroundColor Green "[$($node.DisplayName)] Deleted for no beacon owner"
Add-Content -path $deletedpath -Value "[$($node.DisplayName)] Deleted for no beacon owner"
Add-Content -path $deletedpath -Value "[ ]"
$node.ParentNode.RemoveChild($node)
}
}
#>
}
$myXML.Save($filePath)