Skip to content

Instantly share code, notes, and snippets.

View kevinblumenfeld's full-sized avatar
🎯
Focusing

Kevin Blumenfeld kevinblumenfeld

🎯
Focusing
View GitHub Profile
$params = @{
SearchBase = (Get-ADDomain).DistinguishedName
Filter = { proxyAddresses -like '*' }
Properties = 'Displayname',
'SamAccountName',
'UserPrincipalName',
'ProxyAddresses',
'DistinguishedName'
}
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -EA SilentlyContinue
Set-AdServerSettings -ViewEntireForest $true
$OutFile = ".\Exchange_Permission_Export.csv"
"DisplayName" + "!" + "Alias" + "!" + "OU" + "!" + "PrimarySMTP" + "!" + "FullAccess" + "!" + "SendAs" + "!" + "SendonBehalf" | Out-File $OutFile -Force -encoding ascii
# $Mailboxes = import-csv .\perms.csv
$Mailboxes = Get-Mailbox -ResultSize:Unlimited | Select DistinguishedName, UserPrincipalName, DisplayName, Alias,
@{n = "OU" ; e = {$_.Distinguishedname | ForEach-Object {($_ -split '(OU=)', 2)[1, 2] -join ''}}}
ForEach ($Mailbox in $Mailboxes) {
Write-Output "Mailbox: $($Mailbox.UserPrincipalName)"
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -EA SilentlyContinue
Set-AdServerSettings -ViewEntireForest $true
$OutFile = ".\Exchange_Permission_Export.csv"
"DisplayName" + "!" + "Alias" + "!" + "OU" + "!" + "PrimarySMTP" + "!" + "FullAccess" + "!" + "SendAs" + "!" + "SendonBehalf" | Out-File $OutFile -Force -encoding ascii
# $Mailboxes = import-csv .\perms.csv
$Mailboxes = Get-Mailbox -ResultSize:Unlimited | Select DistinguishedName, UserPrincipalName, DisplayName, Alias,
@{n = "OU" ; e = {$_.Distinguishedname | ForEach-Object {($_ -split '(OU=)', 2)[1, 2] -join ''}}}
ForEach ($Mailbox in $Mailboxes) {
Write-Output "Mailbox: $($Mailbox.UserPrincipalName)"
Get-Mailbox : Cannot bind parameter 'Identity'. Cannot convert value "" to type
"Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Parameter values of type
Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter can't be empty. Specify a value, and try again.
Parameter name: identity"
At C:\scripts\Get_Mailbox_Permissions.Exchange2.ps1:15 char:69
+ ... Fullaccess = (($FullAccess).split("!!") | % {((get-mailbox $_).Displa ...
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Get-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
function ConvertTo-DistinguishedName {
[CmdletBinding()]
[OutputType([string])]
Param
(
# e.g. 'corp.ad.contoso.com/CORP/USERS/Person'
[Parameter(Mandatory = $true,
Position = 0)]
[ValidateNotNullOrEmpty()]
# must be at least a.b/w - no single character domain or missing path
Get-ADUser -Filter 'proxyaddresses -ne "$null"' -ResultSetSize $null -Properties DisplayName, samaccountname, UserPrincipalName, proxyAddresses, Distinguishedname -searchBase "DC=CONTOSO,DC=local" |
select DisplayName, samaccountname, UserPrincipalName,
@{n = "OU" ; e = {$_.Distinguishedname | ForEach-Object {($_ -split '(OU=)',2)[1,2] -join ''}}},
@{n = "PrimarySMTP" ; e = {( $_.proxyAddresses | ? {$_ -cmatch "SMTP:*"}).Substring(5) -join ";" }},
@{n = "smtp" ; e = {( $_.proxyAddresses | ? {$_ -cmatch "smtp:*"}).Substring(5) -join ";" }},
@{n = "x500" ; e = {( $_.proxyAddresses | ? {$_ -match "x500:*"}).Substring(0) -join ";" }},
@{n = "SIP" ; e = {( $_.proxyAddresses | ? {$_ -match "SIP:*"}).Substring(4) -join ";" }} |
Export-Csv ADUsers.csv -NTI
Param (
[Parameter(Mandatory = $True)]
$givenname,
[Parameter(Mandatory = $True)]
$surname,
[Parameter(Mandatory = $True)]
$template,
[Parameter(Mandatory = $False)]
$password = "contoso2830!!",
Param (
[Parameter(Mandatory = $True)]
$givenname,
[Parameter(Mandatory = $True)]
$surname,
[Parameter(Mandatory = $False)]
$storeNum,
[Parameter(Mandatory = $False)]
$mobile,
Function Sync-ADConnect {
Param (
[Parameter(Mandatory = $False)]
[switch] $Initial,
[Parameter(Mandatory = $False)]
$aadComputer = "se-c-ac01.corp.ad.sentara1.com"
)
<#
.SYNOPSIS
$i = 1
while (get-aduser -LDAPfilter "(userprincipalname=$userprincipalname)") {
$FirstName = $FirstName + $i
$userprincipalname = $LastName.replace(" ", "") + "-" + $FirstName.replace(" ", "") + "@" + $PsBoundParameters[$ParamName_emaildomain]
$i++
}
$name = $LastName + ", " + $FirstName