Powershell script doesn't reognise a cmdlet, typing it directly works!
I have the following very simple script:
####################################################################################################
# ExportMailbox.ps1
#
###################################################################################################
Clear-Host
$TargetUserName = Read-Host "Enter the Alias or sAMAccountName of the user you would like to Export"
$TargetArchiveDir = Get-Item "\\Server1\Exports\"
$CurrentHostName = hostname
$CurrentProfile = Gwmi Win32_ComputerSystem -Comp $CurrentHostName
"Logged On As User: " + $CurrentProfile.UserName
Write-Host "Exporting Mailbox to" "\\Server1\Exports\" -ForeGroundColor Yellow
New-MailboxExportRequest -Mailbox $TargetuserName -FilePath $TargetArchiveDir
When executing the script, I get the error that the New-MailboxExportRequest cmdlet is not recognised. However if I run the same cmdlet from the CLI using the same credentials it works. So I confirm I have the role assigned to me.
Anyone?
May 18th, 2011 5:42am
When you execute the script, are you sure you're launching it in an EMS session, and not a generic Powershell session?[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
May 18th, 2011 5:58am
I fixed it:
Needed to call the right snap-in.
############################################
#
#ExportMailbox.ps1
#
############################################
Clear-Host
#Load Exchange Server 2010 Management Shell if not loaded.
if (-not (Get-PSSnapin | Where-Object {$_.Name -like "Microsoft.Exchange.Management.PowerShell.E2010"}))
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
$TargetUserName = Read-Host "Enter the alias or sAMAccountName of the user you would like to export, e.g. Joe.Bloggs"
$CurrentHostName = hostname
$Path = "\\" + $CurrentHostName + "\Exports\" + $TargetUserName + ".pst"
Write-Host "Attempting to export mailbox to" $Path -ForeGroundColor Yellow
New-MailboxExportRequest -Mailbox $TargetuserName -FilePath $Path
$Exit = Read-Host "Press any key to exit..."
However still getting stupid errors about the source database not responding or something. Works fine through Exchange Powershell CLI when manually done. I'm heading for an early retirement here. This technology sucks more and more each day!
May 18th, 2011 6:48am
Hi Nadim,
The script works fine in my test lab.
Please remove any export requests first: Get-MailboxExportRequest | Remove-MailboxExportRequest
You can post the whole error message here.
And please check whether there is any error event in the Event Viewer.
Frank Wang
TechNet Subscriber Support
in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com
Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2011 4:32am
Hi Nadim,
Any updates?Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
May 22nd, 2011 9:42pm