Quantcast
Channel: PowerShell General
Viewing all 10624 articles
Browse latest View live

Setting up link to O365 Tenancy

$
0
0

Hi Guys,

 

i am looking for a way within Powershell Pro (by idera) to setup a connection i can click on to connect me to a specific tenancy in office 365. I work on a number of tenancies and it would be ideal for me to be able to click on a specific icon or link to connect me in to a certain tenancy at a time. I am looking at remoting configurations but not sure of some settings ?

 

Any ideas?

 

Paul. 


implicit remoting remove-inboxrule

$
0
0

Creating a script that will remove users and their homefolders after a certain period, but before deleting they will be disabled and the forwarders to an external email address must be removed.

Before the commands are ran a remote session is created 

If i run Get-Mailbox UserName | Get-InboxRule the following error message appears :
 The operation couldn't be performed because 'Domain\UserName' couldn't be found.
   + CategoryInfo          : NotSpecified: (:) [Get-InboxRule], ManagementObjectNotFoundException
   + FullyQualifiedErrorId : 320F1544,Microsoft.Exchange.Management.RecipientTasks.GetInboxRule

When i run get-inboxrule -mailbox Username | remove-inboxrule it works. However i want to specify an OU with the disabled users instead of modifying a single mailbox

I've tried the command seen below but the same error message appears.

$mailbox = get-mailbox -OrganizationalUnit "OU=Disabled Users,DC=Domain,DC=com" | Get-InboxRule
foreach($usermailbox in $mailbox)
{
get-InboxRule -mailbox $usermailbox

Is it possible to create a remote session and then run the commands that will remove the inboxrules for users in a specific OU?

 

 

Exchange 2010 NDR

$
0
0

I am getting NDR due to contact being synced with my organization that are not compatible with Exchange 2010.  I figured out that it is a version mismatch.  So my idea was to write a script and run it weekly to locate incompatible contacts and upgrade them. 

 

This is the command I wrote to locate the contact:

get-mailcontact -resultsize unlimited | where {$_.ExchangeVersion -eq "0.0 (6.5.6500.0)"} >C:\NDR.CSV

This is my fix for a single user account

get-mailcontact myemail@help.com | set-mailcontact -customattribute1 "Always" -ForceUpgrade -Confirm:$False
get-mailcontact myemail@help.com | set-mailcontact -customattribute1 $null

Of course that does not work for bulk.  So this is what I came up with but I am not for sure.  Unfortunately I am at a point where I am stuck.

$CorruptContact = get-mailcontact -resultsize unlimited | where {$_.ExchangeVersion -eq "0.0 (6.5.6500.0)"}
$CorruptContact | ForEach-Object {set-mailcontact -customattribute1 "Always" -ForceUpgrade -Confirm:$False}
$CorruptContact | ForEach-Object {set-mailcontact -customattribute1 $null}

Any help would be greatly appreciated,
Dennis

Issue with an If statement

$
0
0

Hi Everyone, id love some help with the below script if anyone can shed some light. Im sure its something simple im not looking at. The script emails users in AD whos accounts are expiring within 14 days and sends doco on how to change their passwords. I then wanted to put an IF statement in there which emails me from 7 days with the logs.. Im sure its something basic in the syntax.. i can get it all to work untill the second IF statement.

#Add the Quest PowerShell snapin
Add-PsSnapIn Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
Get-QADUser -SizeLimit 0 | Select-Object samAccountName,mail,PasswordStatus | Where-Object {$_.PasswordStatus -ne "Password never expires" -and $_.PasswordStatus -ne "Expired" -and $_.PasswordStatus -ne "User must change password at next logon." -and $_.mail -ne $null} |
ForEach-Object {
  $today = Get-Date
  $logdate = Get-Date -format yyyyMMdd
  $samaccountname = $_.samAccountName
  $mail = $_.mail
  $passwordstatus = $_.PasswordStatus
  $passwordexpiry = $passwordstatus.Replace("Expires at: ","")
  $passwordexpirydate = Get-Date $passwordexpiry
  $daystoexpiry = ($passwordexpirydate - $today).Days
  $smtpserver = "192.XXX.XXX.6"
  $attachment = "\\test\it$\PWD expiry reports\Updating the password on your Mobile and or Tablet device.docx"
  $emailFrom = "reports@test.com"
  $body = "Please change your password to prevent loss of access to Curwoods Systems. "
  $body += "Attached is the relevant documentation to change the password on your mobile and tablet device. If you are unable to change your password, please submit a  request or contact Help Desk on ext 3333 "
  if ($daystoexpiry -lt 3 ) {
    $emailTo = "$mail"
    $subject = "**PASSWORD CHANGE REMINDER** Your Network password will expire in $daystoexpiry day(s) please change your password."   
    Send-MailMessage -To $emailTo -From $emailFrom -Subject $subject -Body $body -Attachments $attachment -SmtpServer $smtpserver
    Write-Host "Email was sent to $mail on $today"
    Add-Content C:\Windows\SYSVOL\sysvol\test\scripts\Scripts\Password_expiry\Logs\maillog$logdate.txt  "Email was sent to $mail on $today"
  }
}
if ($daystoexpiry -lt 3 ) {
Send-MailMessage -To "ryan@test.com" -From "reports@test.com" -Subject "Password change log for $today" -Body "This is the log from $today" -Attachments "C:\Windows\SYSVOL\sysvol\test\scripts\Scripts\Password_expiry\Logs\maillog$logdate.txt" -SmtpServer $smtpserver   
}

Find if email does not exist

$
0
0

I need to find a way to discover on a nightly basis if an email is not received in an inbox then send an email of it does not exist. The email come in between 7-8 PM MST from an internal host just stating when a job completes. No email is sent if it does not. Can someone point me to an example of how this might be done? The best way I figure is powershell.

Groups in Office365

$
0
0

Hello,

 

I have a AD connect to office 365 with DirSync, perfectly synchronized(Users,Groups...).

Also, inoffice365I createdgroupsdirectly from the platform (No connect with my domain) and when i try get the all groups(Domain + office365 ) not works....

 

My code is

The first  step I connnect to my office 365

$Office365Credentials=Get-Credential 

$Session=New-PSSession-ConfigurationNameMicrosoft.Exchange-ConnectionUrihttps://ps.outlook.com/powershell-Credential$Office365credentials-AuthenticationBasic–AllowRedirection

Import-PSSession$Session-AllowClobber

and in the next step I get the groups

$objDistributionGroups= Get-Group

when I try todisplay this variableonly seedomain groupsbut notcreated in office365.

 

ispossible to seeonlythe groups created in office365?

 

thanks

 

Filter mails by date - user mailbox, exchange 2007

$
0
0

Hi,

I have exchange 2007.

I need to get a report that contain the numbers of emails that the user received from DATE X to DATE Y. 

I need to connect to a user's mailbox and pull out this information, the search need to be in all folders of mailbox.

 

need help with this issue.

 

Thanks,

Lior 

Exchange 2013 Script to remove Resigned Users from all the DL's in organization

$
0
0

Hi,

I am trying to write a script that will do the following tasks:

1) Members of DL named "Resigned" to be removed from all the other DL's in the organization except DL "Resigned".

