Skip to content

Commit 3b400ef

Browse files
author
haraldpfirmann
committed
New queries
1 parent 9f536cd commit 3b400ef

13 files changed

Lines changed: 293 additions & 11 deletions

File tree

ActiveDirectory/Users/Get-ADUsersWithDefinedStatus.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ Import-Module ActiveDirectory
8787
try{
8888
$resultMessage = @()
8989

90-
if([System.String]::IsNullOrWhiteSpace($OUPath)){
91-
$OUPath = $Domain.DistinguishedName
92-
}
9390
if($PSCmdlet.ParameterSetName -eq "Remote Jumphost"){
9491
if([System.String]::IsNullOrWhiteSpace($DomainName)){
9592
$Domain = Get-ADDomain -Current LocalComputer -AuthType $AuthType -Credential $DomainAccount -ErrorAction Stop

ActiveDirectory/_LIB_/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Library scripts for Active Directory
2+
3+
> Note: The scripts must be stored in a folder named \_LIB_ to use them as library scripts
4+
> <br>The use of the scripts requires the PowerShell Module ActiveDirectory.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#Requires -Version 4.0
2+
#Requires -Modules ActiveDirectory
3+
4+
<#
5+
.SYNOPSIS
6+
Lists the users below the ou
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, AppSphere AG assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of AppSphere AG.
16+
© AppSphere AG
17+
18+
.COMPONENT
19+
Requires Module ActiveDirectory
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/tree/master/ActiveDirectory/_QUERY_
23+
24+
.Parameter OUPath
25+
Specifies the AD path
26+
27+
.Parameter UserName
28+
Specifies the SamAccountName of the users, use * to represent any series of characters, is the parameter empty all users retrieved
29+
30+
.Parameter DomainAccount
31+
Active Directory Credential
32+
33+
.Parameter DomainName
34+
Name of Active Directory Domain
35+
36+
.Parameter SearchScope
37+
Specifies the scope of an Active Directory search
38+
39+
.Parameter AuthType
40+
Specifies the authentication method to use
41+
#>
42+
43+
param(
44+
[Parameter(Mandatory = $true)]
45+
[string]$OUPath,
46+
[string]$SamAccountName,
47+
[PSCredential]$DomainAccount,
48+
[string]$DomainName,
49+
[ValidateSet('Base','OneLevel','SubTree')]
50+
[string]$SearchScope='SubTree',
51+
[ValidateSet('Basic', 'Negotiate')]
52+
[string]$AuthType="Negotiate"
53+
)
54+
55+
Import-Module ActiveDirectory
56+
57+
try{
58+
$Script:users = @()
59+
if([System.String]::IsNullOrWhiteSpace($SamAccountName)){
60+
$SamAccountName = "*"
61+
}
62+
if($null -ne $DomainAccount){
63+
if([System.String]::IsNullOrWhiteSpace($DomainName)){
64+
$Domain = Get-ADDomain -Current LocalComputer -AuthType $AuthType -Credential $DomainAccount -ErrorAction Stop
65+
}
66+
else{
67+
$Domain = Get-ADDomain -Identity $DomainName -AuthType $AuthType -Credential $DomainAccount -ErrorAction Stop
68+
}
69+
if([System.String]::IsNullOrWhiteSpace($OUPath)){
70+
$OUPath = $Domain.DistinguishedName
71+
}
72+
$Script:users += Get-ADUser -Server $Domain.PDCEmulator -Credential $DomainAccount -AuthType $AuthType -Filter {SamAccountName -like $SamAccountName} `
73+
-SearchBase $OUPath -SearchScope $SearchScope -Properties DistinguishedName, DisplayName, SamAccountName | Sort-Object -Property DisplayName
74+
}
75+
else{
76+
if([System.String]::IsNullOrWhiteSpace($DomainName)){
77+
$Domain = Get-ADDomain -Current LocalComputer -AuthType $AuthType -ErrorAction Stop
78+
}
79+
else{
80+
$Domain = Get-ADDomain -Identity $DomainName -AuthType $AuthType -ErrorAction Stop
81+
}
82+
if([System.String]::IsNullOrWhiteSpace($OUPath)){
83+
$OUPath = $Domain.DistinguishedName
84+
}
85+
$Script:users += Get-ADUser -Server $Domain.PDCEmulator -AuthType $AuthType -Filter {SamAccountName -like $SamAccountName} `
86+
-SearchBase $OUPath -SearchScope $SearchScope -Properties DistinguishedName, DisplayName, SamAccountName | Sort-Object -Property DisplayName
87+
}
88+
if($SRXEnv) {
89+
$SRXEnv.ResultList =@()
90+
$SRXEnv.ResultList2 =@()
91+
}
92+
if($null -ne $Script:users){
93+
foreach($itm in $users){
94+
if($SRXEnv) {
95+
$SRXEnv.ResultList += $itm.DistinguishedName # Value
96+
$SRXEnv.ResultList2 += "$($itm.DisplayName) ($($itm.SamAccountName))" # DisplayValue
97+
}
98+
else{
99+
Write-Output "$($itm.DisplayName) ($($itm.SamAccountName))"
100+
}
101+
}
102+
}
103+
}
104+
catch{
105+
throw
106+
}
107+
finally{
108+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#Requires -Version 4.0
2+
#Requires -Modules ActiveDirectory
3+
4+
<#
5+
.SYNOPSIS
6+
Lists users where disabled, inactive, locked out and/or account is expired
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, AppSphere AG assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of AppSphere AG.
16+
© AppSphere AG
17+
18+
.COMPONENT
19+
Requires Module ActiveDirectory
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/tree/master/ActiveDirectory/_QUERY_
23+
24+
.Parameter OUPath
25+
Specifies the AD path
26+
27+
.Parameter DomainAccount
28+
Active Directory Credential
29+
30+
.Parameter Disabled
31+
Show the users where account disabled
32+
33+
.Parameter InActive
34+
Show the users where account inactive
35+
36+
.Parameter Locked
37+
Show the users where account locked
38+
39+
.Parameter Expired
40+
Show the users where account expired
41+
42+
.Parameter DomainName
43+
Name of Active Directory Domain
44+
45+
.Parameter SearchScope
46+
Specifies the scope of an Active Directory search
47+
48+
.Parameter AuthType
49+
Specifies the authentication method to use
50+
#>
51+
52+
param(
53+
[Parameter(Mandatory = $true)]
54+
[string]$OUPath,
55+
[PSCredential]$DomainAccount,
56+
[bool]$Disabled,
57+
[bool]$InActive,
58+
[bool]$Locked,
59+
[bool]$Expired,
60+
[string]$DomainName,
61+
[ValidateSet('Base','OneLevel','SubTree')]
62+
[string]$SearchScope='SubTree',
63+
[ValidateSet('Basic', 'Negotiate')]
64+
[string]$AuthType="Negotiate"
65+
)
66+
67+
Import-Module ActiveDirectory
68+
69+
try{
70+
$Script:users = @()
71+
if($null -ne $DomainAccount){
72+
if([System.String]::IsNullOrWhiteSpace($DomainName)){
73+
$Domain = Get-ADDomain -Current LocalComputer -AuthType $AuthType -Credential $DomainAccount -ErrorAction Stop
74+
}
75+
else{
76+
$Domain = Get-ADDomain -Identity $DomainName -AuthType $AuthType -Credential $DomainAccount -ErrorAction Stop
77+
}
78+
if([System.String]::IsNullOrWhiteSpace($OUPath)){
79+
$OUPath = $Domain.DistinguishedName
80+
}
81+
if($Disabled -eq $true){
82+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -Credential $DomainAccount -AuthType $AuthType -AccountDisabled -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
83+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
84+
}
85+
if($InActive -eq $true){
86+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -Credential $DomainAccount -AuthType $AuthType -AccountInactive -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
87+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
88+
}
89+
if($Locked -eq $true){
90+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -Credential $DomainAccount -AuthType $AuthType -LockedOut -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
91+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
92+
}
93+
if($Expired -eq $true){
94+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -Credential $DomainAccount -AuthType $AuthType -AccountExpired -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
95+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
96+
}
97+
}
98+
else{
99+
if([System.String]::IsNullOrWhiteSpace($DomainName)){
100+
$Domain = Get-ADDomain -Current LocalComputer -AuthType $AuthType -ErrorAction Stop
101+
}
102+
else{
103+
$Domain = Get-ADDomain -Identity $DomainName -AuthType $AuthType -ErrorAction Stop
104+
}
105+
if([System.String]::IsNullOrWhiteSpace($OUPath)){
106+
$OUPath = $Domain.DistinguishedName
107+
}
108+
if($Disabled -eq $true){
109+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -AuthType $AuthType -AccountDisabled -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
110+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
111+
}
112+
if($InActive -eq $true){
113+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -AuthType $AuthType -AccountInactive -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
114+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
115+
}
116+
if($Locked -eq $true){
117+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -AuthType $AuthType -LockedOut -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
118+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
119+
}
120+
if($Expired -eq $true){
121+
$Script:users += Search-ADAccount -Server $Domain.PDCEmulator -AuthType $AuthType -AccountExpired -UsersOnly -SearchBase $OUPath -SearchScope $SearchScope `
122+
| Select-Object DistinguishedName, SamAccountName | Sort-Object -Property SamAccountName
123+
}
124+
}
125+
if($SRXEnv) {
126+
$SRXEnv.ResultList =@()
127+
$SRXEnv.ResultList2 =@()
128+
}
129+
if($null -ne $Script:users){
130+
foreach($itm in $users){
131+
if($SRXEnv) {
132+
$SRXEnv.ResultList += $itm.DistinguishedName # Value
133+
$SRXEnv.ResultList2 += $itm.SamAccountName # DisplayValue
134+
}
135+
else{
136+
Write-Output $itm.SamAccountName
137+
}
138+
}
139+
}
140+
}
141+
catch{
142+
throw
143+
}
144+
finally{
145+
}

ActiveDirectory/_QUERY_/readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Queries
2+
3+
> Note: The scripts must be stored in a folder named \_QUERY_ to use them as queries
4+
><br>The use of the scripts requires the PowerShell Module ActiveDirectory
5+
6+
+ [QUY_Get-ADUsers.ps1](./QUY_Get-ADUsers.ps1)
7+
8+
Lists the users below the ou
9+
10+
+ [QUY_Get-ADUsersWithDefinedStatus.ps1](./QUY_Get-ADUsersWithDefinedStatus.ps1)
11+
12+
Lists users where disabled, inactive, locked out and/or account is expired

Hyper-V/_LIB_/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Library scripts for Microsoft Hyper-V
2+
3+
> Note: The scripts must be stored in a folder named \_LIB_ to use them as library scripts
4+
> <br>The use of the scripts requires the PowerShell Module Hyper-V.

Hyper-V/_QUERY_/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Queries
22

33
> Note: The scripts must be stored in a folder named \_QUERY_ to use them as queries
4+
< <br>The use of the scripts requires the PowerShell Module Hyper-V
45
56
+ [QUY_Get-MSHVVirtualMachineDrives.ps1](./QUY_Get-MSHVVirtualMachineDrives.ps1)
67

VMware/_LIB_/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Library scripts for VMware
2+
3+
> Note: The scripts must be stored in a folder named \_LIB_ to use them as library scripts
4+
> <br>The use of the scripts requires the PowerShell Module VMware.PowerCLI.

WinPrintManagement/Printers/Get-PrtMPrinters.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ try{
5252
else {
5353
$Script:Cim =New-CimSession -ComputerName $ComputerName -Credential $AccessAccount -ErrorAction Stop
5454
}
55-
$Script:Printers=Get-Printer -Full -CimSession $Script:Cim -ComputerName $ComputerName | Where-Object {$_.Type -eq 'Local'} `
55+
$Script:Printers = Get-Printer -Full -CimSession $Script:Cim -ComputerName $ComputerName | Where-Object {$_.Type -eq 'Local'} `
5656
| Select-Object Name,DriverName,PortName,Shared,Sharename,Comment,Location,Datatype,PrintProcessor,RenderingMode `
5757
| Sort-Object Name
5858
$Script:Csv=@()

WinPrintManagement/_LIB_/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Library scripts for Windows Print Management
2+
3+
> Note: The scripts must be stored in a folder named \_LIB_ to use them as library scripts
4+
> <br>The use of the scripts requires the PowerShell Module PrintManagement.

0 commit comments

Comments
 (0)