<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell Daily &#187; foreach</title>
	<atom:link href="http://proproit.com/tag/foreach/feed/" rel="self" type="application/rss+xml" />
	<link>http://proproit.com</link>
	<description>Using PowerShell in Real Life Daily</description>
	<lastBuildDate>Thu, 11 Oct 2012 08:19:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Inherit all Site Content from Root Site and Add Three AD groups</title>
		<link>http://proproit.com/sharepoint/inherit-all-site-content-from-root-site-and-add-three-ad-groups/</link>
		<comments>http://proproit.com/sharepoint/inherit-all-site-content-from-root-site-and-add-three-ad-groups/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 06:06:44 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[AllWebs]]></category>
		<category><![CDATA[Contribute]]></category>
		<category><![CDATA[descendant]]></category>
		<category><![CDATA[Dispose]]></category>
		<category><![CDATA[folders]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[FrontEnd]]></category>
		<category><![CDATA[HasUniqueRoleAssignments]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[Lists]]></category>
		<category><![CDATA[owner]]></category>
		<category><![CDATA[ownergroup]]></category>
		<category><![CDATA[PermissionLevel]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Read-Host]]></category>
		<category><![CDATA[ResetRoleInheritance]]></category>
		<category><![CDATA[security group]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[site url]]></category>
		<category><![CDATA[siteurl]]></category>
		<category><![CDATA[snapin]]></category>
		<category><![CDATA[SPSite]]></category>
		<category><![CDATA[SPUser]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=316</guid>
		<description><![CDATA[In one of my recent projects it was needed to inherit all descendant content permissions on root site from its parent.
I prepared this script to inherit all content permissions from root site which include all subsites, lists, folders and even items.
It just asking for site collection URL and three major AD groups which should have full, contribute and read access but providing of this access could be easily removed from the script.]]></description>
				<content:encoded><![CDATA[<p>In one of my recent projects it was needed to inherit all descendant content permissions on root site from its parent.</p>
<p>I prepared this script to inherit all content permissions from root site which include all subsites, lists, folders and even items.</p>
<p>It just asking for site collection URL and three major AD groups which should have full, contribute and read access but providing of this access could be easily removed from the script.</p>
<pre class="brush: ps">
#getting input from console
$siteurl = Read-Host ("Please enter site URL")
$ownergroup = Read-Host ("Please enter owner security group")
$writegroup = Read-Host ("Please enter write security group")
$readgroup = Read-Host ("Please enter read security group")
$site = Get-SPSite $siteurl

#adding new AD groups in SharePoint and giving them particular permissions
New-SPUser -UserAlias $ownergroup -Web $site.Url -PermissionLevel "Full Control" | foreach {$ownergroup + ", Full Control"}
New-SPUser -UserAlias $writegroup -Web $site.Url -PermissionLevel "Contribute" | foreach {$writegroup + ", Contribute"}
New-SPUser -UserAlias $readgroup -Web $site.Url -PermissionLevel "Read" | foreach {$readgroup + ", Read"}

#recursive inheritance for all subsite
foreach($subsite in $site.AllWebs)
    { 
    if ($subsite.HasUniqueRoleAssignments)
        {
        ”Site, ” + $subsite.Url
        $subsite.ResetRoleInheritance()
        $subsite.Update()
        }
#recursive inheritance for all lists in this particular subsite in cycle
    foreach($list in $subsite.Lists)
        {
        if ($list.HasUniqueRoleAssignments)
            {
            ”List, ” + $list.Title
            $list.ResetRoleInheritance()
            $list.Update()
            }
#recursive inheritance for all folders in this particular list in cycle
         foreach ($folder in $list.Folders)
            {
            if ($folder.HasUniqueRoleAssignments)
                {
                ”Folder, ” + $folder.Name + “  ” + $folder.Title
                $folder.ResetRoleInheritance()
                $folder.Update()
                }
            }
#recursive inheritance for all item in this particular folder in cycle
        foreach ($item in $list.Items)
            {
            if ($item.HasUniqueRoleAssignments)
                {
                ”Item, ” + $item.Name + “  ” + $item.Title
                $item.ResetRoleInheritance()
                $item.Update()
                }
            }
        } 
 $subsite.Dispose()
    }
$site.Dispose() 
</pre>
<p>P.S. This script should be used on Web FrontEnd Sharepoint Server with adding PS Snapin Microsoft.SharePoint.PowerShell</p>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/sharepoint/inherit-all-site-content-from-root-site-and-add-three-ad-groups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Office Project Professional 2010 Remote Uninstall</title>
		<link>http://proproit.com/wmi/microsoft-office-project-professional-2010-remote-uninstall/</link>
		<comments>http://proproit.com/wmi/microsoft-office-project-professional-2010-remote-uninstall/#comments</comments>
		<pubDate>Fri, 25 May 2012 10:45:52 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[Installation]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft office]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[project professional]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[remote computer]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[wmi]]></category>
		<category><![CDATA[WmiObject]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=286</guid>
		<description><![CDATA[Here is an example how to uninstall Microsoft Office Project Professional 2010 remotely.]]></description>
				<content:encoded><![CDATA[<p>Here is an example how to uninstall Microsoft Office Project Professional 2010 remotely.<br />
This script include these steps:<br />
1. Getting the list of computers and performs actions following actions on them<br />
2. Check if it is pinging, if there is installed Microsoft Office Project Professional 2010 using wmi<br />
3. Creates a job with invoke-command for particular computer with these steps:<br />
    a. Creates file config.xml in C:\Windows\Temp (for silent uninstall command)<br />
    b. Checks remote computer architecture (x32 or x64)<br />
    c. Runs this command which performs silent uninstall: &#8220;C:\Program Files\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\setup.exe&#8221; /UNINSTALL PRJPRO /CONFIG &#8220;C:\Windows\Temp\config.xml&#8221;<br />
    d. Register Event: if changes the job state than performs checking if this computer still has Microsoft Office Project Professional 2010 in installed programs<br />
    c. Depending on result in checking existence of Microsoft Office Project Professional 2010 after uninstall command it writes to the host if job passed or failed.</p>
<pre class="brush: ps">
"PC01" | ForEach-Object {
    if (Test-Connection $_ -Quiet -Count 1)
        {
        $pcname=$_
        if (Get-WmiObject win32_product -ComputerName $pcname -Filter "Caption='Microsoft Office Project Professional 2010'")
            {
            $pcname
            $job = Invoke-Command -ComputerName $pcname -AsJob -ScriptBlock `
                {
                New-Item -Path C:\Windows\Temp -Name config.xml -ItemType "file" -Value `
                        '
                        <Configuration Product="PrjPro">
	                        <Display Level="None" CompletionNotice="No" SuppressModal="Yes" AcceptEula="Yes" /> 
	                        <Logging Type="standard" Path="%temp%" Template="Microsoft Office Project Professional Setup(*).txt" />
	                        <OptionState Id="OptionID" State="absent" Children="force" />
	                        <Setting Id="SETUP_REBOOT" Value="Never" />
                        </Configuration>
                        '
                if([IntPtr]::Size -eq 4)
                    {
                    Start-Process -PassThru -Verb RunAs -FilePath "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\setup.exe" -ArgumentList '/UNINSTALL PRJPRO /CONFIG "C:\Windows\Temp\config.xml"' -Wait
                    }
                Else
                    {                        
                    Start-Process -PassThru -Verb RunAs -FilePath "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\setup.exe" -ArgumentList '/UNINSTALL PRJPRO /CONFIG "C:\Windows\Temp\config.xml"' -Wait
                    }
                }
            Register-ObjectEvent $job StateChanged -Action `
                {
                if (Get-WmiObject win32_product -Filter "Caption='Microsoft Office Project Professional 2010'")
                    {
                    Write-Host "Job #$($sender.Id) ($($sender.Location)) failed" -ForegroundColor Red
                    }
                else
                    {
                    Write-Host "Job #$($sender.Id) ($($sender.Location)) completed" -ForegroundColor Green
                    }
                }
            }
        }
    }
</pre>
<p>P.S. Please take into consideration that PowerShell Remoting should be enabled on all computers where do you want to perform uninistall:</p>
<ul>
<li>$Host.Version 3.0 Beta</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/wmi/microsoft-office-project-professional-2010-remote-uninstall/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get Currently Logged On User</title>
		<link>http://proproit.com/wmi/get-currently-logged-on-user/</link>
		<comments>http://proproit.com/wmi/get-currently-logged-on-user/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 13:55:40 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[ActiveRoles]]></category>
		<category><![CDATA[address]]></category>
		<category><![CDATA[ADManagement]]></category>
		<category><![CDATA[computerName]]></category>
		<category><![CDATA[Computersystem]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[Logged]]></category>
		<category><![CDATA[OSName]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[QADComputer]]></category>
		<category><![CDATA[QADUser]]></category>
		<category><![CDATA[Quest]]></category>
		<category><![CDATA[Quiet]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[username]]></category>
		<category><![CDATA[WmiObject]]></category>
		<category><![CDATA[workstation]]></category>
		<category><![CDATA[workstation name]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=259</guid>
		<description><![CDATA[I simply put the workstation name and run the script. The result is in output window in comma separated view: workstation name, NT user account name, and user's e-mail address taken from AD]]></description>
				<content:encoded><![CDATA[<p>This is the most often used script. I am using it whenever someone wants to know who is logged on to that workstation or I need to do something on that workstation remotely.</p>
<p>I simply put the workstation name and run the script. The result is in output window in comma separated view: workstation name, NT user account name, and user&#8217;s e-mail address taken from AD.</p>
<pre class="brush: ps">Get-QADComputer -Name workstation -osname *XP* | sort name | foreach `
    {
    if (Test-Connection $_.name -Quiet)
        {
        $name = $_.name
        $name + ", " + `
        ((Get-WmiObject Win32_ComputerSystem -ComputerName $name -EA Stop).UserName) + ", " + `
        (Get-QADUser (((Get-WmiObject Win32_ComputerSystem -ComputerName $name -EA Stop).UserName)) -EA Stop | foreach {$_.email})
        trap {$name + ", " + "{0}" -f $_.Exception.Message; continue}
        }
    else
        {
        $_.name + ", don't respond"
        }
    }</pre>
<p>P.S. I am using:</p>
<ul>
<li>$Host.Version 3.0 Preview</li>
<li>Quest.ActiveRoles.ADManagement 1.4.0.2139</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/wmi/get-currently-logged-on-user/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Outlook Signature</title>
		<link>http://proproit.com/activedirectory/outlook-signature/</link>
		<comments>http://proproit.com/activedirectory/outlook-signature/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 15:19:02 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[ADCompany]]></category>
		<category><![CDATA[ADStreetAddress]]></category>
		<category><![CDATA[ADTelePhoneNumber]]></category>
		<category><![CDATA[City]]></category>
		<category><![CDATA[CompanyRegPath]]></category>
		<category><![CDATA[custom variables]]></category>
		<category><![CDATA[default signature]]></category>
		<category><![CDATA[department]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[EmailOptions]]></category>
		<category><![CDATA[EmailSignature]]></category>
		<category><![CDATA[environment variables]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[exclusions]]></category>
		<category><![CDATA[force]]></category>
		<category><![CDATA[ForcedSignatureNew]]></category>
		<category><![CDATA[ForcedSignatureReplyForward]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[ForEach-object]]></category>
		<category><![CDATA[forward messages]]></category>
		<category><![CDATA[HKCU]]></category>
		<category><![CDATA[html rtf]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[LoadWithPartialName]]></category>
		<category><![CDATA[LocalSignaturePath]]></category>
		<category><![CDATA[LogonName]]></category>
		<category><![CDATA[match]]></category>
		<category><![CDATA[Message]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[phoneNumber]]></category>
		<category><![CDATA[ReplyMessageSignature]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Selection]]></category>
		<category><![CDATA[signature files]]></category>
		<category><![CDATA[signatures]]></category>
		<category><![CDATA[SignatureSourceFiles]]></category>
		<category><![CDATA[SignatureVersion]]></category>
		<category><![CDATA[SigVersion]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[specialist]]></category>
		<category><![CDATA[StreetAddress]]></category>
		<category><![CDATA[telephonenumber]]></category>
		<category><![CDATA[txt]]></category>
		<category><![CDATA[username]]></category>
		<category><![CDATA[using microsoft word]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=155</guid>
		<description><![CDATA[This is a script for generating a unique Outlook signatures for users based on their information taken from Active Directory.]]></description>
				<content:encoded><![CDATA[<p>This is a script for generating a unique Outlook signatures for users based on their information taken from Active Directory.</p>
<p>For source files you should create an .html, .rtf and .txt files like <a title="these templates" href="http://proproit.com/uploads/Signature.zip" target="_blank">these templates</a> where using Microsoft Word create for each of entries corresponding bookmarks.<br />
The simplest way is to edit above templates to fit to your organization needs.</p>
<p>Thanks for Jan Egil Ring. This script is based on his script</p>
<pre class="brush: ps">#Custom variables
$CompanyName = 'Default'
$DomainName = 'domain.com'
#When the version number are updated the local signature are re-created. The value of this variable will be stored in appropriate registry value and every log on compared to it
$SigVersion = '1.0'
$SigSource = "\\domain.com\NETLOGON\Signature\Files"
#When set to 1 the signature is enforced as default signature for new messages. 0 = no force, 1 = force
$ForceSignatureNew = '1'
#When set to 1 the signature is enforced as default signature for reply/forward messages. 0 = no force, 1 = force
$ForceSignatureReplyForward = '0'

#Environment variables
$AppData=(Get-Item env:appdata).value
$SigPath = '\Microsoft\Signatures'
$LocalSignaturePath = $AppData+$SigPath

#Get Active Directory information for current user
$UserName = $env:username
$Filter = "(&amp;(objectCategory=User)(samAccountName=$UserName))"
$Searcher = New-Object System.DirectoryServices.DirectorySearcher
$Searcher.Filter = $Filter
$ADUserPath = $Searcher.FindOne()
$ADUser = $ADUserPath.GetDirectoryEntry()
$ADDisplayName = $ADUser.DisplayName
$ADTitle = $ADUser.Title
$ADCompany = $ADUser.Company
$ADDepartment = $ADUser.Department
$ADStreetAddress = $ADUser.StreetAddress
$ADCity = $ADUser.l
$ADTelePhoneNumber = $ADUser.TelephoneNumber
$ADFax = $ADUser.facsimiletelephonenumber
$ADmail = $ADUser.mail
$ADsamaccountname = $ADUser.samaccountname

#Here the script is checking for exclusions for which users do not use this script.
#For example where not installed Outlook
if ($ADsamaccountname -match "logonname" -or `
    $ADTitle -match "Cashier")
    {break;}

#Setting registry information for the current user.
#Putting a new key with company name to the registry and creating signature settings there
$CompanyRegPath = "HKCU:\Software\"+$CompanyName
if (Test-Path $CompanyRegPath){}
else {New-Item -path "HKCU:\Software" -name $CompanyName}
if (Test-Path $CompanyRegPath'\Outlook Signature Settings'){}
else {New-Item -path $CompanyRegPath -name "Outlook Signature Settings"}
$ForcedSignatureNew = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ForcedSignatureNew
$ForcedSignatureReplyForward = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ForcedSignatureReplyForward
$SignatureVersion = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').SignatureVersion
Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name SignatureSourceFiles -Value $SigSource
$SignatureSourceFiles = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').SignatureSourceFiles

#Forcing signature for new messages if enabled
if ($ForcedSignatureNew -eq '1')
    {

#Set company signature as default for New messages
    [Void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Word")
    $MSWord = New-Object -com word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    $EmailSignature.NewMessageSignature=$CompanyName
    $MSWord.Quit()
    }

#Forcing signature for reply/forward messages if enabled
if ($ForcedSignatureReplyForward -eq '1')
    {

#Set company signature as default for Reply/Forward messages
    [Void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Word")
    $MSWord = New-Object -com word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    $EmailSignature.ReplyMessageSignature=$CompanyName
    $MSWord.Quit()
    }

#Copying signature sourcefiles and creating signature if signature-version are different from local version
#In some case there are a problem when copying a signature but not substitute user AD information
#Or if this information is changing by HR specialist in AD. It should be actual after relog
if (
   $SignatureVersion -ne $SigVersion -or `
   !(Test-Path ($LocalSignaturePath+'\'+$CompanyName+'.log')) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "DisplayName: ") -notlike ("DisplayName: "+$ADDisplayName) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "Title: ") -notlike ("Title: "+$ADTitle) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "Company: ") -notlike ("Company: "+$ADCompany) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "Department: ") -notlike ("Department: "+$ADDepartment) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "StreetAddress: ") -notlike ("StreetAddress: "+$ADStreetAddress) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "City: ") -notlike ("City: "+$ADCity) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "TelePhoneNumber: ") -notlike ("TelePhoneNumber: "+$ADTelePhoneNumber) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "Fax: ") -notlike ("Fax: "+$ADFax) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.log') | Select-String "mail: ") -notlike ("mail: "+$ADmail) -or `
   (Get-Content ($LocalSignaturePath+'\'+$CompanyName+'.htm') | Select-string ">DisplayName<")
 )
 {
#Copy signature templates from domain to local Signature-folder
 Copy-Item "$SignatureSourceFiles\*" $LocalSignaturePath -Recurse -Force

#Insert variables from Active Directory to rtf signature-file
 [Void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Word")
 $MSWord = New-Object -com word.application
 $MSWord.Documents.Open($LocalSignaturePath+'\'+$CompanyName+'.rtf')

 ($MSWord.ActiveDocument.Bookmarks.Item("DisplayName")).Select()
 $MSWord.Selection.Text=$ADDisplayName
 "DisplayName: "+$ADDisplayName &gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("Title")).Select()
 $MSWord.Selection.Text=$ADTitle
 "Title: "+$ADTitle &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("Company")).Select()
 $MSWord.Selection.Text=$ADCompany
 "Company: "+$ADCompany &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("Department")).Select()
 $MSWord.Selection.Text=$ADDepartment
 "Department: "+$ADDepartment &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("StreetAddress")).Select()
 $MSWord.Selection.Text=$ADStreetAddress
 "StreetAddress: "+$ADStreetAddress &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("City")).Select()
 $MSWord.Selection.Text=$ADCity
 "City: "+$ADCity &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("phoneNumber")).Select()
 $MSWord.Selection.Text=$ADTelePhoneNumber
 "TelePhoneNumber: "+$ADTelePhoneNumber &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("Fax")).Select()
 $MSWord.Selection.Text=$ADFax
 "Fax: "+$ADFax &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument.Bookmarks.Item("mail")).Select()
 $MSWord.Selection.Text=$ADmail
 "mail: "+$ADmail &gt;&gt; ($LocalSignaturePath+'\'+$CompanyName+'.log')

 ($MSWord.ActiveDocument).Save()
 ($MSWord.ActiveDocument).Close()
 $MSWord.Quit()

#Insert variables from Active Directory to htm signature-file
 [Void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Word")
 $MSWord = New-Object -com word.application

 $MSWord.Documents.Open($LocalSignaturePath+'\'+$CompanyName+'.htm')

 ($MSWord.ActiveDocument.Bookmarks.Item("DisplayName")).Select()
 $MSWord.Selection.Text=$ADDisplayName

 ($MSWord.ActiveDocument.Bookmarks.Item("Title")).Select()
 $MSWord.Selection.Text=$ADTitle

 ($MSWord.ActiveDocument.Bookmarks.Item("Company")).Select()
 $MSWord.Selection.Text=$ADCompany

 ($MSWord.ActiveDocument.Bookmarks.Item("Department")).Select()
 $MSWord.Selection.Text=$ADDepartment

 ($MSWord.ActiveDocument.Bookmarks.Item("StreetAddress")).Select()
 $MSWord.Selection.Text=$ADStreetAddress

 ($MSWord.ActiveDocument.Bookmarks.Item("City")).Select()
 $MSWord.Selection.Text=$ADCity

 ($MSWord.ActiveDocument.Bookmarks.Item("phoneNumber")).Select()
 $MSWord.Selection.Text=$ADTelePhoneNumber

 ($MSWord.ActiveDocument.Bookmarks.Item("Fax")).Select()
 $MSWord.Selection.Text=$ADFax

 ($MSWord.ActiveDocument.Bookmarks.Item("mail")).Select()
 $MSWord.Selection.Text=$ADmail

 ($MSWord.ActiveDocument).Save()
 ($MSWord.ActiveDocument).Close()
 $MSWord.Quit()

#Insert variables from Active Directory to txt signature-file
(Get-Content $LocalSignaturePath'\'$CompanyName'.txt') | Foreach-Object {$_ `
 -replace "DisplayName", $ADDisplayName `
 -replace "Title", $ADTitle `
 -replace "Company", $ADCompany `
 -replace "Department", $ADDepartment `
 -replace "StreetAddress", $ADStreetAddress `
 -replace "City", $ADCity `
 -replace "PhoneNumber", $ADTelePhoneNumber `
 -replace "Fax", $ADFax `
 -replace "mail", $ADmail} | Set-Content $LocalSignaturePath'\'$CompanyName'.txt'
 }
else {}

#Stamp registry-values for Outlook Signature Settings if they doesn`t match the initial script variables.
#Note that these will apply after the second script run when changes are made in the "Custom variables"-section.
if ($ForcedSignatureNew -eq $ForceSignatureNew){}
else {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ForcedSignatureNew -Value $ForceSignatureNew}
if ($ForcedSignatureReplyForward -eq $ForceSignatureReplyForward){}
else {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ForcedSignatureReplyForward -Value $ForceSignatureReplyForward}
if ($SignatureVersion -eq $SigVersion){}
else {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name SignatureVersion -Value $SigVersion}</pre>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/activedirectory/outlook-signature/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Which User is Logged in to Workstation</title>
		<link>http://proproit.com/wmi/which-user-is-logged-in-to-workstation/</link>
		<comments>http://proproit.com/wmi/which-user-is-logged-in-to-workstation/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 12:22:44 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[computerName]]></category>
		<category><![CDATA[Computersystem]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[error message]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[exception message]]></category>
		<category><![CDATA[file csv]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[Logged]]></category>
		<category><![CDATA[OSName]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[output string]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[QADComputer]]></category>
		<category><![CDATA[QADUser]]></category>
		<category><![CDATA[Quiet]]></category>
		<category><![CDATA[test connection]]></category>
		<category><![CDATA[trap name]]></category>
		<category><![CDATA[username]]></category>
		<category><![CDATA[windows xp]]></category>
		<category><![CDATA[wmi]]></category>
		<category><![CDATA[WmiObject]]></category>
		<category><![CDATA[workstation name]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=125</guid>
		<description><![CDATA[It is useful to know which user is logged in to the specified workstation]]></description>
				<content:encoded><![CDATA[<p>It is useful to know which user is logged in to the specified workstation.</p>
<p>For this I wrote this script.</p>
<pre class="brush: ps">
#getting the needed workstations. in this example all XPs in our domain
Get-QADComputer -OSName "Windows XP Professional" | foreach `
    {
#each of them is testing for ping. if it's pinging the script continue
    if (Test-Connection $_.name -Quiet)
        {
        $name = $_.name
#generates a string in which is workstation name; username; user's email        
        $name + ";" + `
        ((Get-WmiObject Win32_ComputerSystem -ComputerName $name -EA Stop).UserName) + ";" + `
        (Get-QADUser (((Get-WmiObject Win32_ComputerSystem -ComputerName $name -EA Stop).UserName)) -EA Stop | foreach {$_.email})
#this string is for trapping errors generating by last string and output workstation's name; error message
        trap {$name + ";" + "{0}" -f $_.Exception.Message; continue}
        }
    else
        {
#if the workstation do not pinging there are an output string with name;don't respond
        $_.name + ";don't respond"
        }
    }
</pre>
<p>It&#8217;s is possible to add >> c:\file.csv and import this list to excel.</p>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/wmi/which-user-is-logged-in-to-workstation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Servers&#8217; Models with WMI</title>
		<link>http://proproit.com/wmi/get-servers-models-with-wmi/</link>
		<comments>http://proproit.com/wmi/get-servers-models-with-wmi/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 06:45:19 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[boss]]></category>
		<category><![CDATA[brush]]></category>
		<category><![CDATA[computerName]]></category>
		<category><![CDATA[Computersystem]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[ErrorAction]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[HDD]]></category>
		<category><![CDATA[HideTableHeaders]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[match]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[necessary servers]]></category>
		<category><![CDATA[OSName]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[QADComputer]]></category>
		<category><![CDATA[Quiet]]></category>
		<category><![CDATA[RAM]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[silentlycontinue]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[test connection]]></category>
		<category><![CDATA[variable name]]></category>
		<category><![CDATA[win2k3]]></category>
		<category><![CDATA[wmi]]></category>
		<category><![CDATA[WmiObject]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=114</guid>
		<description><![CDATA[If your boss said to collect information about server's models for upgrading it's RAM or HDD you can use this script with help of WMI.]]></description>
				<content:encoded><![CDATA[<p>If your boss said to collect information about servers&#8217; models for upgrading it&#8217;s RAM or HDD you can use this script with help of WMI.</p>
<pre class="brush: ps">
#getting all computers with win2k8, you can use *2003* for win2k3
Get-QADComputer -osName *2008* | foreach `
    {
#if they are pinging     
    if (Test-Connection $_.name -Quiet)
        {
#if there are no problems with wmi access and server's model matching ml150
        if((Get-WmiObject -computername $_.name Win32_Computersystem -ErrorAction silentlycontinue).model -match "ML150")
            {
#assigning to variable name and model of that server
            $wmi = Get-WmiObject -computername $_.name Win32_Computersystem -ErrorAction silentlycontinue | ft name, model -HideTableHeaders
#checking wmi for errors if everithing is ok then output $wmi
            if (-not $wmi)
                {
                write-warning $_.name + ", WMI Error"
                }
            else
                {
                $wmi
                }
            }
        }
#and if server is not pinging, write it on the screen
    else
        {
        $_.name + ", don't respond"
        }
    }
</pre>
<p>After that you will receive the list without the headers of servers&#8217; names and models with are math ml150 in the model. You can use whatever you like in this statement or just delete this if statement for output all necessary servers and it&#8217; models.</p>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/wmi/get-servers-models-with-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change Outlook Account Settings</title>
		<link>http://proproit.com/outlook/change-outlook-account-settings/</link>
		<comments>http://proproit.com/outlook/change-outlook-account-settings/#comments</comments>
		<pubDate>Wed, 26 May 2010 12:26:16 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[account management]]></category>
		<category><![CDATA[account settings]]></category>
		<category><![CDATA[corporate users]]></category>
		<category><![CDATA[documents and settings]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[framework v2]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[machine software]]></category>
		<category><![CDATA[mail server name]]></category>
		<category><![CDATA[microsoft net framework]]></category>
		<category><![CDATA[microsoft powershell]]></category>
		<category><![CDATA[Name]]></category>
		<category><![CDATA[necessary files]]></category>
		<category><![CDATA[outlook account]]></category>
		<category><![CDATA[outlook profile]]></category>
		<category><![CDATA[profile files]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[snapin]]></category>
		<category><![CDATA[software microsoft]]></category>
		<category><![CDATA[test path]]></category>
		<category><![CDATA[windir]]></category>
		<category><![CDATA[windows registry editor]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=94</guid>
		<description><![CDATA[One day I have received the task to change mail server name and apply tls encryption for all our corporate users.]]></description>
				<content:encoded><![CDATA[<p>As you may know all Outlook account settings for user are stores in registry and it is hard to change some settings for big amount of users (for my example &#8211; 500).</p>
<p>One day I have received the task to change mail server name and apply tls encryption for all our corporate users. I&#8217;ve found an interesting powershell script for changing user account settings locally. And that&#8217;s what I needed is to copy all necessary files to user&#8217;s PC and make changes in account settings.</p>
<p>First of all you should download this snapin (<a href="http://psoutlookmanager.codeplex.com">http://psoutlookmanager.codeplex.com</a>) and use two dll&#8217;s from it which will allow to add snapin to your script (OutlookAccountManager.dll and OutlookAccountManagerPS.dll)</p>
<p>After that make a OutlookAccountManager.reg file (after adding it to registry snapin will be installed &#8211; the same thing as:</p>
<pre class="brush: ps">set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
cd

install OutlookAccountManagerPS.dll
</pre>
<p>)</p>
<p>with this content:</p>
<pre class="brush: plain">Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\OutlookAccountManagerSnapIn]
"PowerShellVersion"="2.0"
"Vendor"="Alessandro Pilotti"
"Description"="Provides Outlook account management cmdlets"
"VendorIndirect"="OutlookAccountManagerSnapIn,Alessandro Pilotti"
"DescriptionIndirect"="OutlookAccountManagerSnapIn,Provides Outlook account management cmdlets"
"Version"="1.0.0.0"
"ApplicationBase"="C:\\Documents and Settings\\All Users\\OutlookAccountManager"
"AssemblyName"="OutlookAccountManagerPS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=78530d5fb3fc68b4"
"ModuleName"="C:\\Documents and Settings\\All Users\\OutlookAccountManager\\OutlookAccountManagerPS.dll"
</pre>
<p>After these step it is needed to copy that dlls locally to use it. Follow this code to copy them locally (OutlookAccountManager.ps1):</p>
<pre class="brush: ps">$Sour = "\\domain\netlogon\Outlook.Profile\Files"
$Dest = $env:ALLUSERSPROFILE+"\OutlookAccountManager"
if (!(Test-Path "$Dest\OutlookAccountManagerPS.dll"))
    {
    Copy-Item $Sour -Destination $Dest -Recurse
    }
</pre>
<p>And finally it&#8217;s possible to make the essential script which changes all necessary outlook account settings (Outlook.Profile.ps1):</p>
<pre class="brush: ps">Add-PSSnapin OutlookAccountManagerSnapIn
$profile = Get-MAPIAccount "Outlook" | where-object {!$_.IsExchange}
$profile | foreach `
    {
    if (($_.OutgoingServer = "192.168.100.1") `
    -or ($_.IncomingServer = "192.168.100.1") `
    -or ($_.OutgoingServer = "mail.mail.com") `
    -or ($_.IncomingServer = "mail.mail.com"))
        {
        $_.OutgoingServer = "mail.new.com"
        $_.IncomingServer = "mail.new.com"
        $_.OutgoingSSL = $True;
        $_.OutgoingPort = 465;
        Set-MAPIAccount $_;
        }
    }
Remove-PSSnapin OutlookAccountManagerSnapIn
</pre>
<p>As you can see there are some of ifs. They are needed only for finding that outlook accounts which are related to our corporate network. It&#8217;s not changing that accounts which contain other mail servers.</p>
<p>And finally it is needed to put as startup scripts for whole domain following strings:</p>
<pre class="brush: plain">
powershell.exe -command "\\domain\netlogon\Outlook.Profile\OutlookAccountManager.ps1"
regedit.exe /s "\\domain\netlogon\Outlook.Profile OutlookAccountManager.reg"
</pre>
<p>and logon scripts:</p>
<pre class="brush: plain">
powershell.exe -command "\\domain\netlogon\Outlook.Profile\Outlook.Profile.ps1"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/outlook/change-outlook-account-settings/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Save Credentials for all Servers&#8217; RDP Connections</title>
		<link>http://proproit.com/activedirectory/save-credentials-for-all-servers-rdp-connections/</link>
		<comments>http://proproit.com/activedirectory/save-credentials-for-all-servers-rdp-connections/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 11:46:28 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[CMD]]></category>
		<category><![CDATA[ActiveRoles]]></category>
		<category><![CDATA[cmdkey]]></category>
		<category><![CDATA[Conections]]></category>
		<category><![CDATA[credential]]></category>
		<category><![CDATA[Credentials]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[OSName]]></category>
		<category><![CDATA[pass]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PSCX]]></category>
		<category><![CDATA[RDP]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[TERMSRV]]></category>
		<category><![CDATA[test connection]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=62</guid>
		<description><![CDATA[It was a big joy when I found a solution how to save my current windows credentials for all servers' rdp connections.]]></description>
				<content:encoded><![CDATA[<p>It was a big joy when I found a solution how to save my current windows credentials for all servers&#8217; rdp connections. We have more than 50 servers and it&#8217;s annoying to enter my credentials on every rdp connection to server. But can you imagine how it is hard for environment with 200 and even 1000 connections.</p>
<p>I&#8217;ve found a small utility in Windows 7 &#8211; my present host OS &#8211; cmdkey.exe which can add, change or delete credentials for many type of connections. For my purposes I&#8217;ve used TERMSRV.</p>
<p>If you are using Windows XP you can just copy this utility from Windows Server 2003 but not from Windows 7 or Windows Server 2008.</p>
<p>After changing my windows credential it is possible to run this script for saving your current windows credentials for rdp connections.</p>
<pre class="brush: ps">Get-QADComputer -OSName *2003 | foreach `
    {
    if(Test-Connection $_.name -quiet)
        {
        $pc=$_.name
        $pc
        cmdkey /generic:TERMRV/$pc /user:domain\user /pass:password
        }
    }
</pre>
<p>P.S. I am using:</p>
<ul>
<li>$Host.Version 2.0</li>
<li>Quest.ActiveRoles.ADManagement  1.3.0.1787</li>
<li>PSCX 1.2.0.0</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/activedirectory/save-credentials-for-all-servers-rdp-connections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a Domain Group to the Local Admins Group</title>
		<link>http://proproit.com/activedirectory/adding-a-domain-grou-to-the-local-admins-group/</link>
		<comments>http://proproit.com/activedirectory/adding-a-domain-grou-to-the-local-admins-group/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 20:40:52 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[administrators group]]></category>
		<category><![CDATA[Admins]]></category>
		<category><![CDATA[admins group]]></category>
		<category><![CDATA[adsi]]></category>
		<category><![CDATA[computerName]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[domain group]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[ForEach-object]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[Name]]></category>
		<category><![CDATA[OSName]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[QADComputer]]></category>
		<category><![CDATA[remote computer]]></category>
		<category><![CDATA[test connection]]></category>
		<category><![CDATA[txt]]></category>
		<category><![CDATA[user group]]></category>
		<category><![CDATA[winnt]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=55</guid>
		<description><![CDATA[This script adding domain group on all PCs with XP Professional in our environment and it's logging all PCs to txt file.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve needed to add a new domain group to local administrators group for this I&#8217;ve used ADSI. This script adding domain group on all PCs with XP Professional in our environment and it&#8217;s logging all PCs to txt file.</p>
<pre class="brush: ps">
# Add a domain user (group) to the local Administrators group on the local or a remote computer 
Get-QADComputer -OSName *Professional | ForEach-object `
    {
    if (Test-Connection $_.name -quiet)
        {
        $c=$_.name
        "----------$c---------"
        "----------$c---------" >> c:\administrators.txt
        trap
            {
            '{0}' -f $_.Exception.Message
            '{0}' -f $_.Exception.Message >> c:\administrators.txt;
            return
            }
        [string]$computerName = $c
        ([ADSI]"WinNT://$computerName/Administrators,group").Add("WinNT://domain/group") 
        }
    }
</pre>
<p>P.S. I am using:</p>
<ul>
<li>$Host.Version 2.0</li>
<li>Quest.ActiveRoles.ADManagement  1.3.0.1787</li>
<li>PSCX 1.2.0.0</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/activedirectory/adding-a-domain-grou-to-the-local-admins-group/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Users from AD to WSS</title>
		<link>http://proproit.com/activedirectory/users-from-ad-to-wss/</link>
		<comments>http://proproit.com/activedirectory/users-from-ad-to-wss/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 11:27:31 +0000</pubDate>
		<dc:creator>Mihail Stacanov</dc:creator>
				<category><![CDATA[ADDS]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[cmrecord]]></category>
		<category><![CDATA[contact list]]></category>
		<category><![CDATA[Contacts]]></category>
		<category><![CDATA[department]]></category>
		<category><![CDATA[Dispose]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[FirstName]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[internal phone number]]></category>
		<category><![CDATA[Job]]></category>
		<category><![CDATA[Lists]]></category>
		<category><![CDATA[LogonName]]></category>
		<category><![CDATA[microsoft sharepoint]]></category>
		<category><![CDATA[mob]]></category>
		<category><![CDATA[mobile phone number]]></category>
		<category><![CDATA[Name]]></category>
		<category><![CDATA[NoTypeInformation]]></category>
		<category><![CDATA[Photos]]></category>
		<category><![CDATA[pluses]]></category>
		<category><![CDATA[PSCX]]></category>
		<category><![CDATA[QADService]]></category>
		<category><![CDATA[Quest]]></category>
		<category><![CDATA[spitem]]></category>
		<category><![CDATA[splist]]></category>
		<category><![CDATA[SPSite]]></category>
		<category><![CDATA[StreetAddress]]></category>
		<category><![CDATA[title]]></category>
		<category><![CDATA[title sort]]></category>
		<category><![CDATA[windows sharepoint services]]></category>
		<category><![CDATA[WSS]]></category>

		<guid isPermaLink="false">http://proproit.com/?p=46</guid>
		<description><![CDATA[This script is copying all users which have department, title, which are enabled and copying them through the step of creating csv on disk to Windows SharePoint Services 3.0]]></description>
				<content:encoded><![CDATA[<p>This script is copying all users which have department, title, which are enabled and copying them through the step of creating csv on disk to Windows SharePoint Services 3.0<br />
Need to create a Contact list in Windows SharePoint Services 3.0.</p>
<pre class="brush: ps">
#add quest snappin
add-pssnapin Quest.ActiveRoles.ADManagement

#connect to domain (I have two domains)
connect-QADService -service 'domain.com'

#users from AD to CSV
get-qaduser -enabled | select-object LastName, FirstName, Department, PhoneNumber, Pager, Mobile, Email, Title, Office, City, StreetAddress, LogonName, Name | Where-Object {$_.department} | Where-Object {$_.Title} | Sort-Object Department | Export-Csv -NoTypeInformation "D:\Scripts\contacts2wss\Contacts.csv" -Delimiter ","

#remove pluses from phonenumber
(Get-Content "D:\Scripts\contacts2wss\Contacts.csv") | Foreach-Object {$_ -replace "\+", ""} | Set-Content "D:\Scripts\contacts2wss\Contacts.csv"

#connect to sharepoint
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site=new-object Microsoft.SharePoint.SPSite("http://wss/default.aspx")
$web=$site.rootweb
$splist=$web.Lists["Contact Information"]
$allitems = $splist.items;
$count=$allitems.count-1

get-date > D:\Scripts\contacts2wss\log.txt

#delete all items
for($intIndex=$count;$intIndex-gt-1;$intIndex--)
{
       "Deleting : " + $intIndex >> D:\Scripts\contacts2wss\log.txt
        $allItems.Delete($intIndex);
} 

#import csv
$records = import-csv "D:\Scripts\contacts2wss\Contacts.csv"

#add all items from csv
foreach($cmrecord in $records)
	{
        "Adding : " + $cmrecord.LastName + " " + $cmrecord.FirstName >> D:\Scripts\contacts2wss\log.txt
        $spitem = $spList.Items.Add()
        $spitem["Last Name"] = $cmrecord.LastName
        $spitem["First Name"] = $cmrecord.FirstName
        $spitem["Department"] = $cmrecord.Department
        $spitem["Phone Number"] = $cmrecord.PhoneNumber
        $spitem["Internal Phone Number"] = $cmrecord.Pager
        $spitem["Mobile Phone Number"] = $cmrecord.mobile
        $spitem["E-mail Address"] = $cmrecord.Email
        $spitem["Job Title"] = $cmrecord.Title
        $spitem["Office"] = $cmrecord.Office
        $spitem["City"] = $cmrecord.City
        $spitem["Address"] = $cmrecord.StreetAddress
        
        #taking photos
        $name = $cmrecord.LogonName
        $destination = "\\wss\Contacts\Photos\$name.jpg"
        $spitem["Photo"] = "$destination, "
        
        $spitem.Update() 
	}
Write-Host "List was recreated successfully" >> D:\Scripts\contacts2wss\log.txt
$web.Dispose()
$site.Dispose()
remove-pssnapin Quest.ActiveRoles.ADManagement
</pre>
<p>An important thing is that before setup this script you should create a list &#8220;Contact Information&#8221; from Contacts Template and add from List Settings &#8220;Add from existing site columns&#8221; all required columns to it.</p>
<p>In my example after connecting this list to outlook there are everything ok except photos.</p>
<p>P.S. I am using:</p>
<ul>
<li>$Host.Version 2.0</li>
<li>Quest.ActiveRoles.ADManagement  1.3.0.1787</li>
<li>PSCX 1.2.0.0</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://proproit.com/activedirectory/users-from-ad-to-wss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
