Skip to content

Commit 469df2a

Browse files
committed
2 parents 5780c80 + 0d4cba8 commit 469df2a

File tree

6 files changed

+252
-22
lines changed

6 files changed

+252
-22
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
function Get-SCCMUserCollectionDeployment
2+
{
3+
<#
4+
.SYNOPSIS
5+
Function to retrieve a User's collection deployment
6+
7+
.DESCRIPTION
8+
Function to retrieve a User's collection deployment
9+
The function will first retrieve all the collection where the user is member of and
10+
find deployments advertised on those.
11+
12+
The final output will include user, collection and deployment information.
13+
14+
.PARAMETER Username
15+
Specifies the SamAccountName of the user.
16+
The user must be present in the SCCM CMDB
17+
18+
.PARAMETER SiteCode
19+
Specifies the SCCM SiteCode
20+
21+
.PARAMETER ComputerName
22+
Specifies the SCCM Server to query
23+
24+
.PARAMETER Credential
25+
Specifies the credential to use to query the SCCM Server.
26+
Default will take the current user credentials
27+
28+
.PARAMETER Purpose
29+
Specifies a specific deployment intent.
30+
Possible value: Available or Required.
31+
Default is Null (get all)
32+
33+
.EXAMPLE
34+
Get-SCCMUserTargetedApplication -UserName TestUser -Credential $cred -Purpose Required
35+
36+
.NOTES
37+
Francois-Xavier cat
38+
www.lazywinadmin.com
39+
@lazywinadm
40+
41+
SMS_R_User: https://msdn.microsoft.com/en-us/library/hh949577.aspx
42+
SMS_Collection: https://msdn.microsoft.com/en-us/library/hh948939.aspx
43+
SMS_DeploymentInfo: https://msdn.microsoft.com/en-us/library/hh948268.aspx
44+
#>
45+
46+
[CmdletBinding()]
47+
PARAM
48+
(
49+
[Parameter(Mandatory)]
50+
[Alias('SamAccountName')]
51+
$UserName,
52+
53+
[Parameter(Mandatory)]
54+
$SiteCode,
55+
56+
[Parameter(Mandatory)]
57+
$ComputerName,
58+
59+
[Alias('RunAs')]
60+
[System.Management.Automation.Credential()]
61+
$Credential = [System.Management.Automation.PSCredential]::Empty,
62+
63+
[ValidateSet('Required', 'Available')]
64+
$Purpose
65+
)
66+
67+
BEGIN
68+
{
69+
# Verify if the username contains the domain name
70+
# If it does... remove the domain name
71+
# Example: "FX\TestUser" will become "TestUser"
72+
if ($UserName -like '*\*') { $UserName = ($UserName -split '\\')[1] }
73+
74+
# Define default properties
75+
$Splatting = @{
76+
ComputerName = $ComputerName
77+
NameSpace = "root\SMS\Site_$SiteCode"
78+
}
79+
80+
IF ($PSBoundParameters['Credential'])
81+
{
82+
$Splatting.Credential = $Credential
83+
}
84+
85+
Switch ($Purpose)
86+
{
87+
"Required" { $DeploymentIntent = 0 }
88+
"Available" { $DeploymentIntent = 2 }
89+
default { $DeploymentIntent = "NA" }
90+
}
91+
92+
}
93+
PROCESS
94+
{
95+
# Find the User in SCCM CMDB
96+
$User = Get-WMIObject @Splatting -Query "Select * From SMS_R_User WHERE UserName='$UserName'"
97+
98+
# Find the collections where the user is member of
99+
Get-WmiObject -Class sms_fullcollectionmembership @splatting -Filter "ResourceID = '$($user.resourceid)'" |
100+
ForEach-Object {
101+
102+
# Retrieve the collection of the user
103+
$Collections = Get-WmiObject @splatting -Query "Select * From SMS_Collection WHERE CollectionID='$($_.Collectionid)'"
104+
105+
106+
# Retrieve the deployments (advertisement) of each collections
107+
Foreach ($Collection in $collections)
108+
{
109+
IF ($DeploymentIntent -eq 'NA')
110+
{
111+
# Find the Deployment on one collection
112+
$Deployments = (Get-WmiObject @splatting -Query "Select * From SMS_DeploymentInfo WHERE CollectionID='$($Collection.CollectionID)'")
113+
}
114+
ELSE
115+
{
116+
$Deployments = (Get-WmiObject @splatting -Query "Select * From SMS_DeploymentInfo WHERE CollectionID='$($Collection.CollectionID)' AND DeploymentIntent='$DeploymentIntent'")
117+
}
118+
119+
Foreach ($Deploy in $Deployments)
120+
{
121+
122+
# Prepare Output
123+
$Properties = @{
124+
UserName = $UserName
125+
ComputerName = $ComputerName
126+
CollectionName = $Deploy.CollectionName
127+
CollectionID = $Deploy.CollectionID
128+
DeploymentID = $Deploy.DeploymentID
129+
DeploymentName = $Deploy.DeploymentName
130+
DeploymentIntent = $deploy.DeploymentIntent
131+
TargetName = $Deploy.TargetName
132+
TargetSubName = $Deploy.TargetSubname
133+
134+
}
135+
136+
# Output the current Object
137+
New-Object -TypeName PSObject -prop $Properties
138+
}
139+
}
140+
}
141+
}
142+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function Get-LocalAdministratorBuiltin
2+
{
3+
<#
4+
.SYNOPSIS
5+
function to retrieve the local Administrator account
6+
7+
.DESCRIPTION
8+
function to retrieve the local Administrator account
9+
10+
.PARAMETER ComputerName
11+
Specifies the computername
12+
13+
.EXAMPLE
14+
PS C:\> Get-LocalAdministratorBuiltin
15+
16+
.EXAMPLE
17+
PS C:\> Get-LocalAdministratorBuiltin -ComputerName SERVER01
18+
19+
.NOTES
20+
Francois-Xavier Cat
21+
www.lazywinadmin.com
22+
@lazywinadm
23+
24+
#function to get the BUILTIN LocalAdministrator
25+
#http://blog.simonw.se/powershell-find-builtin-local-administrator-account/
26+
#>
27+
28+
[CmdletBinding()]
29+
param (
30+
[Parameter()]
31+
$ComputerName = $env:computername
32+
)
33+
Process
34+
{
35+
Foreach ($Computer in $ComputerName)
36+
{
37+
Try
38+
{
39+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
40+
$PrincipalContext = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine, $Computer)
41+
$UserPrincipal = New-Object -TypeName System.DirectoryServices.AccountManagement.UserPrincipal($PrincipalContext)
42+
$Searcher = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalSearcher
43+
$Searcher.QueryFilter = $UserPrincipal
44+
$Searcher.FindAll() | Where-Object { $_.Sid -Like "*-500" }
45+
}
46+
Catch
47+
{
48+
Write-Warning -Message "$($_.Exception.Message)"
49+
}
50+
}
51+
}
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function Remove-StringLatinCharacters
2+
{
3+
#http://www.lazywinadmin.com/2015/05/powershell-remove-diacritics-accents.html
4+
#Method 2 (From Marcin Krzanowicz)
5+
PARAM ([string]$String)
6+
[Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($String))
7+
}

TOOL-Remove-StringSpecialCharacter/Remove-StringSpecialCharacter.ps1

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
77
.DESCRIPTION
88
This function will remove the special character from a string.
9-
I am using the regular expression "\w" which means "any word character"
10-
which usually means alphanumeric (letters, numbers, regardless of case) plus underscore (_)
9+
I'm using Unicode Regular Expressions with the following categories
10+
\p{L} : any kind of letter from any language.
11+
\p{Nd} : a digit zero through nine in any script except ideographic
12+
13+
http://www.regular-expressions.info/unicode.html
14+
http://unicode.org/reports/tr18/
1115
1216
.PARAMETER String
1317
Specifies the String on which the special character will be removed
@@ -17,17 +21,13 @@
1721
1822
.EXAMPLE
1923
PS C:\> Remove-StringSpecialCharacter -String "^&*@wow*(&(*&@"
20-
2124
wow
22-
2325
.EXAMPLE
2426
PS C:\> Remove-StringSpecialCharacter -String "wow#@!`~)(\|?/}{-_=+*"
2527
26-
wow_
27-
28+
wow
2829
.EXAMPLE
2930
PS C:\> Remove-StringSpecialCharacter -String "wow#@!`~)(\|?/}{-_=+*" -SpecialCharacterToKeep "*","_","-"
30-
3131
wow-_*
3232
3333
.NOTES
@@ -41,24 +41,25 @@
4141
[ValidateNotNullOrEmpty()]
4242
[Alias('Text')]
4343
[System.String]$String,
44-
45-
[Alias("Keep")]
44+
45+
[Alias("Keep")]
4646
[ValidateNotNullOrEmpty()]
4747
[String[]]$SpecialCharacterToKeep
4848
)
4949
PROCESS
50-
{
51-
IF($PSBoundParameters["SpecialCharacterToKeep"])
52-
{
53-
Foreach ($Character in $SpecialCharacterToKeep)
54-
{
55-
$Regex += "[^\w\.$character"
56-
}
57-
58-
$Regex += "]"
59-
} #IF($PSBoundParameters["SpecialCharacterToKeep"])
60-
ELSE {$Regex = "[^\w\.]"}
61-
50+
{
51+
IF ($PSBoundParameters["SpecialCharacterToKeep"])
52+
{
53+
$Regex = "[^\p{L}\p{Nd}"
54+
Foreach ($Character in $SpecialCharacterToKeep)
55+
{
56+
$Regex += "/$character"
57+
}
58+
59+
$Regex += "]+"
60+
} #IF($PSBoundParameters["SpecialCharacterToKeep"])
61+
ELSE { $Regex = "[^\p{L}\p{Nd}]+" }
62+
6263
$String -replace $regex, ""
63-
} #PROCESS
64+
} #PROCESS
6465
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function Set-PowerShellWindowTitle
2+
{
3+
<#
4+
.SYNOPSIS
5+
Function to set the title of the PowerShell Window
6+
7+
.DESCRIPTION
8+
Function to set the title of the PowerShell Window
9+
10+
.PARAMETER Title
11+
Specifies the Title of the PowerShell Window
12+
13+
.EXAMPLE
14+
PS C:\> Set-PowerShellWindowTitle -Title LazyWinAdmin.com
15+
16+
.NOTES
17+
Francois-Xavier Cat
18+
www.lazywinadmin.com
19+
@lazywinadm
20+
#>
21+
PARAM($Title)
22+
$Host.UI.RawUI.WindowTitle = $Title
23+
}
24+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function Test-IsLocalAdministrator
2+
{
3+
return ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
4+
}

0 commit comments

Comments
 (0)