script (en)

script (en)

  • Mass modifying userWorkstations user attribute in Active Directory

    Adding computers to which users can logon in Active Directory - task that administrators must perform quite ofter. Moreover, sometimes you must provide this privilege to all users in domain.

    Here is the powershell script that will help you in this (it does not modify users that have rights to log on to ANY computers):

  • Generate complex password in two strings in Powershell Generate complex password in two strings in Powershell

    Usually, I generate passwords for my users by closing my eyes and chaotically pressing the buttons on keyboard. There is a new way now - I can generate it in Powershell easily:

  • Manage NTFS ACL (Access Control List) in Powershell

    How to simplify and make more easier managing access rights for files and folders and their inheritance? Take a note to use popular and useful script File System Security PowerShell Module. 

  • Export address book directly from the server in Lync 2010/2013 While working with address book in Lync Server, sometimes its very important and convinient to know, what exactly Lync Server have in its database regarding address book. You will need this, for example, when you working with Active Directory attributes that will be shown in contact card in Lync client.
  • Transaction log truncating in MS SQL Server 2005/2008/R2 In Microsoft SQL Server 2005/2008/R2 truncation of transaction log is different than in SQL Server 2000.
  • Searching the string in MS SQL Server database Sometimes, in troubleshooting and/or learning new software you need to find specific string or value in SQL database.

    Here is the script to run in Query Editor over the base to find some string. In "set @search_string = 'what.you.are.searching.for';" in quotes you must type in what you search.

    The script is compatible at least with SQL Server 2005/2008... hopefully with later versions also.
  • Enable Enterprise Voice for all users in Lync Server 2010/2013 Dont know, how is it going in your companies, but our users can call to any direction if they need it. In case of some issues, I can always apply restrictive policy.

    By default, when we add a user into Lync system, Enterprise Voice is disabled. Here is my way, how I solve this problem. You can also add this script to the script that enables new users in Lync.
  • Running Powershell script in scheduled task

    Like any other scripts, you will need to run Powershell-scripts not in manual mode, but as a scheduled task.

    For example, mass importing and actualizing Lync Server users database you will need to run every one-two-three hours.

    Of course, Task Scheduler in Windows should help in this issue, but how to run *.ps1 file?

  • Export Active Directory users to MS SQL Server

    Today's my script was written while i've been developing billing-system for Asterisk.

    Every user in Active Directory has an attribute with phone number. We will take this attribute and some others into MS SQL Server to use in billing.

    There are tons of scripts that can export AD users into scv-file, but none that will export users directly to SQL database. Of course we can export users into scv and then take this csv and import it into SQL database with the help of SSIS-scripts. But this method will generate two scripts, and if you have more than 5-10-15 AD domains, you will have 10-20-30 scripts, which is likely will lead to errors.
     

  • Export array (table) into csv-file in Powershell In your work in big arrays of data in Powershell, very often you will need to export data to table and after open this table in Excel. Its not recommended to code direct export from array into Excel-file, because you will need Excel installed on computer where you run the script. Also, such a code will run slowly.
    So, I've decided to export data to csv-file.
  • Computer Tabular Status for Approved Updates report in WSUS in Powershell Computer Tabular Status for Approved Updates report in WSUS in Powershell

    When you have many WSUS-servers with central server in your organization, it might be very difficult of getting reports from computers.

    Once I needed a script to show me, at which computers I don't have approved updates installed. There is a report in WSUS console that can give such info (it's called Computer Tabular Status for Approved Updates), but I was not able to go to every WSUS-server and run this report. Its a very weird task when you have 5-10-15 of WSUS-servers.

  • Solving problems with UAC in Windows Server 2012

    Suddenly for me, Veeam Backup & Replication started to throw errors while backing up some of my virtual machines. As I have managed to find out, root problem was in that Veeam could not run pre-freeze script to stop some services.

    Futher researches showed that UAC denied starting of scripts. When I tried to run script with elevated permissions, stop-start of services was performed without any problems.

  • Invoking commands in Linux systems via SSH with the help of Powershell

    In one of my projects, I was needed to write a script that will send SMS messages. We already had Linux server with GSM-modem that accepted commands sent by SSH. So, I was only needed to connect from Windows system to Linux with SSH protocol.

    I tried to use the SSH-Session module for Powershell, but it have some issues when sending commands. So I started to work with Posh-SSH module.

     

    Lets install Posh-SSH:

  • Deleting old files and folders in Powershell

    Task is clear from title - we need to delete old files from some directory. There are many cases in life, when you will need to perform such operation. For example - delete old backups.

  • Scripts for fast address book updating in Lync 2010/2013

    As you know, Lync have its own address book (AB) that downloaded by clients. By default, the download and update process of address boook in Lync 2010/2013 triggered in first 60 minutes (random time) after program start. In our company this situation was considered as wrong, thus I had to find solution how to ensure guaranteed updating of Lync address book right after the client starts. Also, there are other issues with delta-updating of address book, like a big delays (5-10 days) after changes in Active Directory are repliacted to Lync AB. 

    The consequences of such behavior:

  • Mass remote changing of DNS-servers in network interface (NIC) settings in Windows

    During upgrade of domain controllers or theirs addition\removal in Active Directory domain, there is always a need to change DNS-servers in network interfaces settings in Windows. On those computers or servers where you set network settings with DHCP - there is no problems. But on those where you configure settings manually, you will have to change them manually also. It is long and inconvinient.

  • Parsing sites and web-pages with Powershell / Invoke-WebRequest / getElementsByTagName and fight with performance

    Sometimes you need to parse some site or big web-page. Google offers many programs and even software complexes to perform this task, but I want to show, how you can quite simply do this with the help of Powershell.

    There is a Invoke-WebRequest cmdlet in Powershell, that actually parse HTML-page by tags and content. Cmdlet give you an object of page with ParsedHtml property. To this field you can apply methods to extract needed data.

    Assume you need to get all links from the page. See how it works.

  • Backing up the MS SQL (including Express) databases with Powershell script

    In free edition of the Microsoft SQL Server - Express - you have no possibility to schedule backups. But you can set up backups with the help of Powershell scripts and Windows Task Scheduler.

    Take a look at the script - that's my way to SQL backups. The script does not delete old backups, but please read my article Deleting old files and folders in Powershell, it will help. And also - Running Powershell script in scheduled task.

    Please notice highlighted lines - there you will have to set your SQL-instance and path to backups.

  • Moving Exchange 2013 logs from default folders with Powershell Moving Exchange 2013 logs from default folders with Powershell

    As you know, there are many types of Exchange 2013 logs, and a lot of disk space is used - and - space on system disk. Theoretically, you can change paths of all logs in Powershell. But because of number of logs types in Exchange, managing all these folders (and file sizes, directory sizes, max age of files) becomes a true nightmare.

    Thus I created for me and you a little memo in Powershell scripts, so I can run them after installing of next new server.

  • Mass import into MS SQL database script with Powershell Mass import into MS SQL database script with Powershell

    While I've been testing failover cluster of Microsoft SQL Server 2012 (more details: Step-by-step deploying AlwaysOn on MS SQL 2012) I was needed to generate mass import of some data into database.

    As soon as I'm very bad in T-SQL, I decided to write script on Powershell for this task.

    We will need:

    • Database itself
    • Table in it for testing purposes
  • How to remotely restart Windows service with Powershell How to remotely restart Windows service with Powershell

    In case if you need to remotely restart Windows service, here is my Powershell script.

    As soon as we have ICMP/ping disabled between our development environments, I've used WMI pings to determine, if remote machine is running.

  • Find servers with MS SQL Server installed with Powershell Find servers with MS SQL Server installed with Powershell

    Here is the script that will find servers in your domain with Microsoft SQL Server installed.

    Script can handle unresponsive servers with pings via WMI calls, which is useful if ICMP blocked for some reason. Also - I'm using Powershell Remoting, so please be sure it is enabled on your servers.

  • Get all images list for VMs in Azure Get all images list for VMs in Azure

    When you build your environment in Azure Cloud using IaaC (Infrastructure as a Code) approach, sometimes you will face issues during re-deployment. That's because guys from Microsoft update their VM images with new versions of software. As a result, these new images have new IDs and you must update your ARM or Powershell scripts.

    I wrote a script that will help to find new versions of images.

  • [Updated] Monitoring Azure resources with Zabbix Monitoring Azure resources with Zabbix

    June 25, 2020
    During last year, I've been actively refactoring this solution and finally I've updated this article. All code moved to GitHub where you can clone it to your PC and update as needed.

    Also, I've removed all comments as they're not relevant anymore.

     

    Hey!

    Today is the great day, as I'm finally going to share my approach to monitoring of Azure Cloud resources with Zabbix. There is no built-in solution for monitoring Azure with 3rd-party software (at least, I know nothing about that), so we'll need to build our own. Before you start configuring\scripting, please make sure you're familiar with most common Zabbix features, because the task is not trivial.

    Azure monitoring

    Why do we need all this? Well, I've encountered a number of issues, problems and limitations while trying to use native Azure tools - Log Analytics(to paint graphs) and Monitor (to configure alerting). Metrics could appear there with big delays, problems with writing queries, triggering - is also a problem.

    So, we've decided to adopt Zabbix for monitoring of Azure...

  • Implement multi-threading with .NET runspaces in Powershell Implement multi-threading with .NET namespaces in Powershell

    There are multiple options on how to implement multi-threading in Powershell. They are all well known to engineers:

    • Powershell Jobs
    • Powershell Workflows

    But there is another one, which is not quite popular (because of it's complexity), but very powerful: .NET runspaces. While it's quite difficult to implement, it don't have main disadvantage of native Powershell ways - we will not spawn tons of powershell.exe processes. All work will be done within a single process and that will highly increase overall script performance.

    I will not tell you about theory (mainly because I don't clearly understand details), but will give you some insights and script templates to start moving.