Hello forum,
I’m new here but I need a little help with a script please.
I wish to import data from a file (which has UPN), i figured that part with $a = import-csv C:\temp\file.csv but after reading the UPN inside the file, I need to extract from each UPN, all archive information, totalitemsize and retentionpolicy. Also I wish to know how can I run a script without printing the code in powershell while it runs.
Can anyone help please?
Regards
If you would like assistance, post the code, CSV examples that have been scrubbed and expected results.
thank you for your reply but I managed it. here’s the code for someone who needs it:
$a = Import-Csv C:\temp\source_file.csv
foreach ($user in $a){
$_ = Get-MailboxStatistics $mailbox | select @{Name = "TotalArchiveSize"; Expression = {$_.TotalItemSize.ToString().Split("(")[0]}}
$mailbox = $user.UserPrincipalName
$stats = Get-MailboxStatistics $mailbox | Select displayname, totalitemsize
$archive = Get-Mailbox -Archive -Identity $mailbox | select archivequota, archivewarningquota, RetentionPolicy
$user | Add-Member -NotePropertyName Displayname -NotePropertyValue $stats.DisplayName
$user | Add-Member -NotePropertyName TotalitemSize -NotePropertyValue $stats.totalitemsize
$user | Add-Member -NotePropertyName RetentionPolicy -NotePropertyValue $archive.Retentionpolicy
$user | Add-Member -NotePropertyName ArchiveQuota -NotePropertyValue $archive.ArchiveQuota
$user | Add-Member -NotePropertyName ArchivewarningQuota -NotePropertyValue $archive.ArchivewarningQuota
$user | Add-Member -NotePropertyName ArchiveSizeInUse -NotePropertyValue $_.TotalArchiveSize
}
$a | Export-Csv C:\temp\export_file.csv -NoTypeInformation -Delimiter “;”
luis_palma:
$a = Import-Csv C:\temp\source_file.csv
foreach ($user in $a){
$_ = Get-MailboxStatistics $mailbox | select @{Name = "TotalArchiveSize"; Expression = {$_.TotalItemSize.ToString().Split("(")[0]}}
$mailbox = $user.UserPrincipalName
$stats = Get-MailboxStatistics $mailbox | Select displayname, totalitemsize
$archive = Get-Mailbox -Archive -Identity $mailbox | select archivequota, archivewarningquota, RetentionPolicy
$user | Add-Member -NotePropertyName Displayname -NotePropertyValue $stats.DisplayName
$user | Add-Member -NotePropertyName TotalitemSize -NotePropertyValue $stats.totalitemsize
$user | Add-Member -NotePropertyName RetentionPolicy -NotePropertyValue $archive.Retentionpolicy
$user | Add-Member -NotePropertyName ArchiveQuota -NotePropertyValue $archive.ArchiveQuota
$user | Add-Member -NotePropertyName ArchivewarningQuota -NotePropertyValue $archive.ArchivewarningQuota
$user | Add-Member -NotePropertyName ArchiveSizeInUse -NotePropertyValue $_.TotalArchiveSize
}
Glad you have it working. This is an example that is a bit cleaned up if interested:
$csv = Import-Csv C:\temp\source_file.csv
$results = foreach ($user in $csv){
$mailbox = $user.UserPrincipalName
$stats = Get-MailboxStatistics $mailbox |
Select displayname,
totalitemsize,
@{Name = "TotalArchiveSize"; Expression = {$_.TotalItemSize.ToString().Split("(")[0]}}
$archive = Get-Mailbox -Archive -Identity $mailbox |
select archivequota,
archivewarningquota,
RetentionPolicy
[PSCustomObject]@{
Displayname = $stats.DisplayName
TotalitemSize = $stats.totalitemsize
RetentionPolicy = $archive.Retentionpolicy
ArchiveQuota = $archive.ArchiveQuota
ArchivewarningQuota = $archive.ArchivewarningQuota
ArchiveSizeInUse = $stats.TotalArchiveSize
}
}
# $results | Export-Csv....
3 Likes