Home » Posts tagged 'powershell'

Tag Archives: powershell

Map a Network Share with PowerShell

Use the New-SmbMapping command to map a remote network share to a local drive letter.

New-SmbMapping -LocalPath Y: -RemotePath \\server\ShareName

Powershell: Rename Computer, Join Domain, and Reboot

From a “Hey, Scripting Guy! Blog” post.

An alternative to using the NETDOM command line program to rename and join computers to an Active Directory Domain is to use these Windows PowerShell 2.0 command:

(Get-WmiObject win32_computersystem).rename("newname")
add-computer -Credential iammred\administrator -DomainName iammred.net

In the first command, I use the Get-WmiObject cmdlet to retrieve the Win32_ComputerSystem Windows Management Instrumentation class. (The Get-WmiObject cmdlet has an alias of gwmi, and it will also take credentials if required.) Because this class returns only one instance, I can use my group and dot trick (see My Ten Favorite Windows PowerShell Tricks) to directly call the Rename method to rename the computer.

After I rename the computer, I use the Add-Computer cmdlet to join the computer to the domain. The Add-Computer cmdlet allows me to specify the credentials that have rights to add computers to the domain, in addition to the name of the domain to join. Although I did not do it in my example, there is also an ou parameter that allows you to specify the path to the OU that will contain the newly created computer account.

The last command, Restart-Computer, appears without any parameters. This means that the computer will restart within one minute, and it will attempt to cause processes to politely exit (generally a good thing). For emergency type of situations, there is the Force switch that will cause the computer to immediately restart, and not wait on processes to politely exit. The use of this optional parameter can lead to data loss in some situations.

Set Exchange 2010 Alias to samAccountName

Use these PowerShell commands to set a users Exchange mailbox Alias to their username (AKA samAccountName/samid):
$aliasname = Get-Mailbox -OrganizationalUnit "OUNameHere" -ResultSize Unlimited
$aliasname | Foreach-Object{
$_ | Set-mailbox -Alias $_.SamAccountName

Exchange 2007 PowerShell DistributionGroup commands

Here aresome PowerShell cmdlets for working with distribution group in exchange 2007

Get-DistributionGroup – Retrieves properties of a distribution group

New-DistributionGroup – Creates a new distribution group

Remove-DistributionGroup – Deletes a distribution group

Set-DistributionGroup –  Set Properties on a distribution group


How To Create New Exchange 2007 Contacts

You can create (aka import) email contacts in Exchange 2007 from the command line using PowerShell (the Exchange Console). The PS script will read the contact information from a CSV file.

Here is the powershell (Exchange Console) script/command:

Import-Csv contacts.csv | ForEach { New-MailContact -Name $_.displayName -ExternalEmailAddress $_.Emailaddress -OrganizationalUnit "domain.com/company/email/contacts" }

NOTE: be sure to adjust the -OrganizationalUnit parameter in the command above.

CSV file: (contacts.csv)

Mike Wood,michael@example.com
John Q. Customer,johnc@example.org