2) Later I need to disable/remove the users based on their RecipientType.

Complete Details :

Some organizations end up having cluttered distribution lists still populated with

mailboxes belonging to employees who have left the company. One strategy is to put the

email ID's of those employees (mailbox/mail-contacts) to a Distribution List called

“Resigned”. That list contains all non-active employees whose mailboxes have not been

deleted yet.

1) Get All the Distribution Groups from Exchange except DL named "Resigned" in parameter

called $allgroups:

$allgroups=get-distributiongroup -Filter {"DisplayName" -ne "Resigned"}

2) Remove the employees who are listed in the DL named "Resigned" from all other DL's in

Exchange :
  
get-distributiongroupmember "Resigned" | remove-distributiongroupmember $allgroups

3) Since we have the required email ID's already in DL Named "Resigned" we need to

disable/remove them based on their Recipient Type.

If the email ID is  usermailbox then task is to disable the mailbox and if its a

mailcontact task is to remove the contact.


$EmailIDs= get-distributiongroupmember -identity "Resigned" | export-txt

"D:\DL\userlist.txt"
foreach($EmailID in $EmailIDs)
{

If($EmailID -RecipientType -eq "UserMailbox")
{
    get-mailbox $EmailID | Disable-Mailbox $EmailID
}
Else($EmailID -RecipientType -eq "MailContact")
{

    get-mailcontact $EmailID | Remove-MailContact $EmailID
}
}

PowerShell Script :

Till now the powershell script I have reached is as follows:

$allgroups=get-distributiongroup -Filter {"DisplayName" -ne "Resigned"}

get-distributiongroupmember "Resigned" | remove-distributiongroupmember $allgroups

$EmailIDs= get-distributiongroupmember -identity "Resigned" | export-txt

