-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OK: | ||
1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OK: | ||
0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OK: | ||
0 |
58 changes: 58 additions & 0 deletions
58
Examples/Public/Remove-ePOComputer/References/Computer1.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
OK: | ||
[ | ||
{ | ||
"EPOComputerProperties.ParentID": 12345, | ||
"EPOComputerProperties.ComputerName": "Computer1", | ||
"EPOComputerProperties.Description": null, | ||
"EPOComputerProperties.SystemDescription": "N/A", | ||
"EPOComputerProperties.TimeZone": "Central Standard Time", | ||
"EPOComputerProperties.DefaultLangID": "0409", | ||
"EPOComputerProperties.UserName": "Username1", | ||
"EPOComputerProperties.DomainName": "Domain", | ||
"EPOComputerProperties.IPHostName": "Computer1.domain.com", | ||
"EPOComputerProperties.IPV6": "0:0:0:0:0:FFFF:A78:21F1", | ||
"EPOComputerProperties.IPAddress": "10.120.45.123", | ||
"EPOComputerProperties.IPSubnet": "0:0:0:0:0:FFFF:A78:2100", | ||
"EPOComputerProperties.IPSubnetMask": "0:0:0:0:0:FFFF:FFFF:FF00", | ||
"EPOComputerProperties.IPV4x": -1971838479, | ||
"EPOComputerProperties.IPXAddress": "N/A", | ||
"EPOComputerProperties.SubnetAddress": "", | ||
"EPOComputerProperties.SubnetMask": "", | ||
"EPOComputerProperties.NetAddress": "509A4C567EBB", | ||
"EPOComputerProperties.OSType": "Windows 10", | ||
"EPOComputerProperties.OSVersion": "10.0", | ||
"EPOComputerProperties.OSServicePackVer": "", | ||
"EPOComputerProperties.OSBuildNum": 16299, | ||
"EPOComputerProperties.OSPlatform": "Workstation", | ||
"EPOComputerProperties.OSOEMID": "00329-00000-00003-AA862", | ||
"EPOComputerProperties.CPUType": "Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz", | ||
"EPOComputerProperties.CPUSpeed": 3600, | ||
"EPOComputerProperties.NumOfCPU": 8, | ||
"EPOComputerProperties.CPUSerialNum": "N/A", | ||
"EPOComputerProperties.TotalPhysicalMemory": 34237841408, | ||
"EPOComputerProperties.FreeMemory": 6870249472, | ||
"EPOComputerProperties.FreeDiskSpace": 413878, | ||
"EPOComputerProperties.TotalDiskSpace": 720157, | ||
"EPOComputerProperties.IsPortable": 0, | ||
"EPOComputerProperties.Vdi": 0, | ||
"EPOComputerProperties.OSBitMode": 1, | ||
"EPOComputerProperties.LastAgentHandler": 2, | ||
"EPOComputerProperties.UserProperty1": "", | ||
"EPOComputerProperties.UserProperty2": "", | ||
"EPOComputerProperties.UserProperty3": "", | ||
"EPOComputerProperties.UserProperty4": "", | ||
"EPOComputerProperties.UserProperty5": "", | ||
"EPOComputerProperties.UserProperty6": "", | ||
"EPOComputerProperties.UserProperty7": "", | ||
"EPOComputerProperties.UserProperty8": "", | ||
"EPOComputerProperties.SysvolFreeSpace": 36732, | ||
"EPOComputerProperties.SysvolTotalSpace": 243219, | ||
"EPOLeafNode.Tags": "Windows, Workstation, Tag4", | ||
"EPOLeafNode.ExcludedTags": "", | ||
"EPOLeafNode.LastUpdate": "2018-08-08T08:40:23-05:00", | ||
"EPOLeafNode.ManagedState": 1, | ||
"EPOLeafNode.AgentGUID": "20f1477f-ff4d-4c6f-915d-9984d25fd65b", | ||
"EPOLeafNode.AgentVersion": "5.0.6.220", | ||
"EPOBranchNode.AutoID": 2 | ||
} | ||
] |
Binary file not shown.
58 changes: 58 additions & 0 deletions
58
Examples/Public/Remove-ePOComputer/References/Computer3.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
OK: | ||
[ | ||
{ | ||
"EPOComputerProperties.ParentID": 12321, | ||
"EPOComputerProperties.ComputerName": "Computer3", | ||
"EPOComputerProperties.Description": null, | ||
"EPOComputerProperties.SystemDescription": "N/A", | ||
"EPOComputerProperties.TimeZone": "Central Standard Time", | ||
"EPOComputerProperties.DefaultLangID": "0409", | ||
"EPOComputerProperties.UserName": "Username3", | ||
"EPOComputerProperties.DomainName": "Domain", | ||
"EPOComputerProperties.IPHostName": "Computer3.domain.com", | ||
"EPOComputerProperties.IPV6": "0:0:0:0:0:FFFF:A78:21F1", | ||
"EPOComputerProperties.IPAddress": "10.120.45.125", | ||
"EPOComputerProperties.IPSubnet": "0:0:0:0:0:FFFF:A78:2100", | ||
"EPOComputerProperties.IPSubnetMask": "0:0:0:0:0:FFFF:FFFF:FF00", | ||
"EPOComputerProperties.IPV4x": -1971838479, | ||
"EPOComputerProperties.IPXAddress": "N/A", | ||
"EPOComputerProperties.SubnetAddress": "", | ||
"EPOComputerProperties.SubnetMask": "", | ||
"EPOComputerProperties.NetAddress": "509A4C567EA9", | ||
"EPOComputerProperties.OSType": "Windows 10", | ||
"EPOComputerProperties.OSVersion": "10.0", | ||
"EPOComputerProperties.OSServicePackVer": "", | ||
"EPOComputerProperties.OSBuildNum": 16299, | ||
"EPOComputerProperties.OSPlatform": "Workstation", | ||
"EPOComputerProperties.OSOEMID": "00329-00000-00003-AA862", | ||
"EPOComputerProperties.CPUType": "Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz", | ||
"EPOComputerProperties.CPUSpeed": 3600, | ||
"EPOComputerProperties.NumOfCPU": 8, | ||
"EPOComputerProperties.CPUSerialNum": "N/A", | ||
"EPOComputerProperties.TotalPhysicalMemory": 34237841408, | ||
"EPOComputerProperties.FreeMemory": 6870249472, | ||
"EPOComputerProperties.FreeDiskSpace": 413878, | ||
"EPOComputerProperties.TotalDiskSpace": 720157, | ||
"EPOComputerProperties.IsPortable": 0, | ||
"EPOComputerProperties.Vdi": 0, | ||
"EPOComputerProperties.OSBitMode": 1, | ||
"EPOComputerProperties.LastAgentHandler": 2, | ||
"EPOComputerProperties.UserProperty1": "", | ||
"EPOComputerProperties.UserProperty2": "", | ||
"EPOComputerProperties.UserProperty3": "", | ||
"EPOComputerProperties.UserProperty4": "", | ||
"EPOComputerProperties.UserProperty5": "", | ||
"EPOComputerProperties.UserProperty6": "", | ||
"EPOComputerProperties.UserProperty7": "", | ||
"EPOComputerProperties.UserProperty8": "", | ||
"EPOComputerProperties.SysvolFreeSpace": 36732, | ||
"EPOComputerProperties.SysvolTotalSpace": 243219, | ||
"EPOLeafNode.Tags": "Windows, Workstation", | ||
"EPOLeafNode.ExcludedTags": "", | ||
"EPOLeafNode.LastUpdate": "2018-08-08T08:40:23-05:00", | ||
"EPOLeafNode.ManagedState": 1, | ||
"EPOLeafNode.AgentGUID": "69aba147-7c36-419f-858d-98e724dad78c", | ||
"EPOLeafNode.AgentVersion": "5.0.6.220", | ||
"EPOBranchNode.AutoID": 2 | ||
} | ||
] |
8 changes: 8 additions & 0 deletions
8
Examples/Public/Remove-ePOComputer/Remove-ePOComputer.Deletes One Computer.psd1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@{ | ||
Parameters = @{ | ||
ComputerName = 'Computer1' | ||
} | ||
Output = @{ | ||
Type = 'System.Void' | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Examples/Public/Remove-ePOComputer/Remove-ePOComputer.Deletes Two Computers.psd1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@{ | ||
Parameters = @{ | ||
ComputerName = @( | ||
'Computer1', | ||
'Computer2' | ||
) | ||
} | ||
Output = @{ | ||
Type = 'System.Void' | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Examples/Public/Remove-ePOComputer/Remove-ePOComputer.Fails To Delete One Computer.psd1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@{ | ||
Parameters = @{ | ||
ComputerName = 'Computer3' | ||
} | ||
Output = @{ | ||
Throws = $True | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
[System.String] $ProjectDirectoryName = 'ePOwerShell' | ||
[System.String] $FunctionType = 'Public' | ||
[IO.FileInfo] $PesterFile = [IO.FileInfo] ([System.String] (Resolve-Path -Path $MyInvocation.MyCommand.Path)) | ||
[System.String] $FunctionName = $PesterFile.Name.Split('.')[0] | ||
[IO.DirectoryInfo] $ProjectRoot = Split-Path -Parent $PesterFile.Directory | ||
|
||
while (-not ($ProjectRoot.Name -eq $ProjectDirectoryName)) { | ||
$ProjectRoot = Split-Path -Parent $ProjectRoot.FullName | ||
} | ||
|
||
[IO.DirectoryInfo] $ExampleDirectory = Join-Path (Join-Path -Path $ProjectRoot -ChildPath 'Examples' -Resolve) -ChildPath $FunctionType -Resolve | ||
[IO.DirectoryInfo] $ExampleDirectory = Join-Path $ExampleDirectory.FullName -ChildPath $FunctionName -Resolve | ||
[IO.DirectoryInfo] $Global:ReferenceDirectory = Join-Path $ExampleDirectory.FullName -ChildPath 'References' -Resolve | ||
|
||
$Examples = Get-ChildItem $ExampleDirectory -Filter "*.psd1" -File | ||
|
||
$Tests = foreach ($Example in $Examples) { | ||
[hashtable] $Test = @{ | ||
Name = $Example.BaseName.Split('.')[1] | ||
} | ||
|
||
Write-Verbose "Test: $($Test | ConvertTo-Json)" | ||
|
||
foreach ($ExampleData in (Import-PowerShellDataFile -LiteralPath $Example.FullName).GetEnumerator()) { | ||
$Test.Add($ExampleData.Name, $ExampleData.Value) | Out-Null | ||
} | ||
|
||
Write-Verbose "Test: $($Test | ConvertTo-Json)" | ||
Write-Output $Test | ||
} | ||
|
||
Describe $FunctionName { | ||
foreach ($Global:Test in $Tests) { | ||
InModuleScope ePOwerShell { | ||
Mock Invoke-ePORequest { | ||
if (-not ($ResultsFile = Get-ChildItem $ReferenceDirectory.FullName -Filter ('{0}.html' -f $Query.ids))) { | ||
Throw "Error 1: Invalid computername" | ||
} | ||
|
||
$Results = (Get-Content $ResultsFile.FullName | Out-String).Substring(3).Trim() | ConvertFrom-Json | ||
Write-Output $Results | ||
} | ||
|
||
Mock Get-ePOComputer { | ||
if (-not ($ComputerFile = Get-ChildItem $ReferenceDirectory.FullName -Filter ('{0}.html' -f $Computer))) { | ||
Throw "Error 1: Invalid computername" | ||
} | ||
|
||
$Computer = ConvertTo-ePOComputer ((Get-Content $ComputerFile.FullName | Out-String).Substring(3).Trim() | ConvertFrom-Json) | ||
Write-Output $Computer | ||
} | ||
|
||
Mock Write-Warning { | ||
Write-Debug $Message | ||
} | ||
|
||
Mock Write-Error { | ||
Throw $Message | ||
} | ||
|
||
Remove-Variable -Scope 'Script' -Name 'RequestResponse' -Force -ErrorAction SilentlyContinue | ||
|
||
Context $Test.Name { | ||
[hashtable] $parameters = $Test.Parameters | ||
|
||
if ($Test.Output.Throws) { | ||
It "Remove-ePOComputer Throws" { | ||
{ $script:RequestResponse = Remove-ePOComputer @parameters -Confirm:$False} | Should Throw | ||
} | ||
continue | ||
} | ||
|
||
It "Remove-ePOComputer" { | ||
{ $script:RequestResponse = Remove-ePOComputer @parameters -Confirm:$False } | Should Not Throw | ||
} | ||
|
||
It "Output Type: $($Test.Output.Type)" { | ||
$script:RequestResponse | Should BeNullOrEmpty | ||
} | ||
} | ||
} | ||
} | ||
|
||
Remove-Variable -Scope 'Global' -Name 'Test' -Force -ErrorAction SilentlyContinue | ||
Remove-Variable -Scope 'Global' -Name 'ReferenceDirectory' -Force -ErrorAction SilentlyContinue | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<# | ||
.SYNOPSIS | ||
Removes computers managed in ePO | ||
.DESCRIPTION | ||
Using the supplied ComputerName(s), we can remove the computer specified from ePO | ||
.EXAMPLE | ||
Remove-ePOComputer -Computer $Computer | ||
Remove a single tag on a single computer | ||
.EXAMPLE | ||
Remove-ePOComputer -Computer @(Computer1, Computer2) | ||
Remove one tag on two computers | ||
.EXAMPLE | ||
Get-ePOComputer My-Computer123 | Remove-ePOComputer | ||
Remove a single computer through the pipeline | ||
.PARAMETER Computer | ||
Specifies the name of the computer managed by ePO to be removed. This can be provided by: | ||
* An ePOComputer object | ||
* A computer name | ||
This parameter can be provided through the pipeline | ||
.OUTPUTS | ||
None | ||
#> | ||
|
||
function Remove-ePOComputer { | ||
[CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = "High")] | ||
param ( | ||
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)] | ||
[Alias('ComputerName', 'cn', 'Name')] | ||
$Computer | ||
) | ||
|
||
begin { | ||
try { | ||
$Request = @{ | ||
Name = 'system.delete' | ||
Query = @{ | ||
ids = '' | ||
} | ||
} | ||
} catch { | ||
Write-Information $_ -Tags Exception | ||
Throw $_ | ||
} | ||
} | ||
|
||
process { | ||
try { | ||
foreach ($Comp in $Computer) { | ||
if ($Comp -is [ePOComputer]) { | ||
Write-Debug ('Specified computer is an ePOComputer: -f {0}' -f $Comp) | ||
} else { | ||
Write-Debug ('Specified computer is a string: -f {0}' -f $Comp) | ||
$Comp = Get-ePOComputer $Comp | ||
} | ||
|
||
foreach ($C in $Comp) { | ||
Write-Verbose ('Computer Name: {0}' -f $C.ComputerName) | ||
Write-Verbose ('Computer ID: {0}' -f $C.ParentID) | ||
|
||
$Request.Query.ids = $C.ParentID | ||
if ($PSCmdlet.ShouldProcess("Remove ePO computer: $($C.ComputerName)")) { | ||
$Result = Invoke-ePORequest @Request | ||
|
||
if ($Result -eq 0) { | ||
Write-Verbose ('Deleted computer: {0}' -f $C.ComputerName) | ||
} else { | ||
Throw ('Unknown response while deleting computer {0} from ePO: {1}' -f $C.ComputerName, $Result) | ||
} | ||
} | ||
} | ||
} | ||
} catch { | ||
Write-Error $_ | ||
} | ||
} | ||
} |