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

Automating settings on a room mailbox

$
0
0

Hi

I'm trying to create a script that will automate some of the settings for room mailboxes for our organization with a PowerShell script, however, I'm a newbie when it comes to this sort of thing and I'm struggling.

One of the guys who worked here while we were migrating to Exchange 2010 wrote a PowerShell script that asks for a number of parameters and then creates a shared mailbox based on those parameters, so I've made a copy and gone in and made some modifications which all work as expected.

I'm trying to create a second script that goes and changes things like the capacity, BookingWindowInDays and MaximumDurationInMinutes etc.

My problem is I don't know how to do the capacity bit.

At the top of my script I've got the following:

# Parameters below are where you enter the information of the rooms, which PowerShell will then use later on in the script

param(
    [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Room Name")][string]$Name,
    [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="MANAGEMENT Group")][String]$MGRGroup,
 [parameter(Position=2,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="USER Group")][String]$USRGroup,
 [parameter(Position=3,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Capacity")][String]$Capacity
    )

# Loads the ActiveDirectory module into PowerShell if it hasn't already been loaded. This is because the new-adgroup is an AD commandlet rather than an Exchange one  
  
Import-Module ActiveDirectory -ErrorAction SilentlyContinue

# Setup splatting hashtable
$NewSharedMailbox = @{
    "Shared" = $True
    "Name" = $Name
}
# Check parameters OK and add relevant parameters to splatting hashtable
$Recipient=Get-Recipient $Name -ErrorAction SilentlyContinue

How do I then set the capacity? When I do

# Set room mailbox 'standard config'

write-host
Write-Host -ForegroundColor Green "Setting Room Mailbox Standard Config"

try {get-mailbox -name $name | Set-Mailbox -ResourceCapacity $Capacity }
 catch {
     write-host
  write-host -ForegroundColor Green "Please wait..."
  }

PowerShell asks me for the identity of the Set-Mailbox.

Any advice would be greatly appreciated as its doing my head in! I thought I was making good progress with the create room script, but now I've hit a brick wall.

Thanks in advance!


Trying to restore a mail file from a recovery database

$
0
0

I am trying to recover an exchange mail file from a recovery database, I tried to browse the database but got no results

[PS] C:\>Get-MailboxDatabase rdb

Name                           Server          Recovery        ReplicationType
RDB                            CBSEXC001       True            None


[PS] C:\>Get-MailboxDatabase rdb | get-mailbox
[PS] C:\>

if I can't browse the mailboxdatabase, how do I know the users mailbox is there?

any information would be appreciated

sendAs, SendOnBehalfOf access and DL for a specific user

$
0
0

Hi-

Would you happen to have a script that will report the DL and the type of access (SendAs, SendOnBehalfOf) for a specific user?

I tried get-distributiongroup with the managedBy command, but that isn't exactly what I want, as this user may not always manage the group, but has rights to sendAs etc.

Any help would be appreciated.

Thanks!

mailbox search

$
0
0

Hi All

I am trying to create a monthly windows schedule task where mailbox deleted items are searched for last 30 days from the date the schedule is run.

This works
Search-Mailbox -Identity "user" -SearchDumpsteronly -SearchQuery {"Received: 04/01/15..04/02/15 "} -includeunsearchableitems -TargetMailbox searchresults -TargetFolder "test" -Loglevel Full

As i schedule task i do not want to add manual entry {"Received: 04/01/15..04/02/15 "} each time it has to run.


I have tried this and it has failed  

$start=(Get-Date).adddays(-30)
$end=(Get-Date).adddays(-1)
$start = “{0:dd/MM/yyyy} –f $start
$end = “{0:dd/MM/yyyy} –f $end
 
Search-Mailbox -Identity "user" -SearchDumpsteronly -SearchQuery  {("Received -lt $end") -and ("Received -gt $start")} -includeunsearchableitems -TargetMailbox searchresults -TargetFolder "test" -Loglevel Full

Also replaced {("Received -lt $end") -and ("Received -gt $start")} with
{received:$start..$end}

I have come to realise that searchquery does not like varibles date  e.g. $start and $end, if i add real dates 1/1/15 works fine. I have looked at $start and $end values and they appear to match the value that works e.g. 1/1/15

Would anyone know why searchquery behaves like this with date or how to fix it or if i am just doing something wrong

thanks

Ps apologies i did add something similar in an incorrect forum but have done a bit more testing since then based on information provided

Exchange 2010: Export Mailbox to PST using CSV

$
0
0

Hello - I'm in the process of exporting mailboxes from another exchange server from a company we acquired so I can import email into their new mailbox. I have a CSV formatted with headers old,new which has their old alias and new alias. I also only want to capture the last 60 days of email. However, I seem to be missing something in formatting as it keeps creating a new line instead of just executing the script. I'm at a loss and can't seem to get this working. Any help would be appreciated!

 

$sixty = get-date -format "M/d/yyyy" (get-date).AddDays(-60)
$UserList=Import-CSV C:\users.csv
FOREACH ($Person in $UserList) {
New-MailboxExportRequest -Mailbox $Person.old -ContentFilter {(MessageKind -eq 'Email') -and (Received -gt $sixty) -or (Sent -gt $sixty)} -FilePath "\\server\pst\"$Person.new".pst"
}

Little Script Help

$
0
0

Good day,

This is my very first post on the forums :)  I ran into the site when looking to figure out what I am doing wrong with my script.  I hope someone can maybe point me in the right direction. 

I have a list of users (about 500) who need an email alias added to their mailboxes (Exchange 2010) and so I figured I would create a script to do so.  The script imports the usernames from a CSV file and using a variable I concatenate what the new email address will look like. From there I use a simple For loop to run the command for each element of the array containing the imported data from the CSV.  The script looks as follows:

------------------------------

$UsrName = @()

$CSVPath = "C:\PowerShell\UsrEmail.csv";

$UsrName = Get-Content -path $CSVPath;

For ($i=0; $i -lt $UsrName.length; $i++) 

{

  $usridemail = $UsrName[$i] + "@company.com";

  $usridemail;

  Set-RemoteMailbox $UsrName[$i] -EmailAddresses @{Add="$useridemail"};   

}

------------------------------

Using the double quotes in the command, I expected it to evaluate the $useridemail variable and poof, I would be good to go.  However it doesn't appear to be the case.. I get the following error:


user@company.com

Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.Hashtable" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "Failed to convert  from System.String to Microsoft.Exchange.Data.ProxyAddress. Error: Error while converting string '' to result type Microsoft.Exchange.Data.ProxyAddress: The e-mail address cannot be empty."    + CategoryInfo          : InvalidData: (:) [Set-RemoteMailbox], ParameterBindin...mationException    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-RemoteMailbox

 

So with my limited understanding of powershell... from what I can see is that it is not evaluating the $useridemail variable when attempting to add the new email address to the mailbox.

I also have to apologize as I am sure there is a much more efficient way to write a script that does this, but my knowledge of powershell is fairly limited. Any help would be very appreciated.

If I run the set-remotemailbox command manually, and input the username and desired email address it works fine.  So there is something about that variable it doesn't like. 

List all properties but these

$
0
0

I want to list all of a users mailbox properties but a couple.  If I do a get-mailbox user | fl I get all the properties.  Great.  But I don't want to see the certificates so I don't want to see the *cer* in the list.  how in the heck do you exclude some properties.  Thanks

Transportrule exporting as readable format

$
0
0

Hi,

Anyone tried exporting transportrules in readable format? I am looking to export (Export-TransportRuleCollection) to csv or HTML format so that I can use that for meeting discussion doc.. I tried get-transportrule and printing only few columns but its not useful I have 26 rules use different conditions, action and exceptions. so unsuccessful :(   

 

I read MS article for export and importing in xml format (https://technet.microsoft.com/en-us/library/bb629570(v=exchg.141).aspx)

Any help readable format.. appreciated. 

Thank you,

Raj

 


PSWA and Exchange

$
0
0

Hi!

I have just installed Powershell Web Access on a separate Windows 2012R2 server and would like to connect further in to my Exchange 2013 servers to run Exchange commands, like get-mailbox. Any suggestions on what would ble the easiest way to do this? Thanks!

Get-Help -ShowWindow only shows Synopsis

$
0
0

When executing Get-Help with the -ShowWindow parameter for any Exchange-specific cmdlet, the window only shows the Synopsis.  The Syntax, Parameters, Inputs, Outputs, and Examples are all blank.

When executing this with any other command, such as Get-Help Get-ADUser -ShowWindow, the pop-up window shows complete help information.

Running as admin does not help.  Running Update-Help does not help.

I would really like to get this to show in a window as one would expect it to.  I realize that the -Online parameter is a workaround, but I would prefer to use the pop-up window.

Am I stuck with not being able to display help in this way for Exchange functions, or is there something that can be done to correct this behavior?

connect exchange server from remote machine failed with error

$
0
0

 

hi,

Try  to connect exchange server from remote machine.

$session = new-pssession -connectionURI "http://XXXXXXX/powershell?serializationLevel=Full" -ConfigurationName "http://schemas.microsoft.com/powershell/Microsoft.Exchange" -Credential $user

Import-PSSession $Session

 

failed with access denied error 

then   i checked the remote machine , to know how trusted hosts configured .

machine confgured with 'trustedhosts *'

 

then i reset trusted host settings to null value.. its works fine

 

 

 

my question is ,what is the difference between 

Set-Item wsman:\localhost\client\trustedhosts *

and

Set-Item wsman:\localhost\client\trustedhosts null

 

 

thank you

sumith

delete old items older then 30 days from user mail box (exchange 2013)

$
0
0

Hi,

I'm trying to run this command (exchange 2013), delete mails that are older then 30 days:

[int]$numberOfDays=30

[DateTime]$date=[DateTime]::Now.Subtract([TimeSpan]::FromDays($numberOfDays))

Get-Mailbox -Identity $m |Search-Mailbox -SearchQuery {(Received -ge $date) } -DeleteContent

 

$m is the mailbox  identity.

$date is the date ,that mails that older or equal to  $date I want to delete.

 

I get this error:

Search-Mailbox : Could not load file or assembly 'Microsoft.Ceres.NlpBase.RichTypes, Version=16.0.0.0, Culture=neutral, PublicKeyToken

=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

At line:1 char:27

+ Get-Mailbox -Identity $m |Search-Mailbox -SearchQuery {(Received -ge $date) } -D ...

+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Search-Mailbox], FileNotFoundException

    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.Exchange.Management.Tasks.SearchMailbox

need help with this issue.
Thanks,
Lior

 

Convert Array to String

$
0
0

Hi guys,

This is my script to get all mailbox permissions for all shared mailboxes from a specific mailbox store:

Get-Mailbox -Database MailboxstoreXX | Get-MailboxPermission | Where-Object {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.user.tostring() -ne "Domain\UserToFilter" -and $_.user.tostring() -ne "S-1-5*" -and $_.IsInherited -eq $false} | Select-Object User,Identity,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} | Export-Csv -NoTypeInformation -Path "C:\PathToFolder\permissions.csv"

This is a generic code that you could edit for your needs.

The issue that I have:

When executing this on the Exchange server in the Exchange Management Shell I get a nice result in CSV format.

Access rights are shown in the format: FullAccess, DeleteItem, ReadPermission

 

I like to run all my scripts in the ISE editor with a PSSession to Exchange.
The script works as well, but instead of the correct access rights I receive this:
System.Collections.ArrayList

 

So basically, in the ISE editor, the ArrayList is not converted to a string.
Does anybody have an idea how to fix this in the ISE editor?
Or why it is working on the Exchange server but not locally? 

Perhaps there is an easier way?

 

Thank you 

 

RecipientFilter variable wildcard

$
0
0

Hi guys,

please, is there a way, how can I put variable with wildcard in RecipientFilter?

Example:

$filter = [string]('91*')

New-DynamicDistributionGroup -Name $dg.Name -Alias $dg.Alias -RecipientFilter "Department -like $filter"

This example creates DynDystGroup but without wildcard *:

RecipientFilter : ((Department -like '91') -and (-not(Name -like 'SystemMailbox{*')) -and (-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) -and
                  (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) -and (-not(RecipientTypeDetailsValue -eq
                  'ArbitrationMailbox')))

 

Thank you very much,

Lukas

Issue with adding the user to the DL (AD user creation + Add user to SG's + Create office 365 mailbox + Add user to DL)

$
0
0

I have created a script that would perform - AD user creation + Add user to SG's + Create office 365 mailbox + Add user to DL

Here is the script below - 

#############################################################################################

Import-Module ActiveDirectory -ErrorAction Stop

Import-Module MSOnline

Connect-MsolService

$adusers = Import-csv 'C:\Program Files (x86)\scripts\ADUsers.csv'

#This will process the CSV row by row. Each row contains information to create an active directory account for a user. 

foreach ($user in $adusers) 

{

   $username = $user.username  

   $password = $user.password

   $firstname = $user.firstname

   $lastname = $user.lastname

   $surname = $user.surname

   $GroupName = $user.GroupName

   <#write-host "username :"$username

   write-host "password :"$password

   write-host "firstname :"$firstname

   write-host "lastname :"$lastname

   write-host "surname  :"$surname

   write-host "GroupName :"$GroupName#>

 

#create AD Acct sets for username  #sets account name      #sets first name   #sets lastname  #enables account #sets display name        #sets login script path

New-ADUser -samaccountname $username -name "$firstname $surname" -givenname $firstname -surname $lastname -enabled $true -displayname "$firstname $surname"  -accountpassword (convertto-securestring $password -asplaintext -force)

if (Get-ADUser -Filter "surname -eq '$lastname' -and givenname -eq '$firstname'")

{

write-host "User Found"

}

else 

{

write-host "Did not Found user"

}

#Adding Users to Security Groups

Add-ADGroupMember  -Identity "security group 1" $username 

Add-ADGroupMember  -Identity "security group 2" $username

#Adding Users to DL

#Add-ADGroupMember "Distributionlist@domain.com" -Members (get-aduser $username)

#Moving users to OU

Get-ADUser $username | Move-ADObject -TargetPath 'ou=company,ou=Accounts,DC=TEST,DC=local'

###############################Creating office365 Accounts###########################################

#Below will rise popup,Credentials will store to the variable $LiveCred after entering credentials

$Office365Users = New-MsolUser -DisplayName "$firstname $surname" -FirstName $firstname -LastName $lastname -UserPrincipalName $firstname@domain.com –PassWord $password

}

##############################################################################################################

Every thing is working fine and the only issue i have got here is the user is not getting added to the DL (The DL already exists)

 

#Adding Users to DL
#Add-ADGroupMember "Distributionlist@domain.com" -Members (get-aduser $username)

 

I am not sure what i am missing here - have been trying to lot to resolve this issue ! Can you help further ?

 

 


piping a list of email address into a get-user command

$
0
0

I am trying to push a list of variables into get-user, the individual components work.

$email = get-content -path "c:\temp\list.txt" | get-user $email | select-object userprincipalname,department,phone,name | format-table

get-content -path "c:\temp\list.txt" gives the list of email address, and if I take one of those email addresses and paste it into get-user $email | select-object userprincipalname,department,phone,name | format-table, the correct response is returned, however if I join the two together I get [get-user] parmemeterbindingexception.

I really feel I am missing something here

 

Problems with using pipes in a For Each command block

$
0
0

I've been given a list of hundreds of email addresses and asked to output the names, office, & department values to a spreadsheet.  I decided to try this using a for each block but for some reason the export-csv isn't working, I end up with an empty csv output file.  Here's what I'm doing:

The input CSV file is just a header of EmailAddress and then 1 or more email addresses on a new line; right now I'm testing with only a single address in the input file, but I've tested with a small list of 2 good addresses and 1 non-existant address which also didn't work.

$addr = Import-CSV C:\dir\list.csv

foreach ($mb in $addr){Get-recipient -resultsize unlimited | where {$_.emailaddresses -like $mb.EmailAddress} | select name, @{Name=’EmailAddresses’;Expression={[string]::join(";", ($_.EmailAddresses))}}, displayname, department, office | Export-CSV -NoTypeInformation Export-List.csv}

Mark All Email in Mailbox As Read

$
0
0

I have an Outlook mailbox as follows:





Using PowerShell, how do I recurse through each folder (and its subfolders) and mark every message as read? (5_Misc is actually my "inbox"; I renamed it using MFCMAPI).

 

I've tried several scripts, but each one errors.  I can post them if it helps, but if there's a standard way to do it that'd be great.


Thanks for any help.

Hi I am trying to use below script using new-pssession but its not working.

$
0
0

C:\Users\user>"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -command "$s= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Exchservername/PowerShell/ -Authentication Kerberos ; Import-PSsession $s; C:\Failback.ps1 but nothing is happening and there are no errors only warning is coming.

Warning: Some imported command names include unapprovedd verbs which might make them less discoverable. Use the Verbose parameter for more details or type  get-verb to see the lost of approved verbs.

Below is the PS script

Get-MailboxDatabase | Sort Name | ForEach {$MBdb=$_.Name; $ServerHosting=$_.Server.Name ;$ActivationPreference=$_.ActivationPreference| Where {$_.Value -eq 1};

If ( $ServerHosting -ne $ActivationPreference.Key)
{
Move-ActiveMailboxDatabase $MBdb -ActivateOnServer $ActivationPreference.Key -confirm:$False

}
}

doesn't contain a method named 'op_Addition'.

$
0
0

 

 

 

 

 

 

 

 

 

 

 

 

 

Hi,

I look for a solution to add\delete PSObjects from an array.

It looks like if their only one item remains in the array it is not possible to add a new object.

This example get an error with adding a new object.

With this line it is working

$X=$AllQ | Where-Object {$_.Queue -neQ1"}

 

$AllQ

 

 

= @()

For ($i=0;$i-lt 10;$i++) {

 

 

 

$X=New-ObjectPSObject-Property$QProps

 

 

 

$X.Queue="Q$i"

 

 

 

$X.Depth= $i

 

 

 

$AllQ+=$X

}

 

$X

 

 

= @()

$X

 

 

=$AllQ | Where-Object {$_.Queue -eqQ1"}

 

 

 

 $A=New-ObjectPSObject-Property$QProps

 

 

 

 $A.Queue="XX"

 

 

 

 $A.Depth0

 

 

 

 $X+=$A

 

exit

 

Method invocation failed because [System.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'.

At C:\Users\spbpho\AppData\Local\Temp\2\f5b794ec-9548-4d85-b162-e085df99a264.ps1:17 char:8

+ $X += <<<< $A

+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException

+ FullyQualifiedErrorId : MethodNotFound

 

 

 

Viewing all 10624 articles
Browse latest View live