"D:\DL\userlist.txt"
foreach($EmailID in $EmailIDs)
{

If($EmailID -RecipientType -eq "UserMailbox")
{
    get-mailbox $EmailID | Disable-Mailbox $EmailID
}
Else($EmailID -RecipientType -eq "MailContact")
{

    get-mailcontact $EmailID | Remove-MailContact $EmailID
}
}

Lot of errors in the above script but I'm sure I will get my answers from the Experts on this website. Please Help

 

 

 

 

 

 


Set MailboxAutoReplyConfiguration

$
0
0

Hello we are using office 365 exchange online.

I need a script to set the autoreply for multiple users please, and if possible with dates as well.

I'm not sure why am I facing this error:

The term 'Set-MailboxAutoReplyConfiguration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is 

correct and try again.

At line:1 char:34

+ Set-MailboxAutoReplyConfiguration <<<<  -Identity naji.aboumoussa@levantlp.com -AutoReplyState Enabled -ExternalMessage "Dear Clients"

    + CategoryInfo          : ObjectNotFound: (Set-MailboxAutoReplyConfiguration:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

 

Exchange 2013 - count how many emails user received in period of time

$
0
0

Hi,

I have Exchange 2013

I need to connect to specific E-mail box , count all email from date X to date Y.

I tried to do this with Search-Mailbox command, but I need to give a specific folder, I need to search all folders in the box.

I don't wont to use Get-MessageTrackingLog command.

need help with this issue.

 

Thanks

Lior

 

 

Search everything in Exchange

$
0
0

Hi , 

In the Exchange console there is the find option, this will based on your search show all ( Dynamic Dist. groups, Mail Universal Dist. groups, shared mailbox).

what is the powershell script befind this ?  

i know you can use  get-mailbox  or get-distributiongroup etc.. etc.. but is there a cmdlet that i can use to search all ? 

Thanks

Piping where

$
0
0

In further pursuit of delegating Mobile Device Management in our Exchange Online tenant, I am trying to create custom roles to add to a role group.  Here is what I am trying to do.

$RolesforMDM ="Get-ActiveSyncOrganizationSettings","Get-ActiveSyncDeviceStatistics","Get-ActiveSyncDevice","Get-Recipient","Get-ActiveSyncMailboxPolicy","Get-CASMailbox","Set-ActiveSyncOrganizationSettings","Set-CASMailbox","Get-ActiveSyncDeviceAccessRule","Set-ActiveSyncDeviceAccessRule","New-ActiveSyncDeviceAccessRule","Set-ActiveSyncMailboxPolicy","New-ActiveSyncMailboxPolicy","Remove-ActiveSyncDevice","Clear-ActiveSyncDevice"

$MDM_ROLES
="MDM-Mail","MDM-OrgCliAcc","MDM-RecipPol"

New-Managementrole-Name MDM-Mail-Parent"Mail Recipients"
New-Managementrole-Name MDM-OrgCliAcc-Parent"Organization Client Access"
New-Managementrole-Name MDM-RecipPol-Parent"Recipient Policies"

ForEach($roleName in $MDM_ROLES)
{
   
Get-ManagementRoleEntry"$roleName\*"|where{$RolesforMDM -notcontains $_.Name}|Remove-ManagementRoleEntry-Confirm:$False
    $entrylist
=Get-ManagementRoleEntry"$roleName\*"|Select-ExpandPropertyName
}

New-RoleGroup MDM_Admin -Roles $MDM_ROLES

This is "breaking" trying to pipe the results of the where statement to the Remove-ManagementRoleEntry statement.  Here is the error.

Cannot process argument transformation on parameter 'Identity'. Cannot convert value "MDM-RecipPol" to type
"Microsoft.Exchange.Configuration.Tasks.RoleEntryIdParameter". Error: "The format of the value you specified in the
Microsoft.Exchange.Configuration.Tasks.RoleEntryIdParameter parameter isn't valid. Check the value, and then try again.
Parameter name: identity"
    + CategoryInfo          : InvalidData: (MDM-RecipPol:PSObject) [Remove-ManagementRoleEntry],
: (MDM-RecipPol:PSObject) [Remove-ManagementRoleEntry],

I am new to Office 365 and PowerShell, so any help is appreciated.

Save and ge back a PsSession (to MS Exchange)

$
0
0

Hello,

I'am using a webservice (in PHP) which connect to a windows server and execute a powershell script to connect to Microsoft Exchange (and interract with it).

 

But each time an operator is using the webservice, a new connexion to Ms Exchange is opened and closed. (and this method is really long.. and boring for operators)

 

I would like to open a persistant connexion to Ms Exchange (PsEssion) which i will retrieve in any others processes.

 

exemple:

1 - a shceduler is executing a powershell script to connect to microsoft exchange with a PsSession

2 - The webservice launch another powershell process and retrieve the existing PS-Session.

(so, no more connexion)

 

Is it possible? Actually, when a PS-Session is running into one process, if a second process

runs "Get-PsSession" there is no result..

 

Thanks for your help

 

import-csv - mailboxdatabase

$
0
0

Hi folks,

New to the forum and powershell.

I need to import a csv file which contains a list of our users and then use a cmdlet to find out their active mailbox database (get-mailboxdatabase) and then export this to a csv

Could someone send me the cmdlet please?

Many thanks

I'm sure I'm doing this wrong

$
0
0

I've been doing this the same way for a while but wondering if there's a better way.

Currently when I run a script that needs to do any analysis on on mailboxes I load them all into a variable. 

With 24000 mailboxes that takes a long time and uses what I've seen up to 7Gb of memory which on a shared VM Management box makes me unpopular with the team.

Example script below

$mailboxes=Get-Mailbox-ResultSize Unlimited

$panalisys= @()


foreach ($mbin$mailboxes)
{
$defperm=Get-MailboxFolderPermission-Identity$mb.Alias-User Default | Select-Object User, @{l="AccessRights";e={$_.AccessRights}}
$userDetails=Get-ADUser
$panalisys=New-Object PSObject
$panalisys | Add-Member-MemberType NoteProperty -Name'MBName'-Value$mb.DisplayName
$panalisys | Add-Member-MemberType NoteProperty -Name'User'-Value$defperm.User
$panalisys | Add-Member-MemberType NoteProperty -Name'SMTPAddress'-Value$mb.PrimarySMTPAddress
$panalisys | Add-Member-MemberType NoteProperty -Name'AccessRights'-Value$defperm.AccessRights
$panalisys | Add-Member-MemberType NoteProperty -Name'Department'-Value$userDetails.Department
$p +=$panalisys
}
$p | ?{$_.AccessRights-ne"None"} | Export-Csv c:\ScottTools\permanal.csv-NoTypeInformation

So I'm loading the mailboxes into the $mailboxes variable then running Get-MailboxFolderPermission and Get-ADUser to get the info I need.

This is to allow a team to talk to people with their Default Access on their mailbox set to anything but none. This takes hours and a lot of memory.

I'm guessing I'm probably doing it in an inefficient way. Any advice much appreciated.


about using vb/C# to create user+mailbox in exchange 2010

$
0
0

Is there any tutorial to learn?

i only know , create it 1 by 1 in Powershell .

how to auto enter Password..as it prompts  password everytime when creating users in exchange PS

Filter on Mailboxes and disabled users in AD

$
0
0

Hi, 

 

I am kinda new to powershell. 

 

What I need. 

An Powershell command to retrieve all mailboxes sorted on accounts that is enabled in AD. 

We have an environment where people quits, moves and all sorts of things, so accounts in AD is disabled to be reactivated again in a month or a year. 

 

What's needed. 

To have an up2date list of all mailboxes which currently resides and have an active AD account.

 

What's been tried :

get-mailbox |?{$_.UserAccountControl -Match "AccountDisabled"} |FT Name,Database,UserAccountControl | Out-file C:\path.csv

Did not give any result

These seemed hopefull but commands are not present. 

Search-ADAccount -AccountDisabled | Out-file C:\path.csv 

Get-Aduser -Filter (enabled -ne $true) 

 

Any tips/tricks/winks ?

 

Regards

Jan 

Trying to Export User Emails From Journaling Mailbox

$
0
0

We have a customer who is looking to export all email associated with a user, the user has multiple email addresses, but all with the syntax 'user@xxx.xxx'.I am trying to run the following export command with no success.

New-MailboxExportRequest –Mailbox jmmfexch2 –ContentFilter {(participants –eq ‘*bingalls*’)} –FilePath “\\mfexch2\archives\whatever.pst”

It finishes quickly and generates a 256K empty .pst file

Any help appreciated,

Thanks,

Bob

New-mailboxexportrequest to export contacts folder to CSV file

$
0
0

Hello,

I'm having trouble exporting out the contacts to a .csv file. I have a UNC share created with the Exchange trusted subsystem with full control on the share and the ntfs permissions. I can do the export to .pst but I need it in csv format and am not sure how to first convert to string and then export the file to csv.

Help appreciated. Thank you

Gordon

Script To Add Prefix to all existing distribution groups

$
0
0

I am looking for a script that will add a prefix of "DL_MBM_" to the front of all of our 551 distribution groups. Can anyone help me out? :( I am no scripting guru by any means.

Viewing all 10624 articles
Browse latest View live