Is it possible to import Exchange settings? - powershell

I want to be able to export Exchange settings which happen to be message size-related, and import them using PowerShell.
"Backing up is good, restoring is better."
I've been exporting them like so:
get-transportconfig | select maxsendsize | Export-Csv $backupPath\transportconfig.csv
get-sendconnector | select name, maxmessagesize | Export-Csv $backupPath\sendconnector.csv
get-mailbox | select Name, Maxsendsize |Export-Csv $backupPath\mailbox.csv
But can I do anything with this?
How does one import the settings?
You can find a lot of examples of how to import table data, but I can't find anything about importing settings.

You can use Export-Clixml to save the object :enter code here
Get-TransportConfig | Export-Clixml "c:\temp\TransportConfig.xml"
$transportbackup = Import-Clixml "c:\temp\TransportConfig.xml"
Set-TransportConfig -MaxSendSize $transportbackup.MaxSendSize.Value
Then Set-TransportConfig allow you to restore the needed values.
I imagine, it's the same for Set-SendConnector and Set-Mailbox.
Edited
You can find more information for Set-SendConnector here
You can find more information for Set-Mailbox here

Just to wrap this up, I found an answer to my final issue here: [link]ficility.net/tag/import-clixml $mailboxes = Import-Clixml -Path "D:\mailboxes.xml" foreach($mailbox in $mailboxes){ Set-Mailbox -Identity $mailbox.Identity -EmailAddresses $mailbox.EmailAddresses -EmailAddressPolicyEnabled $mailbox.EmailAddressPolicyEnabled }

Related

How to get the get-ADPrincipalGroupMembership for all users in a txt or csv file and put into a txt file for each user?

I am trying to get a file with the group-memberships for every user that is specified in a txt/csv file.
so this is what i had before:
Get-ADPrincipalGroupMembership -Identity $user -Server $DC | Select name | Where-Object name -like GUSR_* | Out-File "C:\temp\$user.txt"
this work fine for getting the groups from 1 singel user, but now i have to do this for 100+ users.
And instead of doing it one by one i am looking for a way to automate it.
so i got myself a .csv export of all the users i want this done for.
and started trying.
what i came up with so far:
$users = Get-Content "C:\temp\test.csv" |ForEach-Object {Get-ADPrincipalGroupMembership -Identity $users -Server $DC | Select name | Where-Object name -like GUSR_* | Out-File "\\ads.net\ADS\SDL\Temp\_ROLAND\RSD\test2\$users.txt"}
This cleary doesnt work.
I have tried a couple of other things with the foreach command but nothing did the trick.
I have the feeling i am not on the right path to get my result.
Maby somebody has done this before and can help me get on the right path.
i'm not new to powershell but i'm far from an expert, most of the time i use it for basic singel commands or edit some great scripts i find.
sadly for this i haven't found any yet.
with kind regards
Roland
Don't assign back to a variable
Import the CSV
No filter after select
Pretiffy your -like
Use $_ as pipeline variable
Use subexpression operator for string+variable concatenation
Import-Csv "C:\temp\test.csv" |ForEach-Object {Get-ADPrincipalGroupMembership -Identity $_.users -Server $_.DC | Where-Object {$_.name -like 'GUSR_*'} | Select -Expand Name | Out-String | Out-File "\\ads.net\ADS\SDL\Temp\_ROLAND\RSD\test2\$($_.users).txt"}

Powershell exports csv file containing active directory security group data

I have a bat file that starts up a PS1 script, the PS1 script is supposed to go to AD and export the names listed in a Security Group. It runs fine and exports fine, however the data is incorrect, almost as if it is exporting some unknown data that I'm not sure where from. Here is my powershell script:
$uni = Read-host 'Your username'
$SG = Read-host 'Security Group'
start-sleep -s 3
powershell.exe get-adgroupmember "$SG" | export-csv -path "C:\users\$uni\desktop\members.csv"
When opening the CSV, it shows similar:
TYPE System.String
Length
79
79
63
17
34
79
26
54
1
Am I needing to declare or import a pssession? if so, what is the configurationname for active directory?
Most likely you're getting a collection of objects in your data. You have to expand or join the data before passing to Export-CSV
See the following articles for some idea:
1) http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/
2) http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2010/Powershell/WhydoIgetSystem.StringwhenusingGet-MessageTrackingLogandexportingtoaCSV.html
The articles give the following examples:
1) change the following
Get-TransportServer | Get-MessageTrackingLog -ResultSize -Start "11/28/2011" -Sender nuno#letsexchange.com | Select * | Export-Csv D:\Reports\Sent_Nuno.csv -NoType
to
Get-TransportServer | Get-MessageTrackingLog -ResultSize -Start "11/28/2011" -Sender nuno#letsexchange.com | Select {$_.Recipients}, {$_.RecipientStatus}, * | Export-Csv D:\Reports\Sent_Nuno.csv -NoType
2) change the following
Get-QADUser seth -IncludeAllProperties | select name, proxyaddresses | Export-Csv .seth-nojoin.csv - See more at: http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/#sthash.JCccKLui.dpuf
to
Get-QADUser seth -IncludeAllProperties | select name, #{Name=’proxyAddresses';Expression={[string]::join(“;”, ($_.proxyAddresses))}} | Export-Csv .seth-all_proxyaddresses.csv - See more at: http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/#sthash.JCccKLui.dpuf
You'll need to import the ActiveDirectory module for the get-ADGroupMember cmdlet, but I assume you've already gotten past that part as you have output instead of errors. I don't have the ability to test currently as I can't import the module (need RSAT or AD Management Gateway Service installed), but I think you would need to insert a select command in your pipeline (to enumerate the problematic data fields) that looks something like this:
powershell.exe get-adgroupmember "$SG" | Select {$_.nameOfVariableReturningSystemString}, * | export-csv -path "C:\users\$uni\desktop\members.csv
Alexander Obersht answered my question through comments, although duct_tape_coder you are also correct. Thanks for the help guys, appreciated.

