• Powershell: How to re-provsion the sync DB to resolve the issue that User Profile Synchronization Service fails to start?

    You can use the below script:

    ==================================

    Get-SPDatabase $syncdb=Get-SPDatabase -Id

    $syncdb.Unprovision()
    $syncdb.Status='Offline'
    Get-SPServiceApplication
    $upa=Get-SPServiceApplication - Id
    $upa.ResetSynchronizationMachine()
    $upa.ResetSynchronizationDatabase()
    $syncdb.Provision()


     

  • Powershell: How to restart the User Profile Synchronization Service if disabled?

    Below script shows how to restart the User Profile Synchronization Service if disabled.

     

    ============================================

    # Loads the SharePoint 2010 PowerShell extensions
    Add-PSSnapIn Microsoft.SharePoint.PowerShell 

    # Sets variable for User Profile Service Application: enter the name of your UPA in quotes, replacing the "UPA" example
    $upa = Get-SPServiceApplication |?{$_.displayname -eq "UPA"}

    # Sets variable for service instance: enter your User Profile Synchonization Service instance ID/GUID in quotes
    # which can be found by running "Get-SPServiceInstance" in PowerShell manually and copying the ID
    $profsync = Get-SPServiceInstance |?{$_.id -eq "382e333c-61f0-4107-ac5f-31aaf0a3aec3"}

    # Sets variables for farm account and password: enter your password in quotes
    $farmacctpwd = ConvertTo-SecureString -AsPlainText -String "Password1" -Force
    $farmacct = (get-spfarm).defaultserviceaccount

    # Sets variable for synchronization server: enter your server name in quotes
    $syncServer = "SharePoint1"
    if($profsync.Status -eq "disabled")
    {
      Write-Host "Provisioning User Profile Synchronization Service"
      $upa.SetSynchronizationMachine($syncServer, $profsync.ID, $farmacct.LookupName(), $farmacctpwd)
    }
    else
    {
      write-host "Profile Synchronization Service is"$profsync.Status
    }

  • CPP: How to wait on a job object?

    This is the sample code in CPP to show how to wait on a job object. In the documentation:

     

    The state of a job object is set to signaled when all of its processes are terminated because the specified end-of-job time limit has been exceeded. Use WaitForSingleObject or WaitForSingleObjectEx to monitor the job object for this event.

     

    If the processes terminate normally, then the job object is not signaled. To detect when all processes in a job have terminated, you need to associate the job with a completion port, and then listen on the I/O completion port for the JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO notification.

    =================================

    #define UNICODE

    #define _UNICODE

    #define STRICT

    #include
    <windows.h>

    #include
    <stdio.h>

    #include
    <atlbase.h>

    #include <atlalloc.h>

    #include
    <shlwapi.h>

     

    int __cdecl wmain(int argc, PWSTR argv[])

    {

       
    CHandle Job(CreateJobObject(nullptr, nullptr));

        if(!Job) {

           
    wprintf(L"Could not create job object, error %d\n", GetLastError());

           
    return 0;

        }

     

       
    CHandle IOPort(CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 1));

        if(!IOPort) {

           
    wprintf(L"Could not create IO completion port, error %d\n",GetLastError());

           
    return 0;

        }

     

       
    JOBOBJECT_ASSOCIATE_COMPLETION_PORT Port;

       
    Port.CompletionKey = Job;

       
    Port.CompletionPort = IOPort;

        if(!SetInformationJobObject(Job, JobObjectAssociateCompletionPortInformation,&Port, sizeof(Port))) {

           
    wprintf(L"Could not associate job with IO completion port, error %d\n", GetLastError());

           
    return 0;

        }

     

       
    PROCESS_INFORMATION ProcessInformation;

       
    STARTUPINFO StartupInfo = { sizeof(StartupInfo) };

       
    PWSTR CommandLine = PathGetArgs(GetCommandLine());

     

        if(!CreateProcess(nullptr, CommandLine, nullptr, nullptr, FALSE,CREATE_SUSPENDED, nullptr, nullptr, &StartupInfo, &ProcessInformation))
    {

           
    wprintf(L"Could not run process, error %d\n", GetLastError());

           
    return 0;

        }

     

        if(!AssignProcessToJobObject(Job, ProcessInformation.hProcess)) {

           
    wprintf(L"Could not assign process to job, error %d\n",
    GetLastError());

           
    return 0;

        }

     

       
    ResumeThread(ProcessInformation.hThread);

       
    CloseHandle(ProcessInformation.hThread);

       
    CloseHandle(ProcessInformation.hProcess);

     

       
    DWORD CompletionCode;

       
    ULONG_PTR CompletionKey;

       
    LPOVERLAPPED Overlapped;

     

       
    while (GetQueuedCompletionStatus(IOPort, &CompletionCode,&CompletionKey, &Overlapped, INFINITE) && CompletionCode !=JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO) {

           
    wprintf(L"Still waiting...\n");

        }

     

       
    wprintf(L"All done\n");

     

       
    return 0;

    }

  • Error "The certificate enrollment page you are attempting to access cannot be used with this version of Windows" after MS11-051 patch installation

    Symptom:

    You have Windows Server 2003 with installed Certification Authority and Web Enrollment components.

    When you try to access web enrollment pages from a Windows Vista-based (or newer) computer you receive error:

    The certificate enrollment page you are attempting to access cannot be used with this version of Windows. To enable Web certificate enrollment for clients running Windows Vista, your administrator must update all Windows CA Web enrollment pages. To learn more about this issue and the steps needed to update Web enrollment pages to support all versions of Windows, see:

    http://support.microsoft.com/kb/922706

    You installed MS11-051 by following KB922706 but you are still getting the same erro.

    Solution:

    1.  Uninstall Security Update MS11-051.
    2.  Install hot fix KB922706
    3.  Install Security Update MS11-051.
    4.  Type:  IISReset

    More information:

    Install KB922706 update. Use the links below to download appropriate update:
    Download link for Windows Server 2003 x86
    Download link for Windows Server 2003 x64

    Install MS11-051 security patch. Use the links below to download appropriate update:
    Download link for Windows Server 2003 x86
    Download link for Windows Server 2003 x64

    There is a more conprehensive article authored by Vadims Podans also talking about this issue, please see:

    http://en-us.sysadmins.lv/Lists/Posts/Post.aspx?ID=53

     


     

  • How to query network adapter for IPv6 protocol?

    Assuming you need it in script, PowerShell:

    # computername

    $MachineName = 'localhost'

     

    # open HKLM reg on $MachineName

    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $MachineName)

     

    # open subKey SYSTEM\CurrentControlSet\services\TCPIP6\Linkage

    $regKey = $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\TCPIP6\\Linkage")

     

    # get the values from the name 'Bind'

    # e.g. \Device\{A2B312D5-A133-4779-B21B-5B3ED82B6DCF}

    $bind = $regKey.GetValue("bind")

     

    # get adapters that are IP enabled : e.g. IPv4 or IPv6 is active

    $adapters = gwmi -computer $MachineName Win32_NetworkAdapterConfiguration|?{$_.IPEnabled}

     

    # for each adapter check if his GUID is in the Bind values and display info regarding IPv6 binding

    foreach ( $adap in $adapters)

       
    {

           
    # get GUID of the adapter

               
    $guid = $adap.SettingID

               
    # get the name of the adapter to be used to display info

           
    $name = (gwmi -computer $MachineName Win32_NetworkAdapter|?{$_.guid -eq $guid}).NetConnectionID

               
    # buid the \device\GUID string from the GUID of the adapter

           
    $device_guid = '\Device\'+$guid

               
    # check if the bind key contains the adapter guid

           
    if($bind -contains $device_guid)

                
    {write-host "Computer $MachineName -> IPv6 OK in adapter: $name" }

           
    else {write-host "Computer $MachineName -> IPv6 not bind on adapter: $name" }

       
    }

    Write `nDone