SecureString password = new SecureString();
string str_password = "pass";
string username = "userr";
string liveIdconnectionUri = "http://exchange.wenatex.com/Powershell?serializationLevel=Full";
foreach (char x in str_password)
{
password.AppendChar(x);
}
PSCredential credential = new PSCredential(username, password);
// Set the connection Info
WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
// create a runspace on a remote path
// the returned instance must be of type RemoteRunspace
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("Enable-Mailbox");
command.AddParameter("Identity", usercommonname);
command.AddParameter("Alias", userlogonname);
command.AddParameter("Database", "MBX_SBG_01");
powershell.Commands = command;
try
{
// open the remote runspace
runspace.Open();
// associate the runspace with powershell
powershell.Runspace = runspace;
// invoke the powershell to obtain the results
return = powershell.Invoke();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// dispose the runspace and enable garbage collection
runspace.Dispose();
runspace = null;
// Finally dispose the powershell and set all variables to null to free
// up any resources.
powershell.Dispose();
powershell = null;
}
Wednesday, July 6, 2011
Automatically create a 2010 exchange mailbox
Start Crawling With PowerShell
A while ago I blogged about starting a new crawl with PowerShell in this post, but today I got a bit further, each rollout I do on my dev machine a whole new site collection gets created using PowerShell, after that there is some test content provisioned (also using PowerShell), and finally the search settings are added. It kinda feels like everything is done through PowerShell. The point however is that I not only want to start a new crawl, but make sure that ‘old’ content is deleted. Step by step; I create some Crawled properties, create some Managed Metadata properties, create some scopes and finally delete the old content and crawl the new one.
The first part creating crawled properties and metadata properties i used this blog post. Getting me something like the following, that checks if the crawled property exists and if so gets it, otherwise creates it, then setting it into a metadata property that can be used. Nice to know is that the –propset property even though the documentation says its optional is in fact required!
1: # Get or create SPEnterpriseSearchMetadataCrawledProperty
2: if (Get-SPEnterpriseSearchMetadataCrawledProperty
3: -SearchApplication $searchapp -Name "proptocreate"
4: -ea "silentlycontinue") {
5: $crawlprop = Get-SPEnterpriseSearchMetadataCrawledProperty
6: -SearchApplication $searchapp -Name "proptocreate"
7: } else {
8: $crawlprop = New-SPEnterpriseSearchMetadataCrawledProperty
9: -SearchApplication $searchapp -VariantType 31
10: -Name proptocreate -IsNameEnum $false -PropSet "00130329-0000-0130-c000-000000131346"
11: }
12:
13: if (Get-SPEnterpriseSearchMetadataManagedProperty
14: -SearchApplication $searchapp -Identity "MetadataPorpertyExample"
15: -ea "silentlycontinue") {
16: write-host -f Green "MetaProperty already exists,
17: we delete it so it can be reacreated "
18: $prop = Get-SPEnterpriseSearchMetadataManagedProperty
19: -SearchApplication $searchapp -Identity "PublishingPageContent"
20: $prop.DeleteAllMappings()
21: $prop.Delete()
22: $searchapp.Update()
23: } else {}
24:
25: write-host -f Green "Try to create MetaProperty"
26: $prop = New-SPEnterpriseSearchMetadataManagedProperty
27: -SearchApplication $searchapp -Name "PublishingPageContent" -Type 1
28: $prop.EnabledForScoping = $true
29: $prop.Update()
30:
31: New-SPEnterpriseSearchMetadataMapping -SearchApplication
32: $searchapp -ManagedProperty $prop -CrawledProperty $crawlprop
After that i can create scopes (my colleague Peter found it out), where I check if a scope already exists and if so delete it so it can be recreated again:
1: if (Get-SPEnterpriseSearchQueryScope -SearchApplication $searchapp
2: -Identity "ScopeExample" -ea "silentlycontinue") {
3: write-host -f Green "Scope already exists,
4: we delete it so it can be reacreated "
5: $scope= Get-SPEnterpriseSearchQueryScope -SearchApplication
6: $searchapp -Identity "ScopeExample"
7: $scope.Delete();
8: $searchapp.Update();
9: } else {}
10:
11: # Create "ScopeExample" scope
12: $scope = New-SPEnterpriseSearchQueryScope -Name "ScopeExample"
13: -Description "Doorzoek alle informatie" -SearchApplication $searchapp
14: -DisplayInAdminUI $true
15:
16: New-SPEnterpriseSearchQueryScopeRule -RuleType AllContent
17: -Url $url -scope $scope
And after that in finally can reset my index, and make sure everything is found:
1: Write-Host -f Green "Delete current index ...";
2: $searchapp.Reset($true, $true)
3:
4: Write-Host -f Green "Start indexing and scopecompilation ";
5: $searchapp.StartScopesCompilation()
6:
7: $CrawlContents = Get-SPEnterpriseSearchServiceApplication
8: | Get-SPEnterpriseSearchCrawlContentSource
9:
10: foreach ($crawlcontent in $CrawlContents)
11: { $crawlcontent.StartFullCrawl(); }
The first part creating crawled properties and metadata properties i used this blog post. Getting me something like the following, that checks if the crawled property exists and if so gets it, otherwise creates it, then setting it into a metadata property that can be used. Nice to know is that the –propset property even though the documentation says its optional is in fact required!
1: # Get or create SPEnterpriseSearchMetadataCrawledProperty
2: if (Get-SPEnterpriseSearchMetadataCrawledProperty
3: -SearchApplication $searchapp -Name "proptocreate"
4: -ea "silentlycontinue") {
5: $crawlprop = Get-SPEnterpriseSearchMetadataCrawledProperty
6: -SearchApplication $searchapp -Name "proptocreate"
7: } else {
8: $crawlprop = New-SPEnterpriseSearchMetadataCrawledProperty
9: -SearchApplication $searchapp -VariantType 31
10: -Name proptocreate -IsNameEnum $false -PropSet "00130329-0000-0130-c000-000000131346"
11: }
12:
13: if (Get-SPEnterpriseSearchMetadataManagedProperty
14: -SearchApplication $searchapp -Identity "MetadataPorpertyExample"
15: -ea "silentlycontinue") {
16: write-host -f Green "MetaProperty already exists,
17: we delete it so it can be reacreated "
18: $prop = Get-SPEnterpriseSearchMetadataManagedProperty
19: -SearchApplication $searchapp -Identity "PublishingPageContent"
20: $prop.DeleteAllMappings()
21: $prop.Delete()
22: $searchapp.Update()
23: } else {}
24:
25: write-host -f Green "Try to create MetaProperty"
26: $prop = New-SPEnterpriseSearchMetadataManagedProperty
27: -SearchApplication $searchapp -Name "PublishingPageContent" -Type 1
28: $prop.EnabledForScoping = $true
29: $prop.Update()
30:
31: New-SPEnterpriseSearchMetadataMapping -SearchApplication
32: $searchapp -ManagedProperty $prop -CrawledProperty $crawlprop
After that i can create scopes (my colleague Peter found it out), where I check if a scope already exists and if so delete it so it can be recreated again:
1: if (Get-SPEnterpriseSearchQueryScope -SearchApplication $searchapp
2: -Identity "ScopeExample" -ea "silentlycontinue") {
3: write-host -f Green "Scope already exists,
4: we delete it so it can be reacreated "
5: $scope= Get-SPEnterpriseSearchQueryScope -SearchApplication
6: $searchapp -Identity "ScopeExample"
7: $scope.Delete();
8: $searchapp.Update();
9: } else {}
10:
11: # Create "ScopeExample" scope
12: $scope = New-SPEnterpriseSearchQueryScope -Name "ScopeExample"
13: -Description "Doorzoek alle informatie" -SearchApplication $searchapp
14: -DisplayInAdminUI $true
15:
16: New-SPEnterpriseSearchQueryScopeRule -RuleType AllContent
17: -Url $url -scope $scope
And after that in finally can reset my index, and make sure everything is found:
1: Write-Host -f Green "Delete current index ...";
2: $searchapp.Reset($true, $true)
3:
4: Write-Host -f Green "Start indexing and scopecompilation ";
5: $searchapp.StartScopesCompilation()
6:
7: $CrawlContents = Get-SPEnterpriseSearchServiceApplication
8: | Get-SPEnterpriseSearchCrawlContentSource
9:
10: foreach ($crawlcontent in $CrawlContents)
11: { $crawlcontent.StartFullCrawl(); }
Thursday, May 26, 2011
Skype has stopped working
A small number of you may have had problems signing in to Skype. This predominantly affects people using Skype for Windows. Skype has identified the problem and will issue a fix in the next few hours.
In the meantime, you can follow the steps below to fix the problem manually.
Windows
- If the Skype icon is displayed in the system tray at the bottom right of the screen, right-click it and select Quit.
- Click Start, type "run" and press Enter. (On Windows XP: Click Start and then Run.)
- Type "%appdata%\skype" and click OK.
- Locate and delete the file shared.xml. The file may be displayed as shared if file extensions are not displayed by default on your computer.
- If you cannot find this file:
- Click Start, type "run" and press Enter. (On Windows XP: Click Start and then Run.)
- Type "control folders" and click OK.
- In the View tab, ensure that Show hidden files and folders is enabled.
- Repeat the instructions from the beginning.
- Restart Skype.
Mac
- Open Finder and locate the following folder:
- Delete the file shared.xml.
- Restart Skype.
~/Library/Application Support/Skype
The ~ sign means your home folder. You can find your home folder by opening Finder and selecting Go> Home from the menu bar or pressing Command (Apple), Shift and H keys at the same time.
Linux
- Go to the following folder:
- Delete the file shared.xml.
- Restart Skype.
/home/YourLinuxUserName/.Skype
The Skype folder is a hidden folder - please check Show hidden files in your file browser to view and access it.
Subscribe to:
Posts (Atom)