Trying to determine managedby attribute for specific distributionlist

I've a text file with a list of distribution groups that I'm trying to get managedby attribute. I tried running different commands but seems to be a syntax issue ( fairly new to PowerShell) because I'm able to retrieve the attribute managedby for single distribution group. When I'm formatting and exporting the result to csv file all I get is a bunch of numbers. I'm on powershell exchange server 2008.
Starting with a flat text file named groups.txt:
Employees#company.com
Executives#company.com
Suggested Solution:
$grouplist = Get-Content groups.txt | foreach {Get-DistributionGroup -Identity $_ | Select-Object PrimarySMTPaddress, ManagedBy}
$grouplist | Export-Csv -Path results.csv -NoTypeInformation
Gives results like:
"PrimarySmtpAddress","ManagedBy"
"Employees#company.com","admin"
"Executives#company.com","admin"
Reproducing the "bunch of numbers" issue:
$grouplist = Get-Content groups.txt | foreach {Get-DistributionGroup -Identity $_ | Select-Object PrimarySMTPaddress, ManagedBy}
Export-Csv -InputObject $grouplist -Path results2.csv -NoTypeInformation
Resulted in:
"Count","Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized"
"2","2","2","1","System.Object[]","False","True","False"
Environment: Exchange 2013, Powershell 5.0, Windows 10 Tech Preview 3

Updating Phonenumbers in AD via csv with Powershell

Please guys, help me out here.
I have created a file with the following command:
Get-ADUser -Filter * -Properties samAccountName,DistinguishedName,telephoneNumber | select-object samAccountName,DistinguishedName,telephonenumber,address,city | Export-Csv C:\Shares\TESTSHARE\new3.csv -notypeinformation -delimiter ";" -Encoding utf8;
This works like a charm, but for the love of god, I cannot manage to import it again, all I wanna do is change the phonenumbers in the excel sheet, and insert the altered file into the AD.
Basically this has robbed me three days worth of time already, and my client is becoming edgy..
EDIT:
I tried to run the script which was posted by Ansgar Wiechers but unfortunately I got a few error messages.
Use the complementary cmdlets in reverse order:
$csv = 'C:\Shares\TESTSHARE\modified3.csv'
Import-Csv $csv -Delimiter ';' -Encoding UTF8 | % {
Get-ADUser -Identity $_.samAccountName |
Set-ADUser -OfficePhone $_.telephonenumber
}
Edit: Your error messages suggest that you try to assign empty telephone numbers. Verify that by adding the following line before Get-ADuser:
Write-Output "{0} [{1}]" -f $_.samAccountName, $_.telephonenumber

Powershell - Adding computers to a security group in Active Directory

How can I add multiple computer accounts from within a text file into a security group in Active Directory? I put this snippet of code together but it only works with user accounts.
Import-Module ActiveDirectory
Get-Content C:\Servers.txt | Foreach-Object {Add-ADGroupMember "WSUS Auto Download and Notify for Install" $_}
The command you are looking for is Add-ADPrincipalGroupMembership.
Get-Content c:\servers.txt | Add-ADPrincipalGroupMember -memberof 'WSUS Auto Download and Notify for Install'
If you need to add the "$" at the end of the computer name, your command could use a scriptblock parameter (an anoymous function that can modify pipeline input).
Get-Content c:\servers.txt | Add-ADPrincipalGroupMember -memberof 'WSUS Auto Download and Notify for Install' -identity {"$_$"}
I use -Identity $_.objectGUID
$_$ didn't work for me.
EDIT: Ah, sorry, that's because I use Get-ADComputer to pipe it, and not a text file.
I had similar task found info on this link worked for me,
Run it in powershell as admin
Import-Module ActiveDirectory
$List=Get-Content c:\computers.txt
$List | foreach {Add-ADGroupMember -id ADGroupName -MEMBERS (Get-ADComputer $_)