Příspěvky

Zobrazují se příspěvky se štítkem PowerShell

Disable Lync accounts for users disabled in AD

Obrázek
Hi all, few days ago I had to do some clean up tasks at one of our customer. Goal was to disable Lync accounts for users, that do not work for company anymore. It seems like a powershell mission. To get list of disabled AD accounts that still have enabled Lync you can use following line: Get -CsAdUser   -ResultSize   Unlimited |  Where-Object   {$_.UserAccountControl  -match "AccountDisabled"   -and   $_.Enabled  -eq   $true } |  Format-Table   Name,Enabled,SipAddress  -auto Then you can easily remove Lync account by using following line: Get -CsAdUser   -ResultSize   Unlimited |  Where-Object   {$_.UserAccountControl  -match "AccountDisabled"   -and   $_.Enabled} | Disable -CsUser

Set up Auto Logon in Windows using PowerShell

Obrázek
Hello Guys, Did you ever felt the need to set up Auto logon to Windows Server or Workstation? Sometimes it is needed. Especialy in Internet Coffee's, or similar places. There is an old way to setup it using Regedit. But there is also way to use PowerShell to accomplish it. Take a look on two simple functions. This function are easy to use in you scripts. I am using it for building testing environement. All You need to do, is to set up $PlainTextAccount and $PlainTextPassword variables.

Lync 2013 Clear Persistent Chat Room Content

Obrázek
Hello Guys! In Lync 2013 we have an option delete all or partial content of Persistent Chat Room! This can be easily done by powershell cmdlet Clear-CsPersistentChatRoom. Detail description of that cmdlet can be found here: http://technet.microsoft.com/en-us/library/jj204976.aspx And now some examples: his example will remove all content before 1.1.2014 from PChatRoom: Clear-CsPersistentChatRoom -Identity "contoso.com\PChatRoom" -EndDate "1/1/2014" This example will remove all content before 1/1/2014 from all Persistech Chat Rooms: Get-CsPersistentChatRoom | Clear-CsPersistentChatRoom -EndDate "1/1/2014" -Confirm: $False This example will remove content older 180 days from all Persistech Chat Rooms: Get-CsPersistentChatRoom | Clear-CsPersistentChatRoom -EndDate ( [ DateTime ]:: today . AddDays( -180 )) -Confirm: $false

Add-PSSnapin

Obrázek
As a Sysadmin I have to running scripts repeatedly. Sometimes I am using powershell snapins like ActiveRoles Management Shell or Exchange Management shell. And then annoying message will appear Try to use code bellow in your scripts. You will never see error message again :)

Remove-Diacritics

Obrázek
Hi guys, it is easy write Powershell script to create users based on the settings in CSV file. Much more difficult is naming convention for logon names. Few month ago I found pretty little function to remove diacritics from string. It is really easy to use this function: $newString = Remove-Diacritics ( "ěščřžžřýí" ) or Write-host ( Remove-Diacritics ( "ěščřžřžý" ))

Delete files and folders

Obrázek
The most of us had to delete files or folders in our scripts. This is truly simple task with powershell. There is cmdlet Remove-Item to delete files and folders. Example for delete file in PowerShell. remove-item c:\Temp\text.txt -force Switch -Force is used to delete protected files. But what will happend if file doesn’t exist? You’ll get an error message. This is the reason to do check if file exist first. To accomplish this, we will use test-path cmdlet. $strFileName = "c:\temp\test.txt" If ( Test-Path $strFileName ) { Remove-Item $strFileName -Force } The similar code can be used for folders. But there is little difference in folders. There can be additional content in folder, you want to remove. So you should use switches -recurse -force. $strFolderName = "c:\temp" If ( Test-Path $strFolderName ) { Remove-Item $strFolderName -recurse -force } This code will remove, folder with all content! So be careful! ...