cls
Remove-Variable * -ErrorAction SilentlyContinue
Import-Module ActiveDirectory
#Prompt for users password which will be changed on first logo
$password = Read-Host "Enter initial password for user. It will be changed at first logon." -AsSecureString
#get users from file
$users = Get-Content "c:\temp\users.txt"
foreach ($user in $users)
{
$split = $user.Split(",", 2)
$first = $split[0];
$last = $split[1];
$display = $first + " " + $last
$name = $first + " " + $last
$upn = $first + "." + $last + "@test.com"
#get the first letter of the first name so we can create alias
$firstletter = $first.substring(0,1)
$alias = $firstletter + $last
#test if user exists
$testuser = Get-ADUser -server DC01 -LDAPFilter "(sAMAccountName=$alias)"
if ($testuser -eq $Null)
{
write-host "creating" $alias
New-Mailbox -UserPrincipalName $upn -Alias $alias -Name $name -Password $password -OrganizationalUnit HQ -FirstName $first -LastName $last -DisplayName $display -ResetPasswordOnNextLogon $true -DomainController DC01
##database is not necessary
Start-Sleep -s 5
Add-DistributionGroupMember -Identity "TestDL" -Member $alias
}Else {
write-host $name "already exists in AD"
}
}
Monday, November 19, 2012
Script to revert to Server Core
Install-WindowsFeature -ComputerName ??? server-gui-mgmt-infra,server-gui-shell
Remove-WindowsFeature -ComputerName ??? Server-Gui-Shell,Server-Gui-Mgmt-Infra
Remove-WindowsFeature -ComputerName ??? Server-Gui-Shell,Server-Gui-Mgmt-Infra
Install Powershell Web Access
Install-WindowsFeature –Name WindowsPowerShellWebAccess -IncludeManagementTools
Install-PswaWebApplication
Add-PswaAuthorizationRule -UserName contoso\anfisher -ComputerName VMM01 -ConfigurationName Windows.Powershell
Remove-WindowsFeature –Name WindowsPowerShellWebAccess -IncludeManagementTools
Uninstall-PswaWebApplication –webApplicationName PSWA
Remove-PswaAuthorizationRule -id 2
Get-PswaAuthorizationRule
Install-PswaWebApplication
Add-PswaAuthorizationRule -UserName contoso\anfisher -ComputerName VMM01 -ConfigurationName Windows.Powershell
Remove-WindowsFeature –Name WindowsPowerShellWebAccess -IncludeManagementTools
Uninstall-PswaWebApplication –webApplicationName PSWA
Remove-PswaAuthorizationRule -id 2
Get-PswaAuthorizationRule
Create Mutliple Test Hyper-V VMs
$NameVM ="testserver"
$NumArray = (1..4)
foreach ($number in $numArray)
{
$srvname = $NameVM + $number
mkdir d:\foldername\$srvname
$path = "d:\foldername\" + $srvname + "\" + $srvname + ".vhdx"
write-host "Creating" $srvname
New-VM –name $srvname -NewVHDSizeBytes 20GB –MemoryStartupBytes 1024MB –NewVHDPath $path –SwitchName CorpNet01
Set-VMDvdDrive –VMName $srvname -Path D:\src\pathtoiso.ISO=
Start-VM –Name $srvname
}
Wednesday, May 16, 2012
Add Categories to Outlook
So I wanted to take a list of categories from our CRM solution and put them Outlook so I can track how many emails and meetings I am sending/hosting for each project. I exported the CRM categories to a txt file and then ran this script.
cls
$cats = Get-Content c:\Temp\categories.txt
foreach ($cat in $cats)
{
$cat
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)
$new=$folder.Session.Categories
$new.Add($cat)
}
cls
$cats = Get-Content c:\Temp\categories.txt
foreach ($cat in $cats)
{
$cat
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)
$new=$folder.Session.Categories
$new.Add($cat)
}
Subscribe to:
Posts (Atom)