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.
powershell (en) - B-blog.info
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:
It's no secret that when you perform backup with Veeam Backup & Replication, sometimes it "forgets" to delete the its snapshots. This leads to the fact that all virtual machine starts to work entirely on snapshot all the time. This is a costly operation, which significantly reduces the performance of the virtual machine.
In addition, system administrators can create snapshot manually and forget about it. We had a case in our company when a virtual server half-year (!!!!!) worked on the snapshot.
Fortunately, VmWare provides a plugin for Powershell, PowerCLI, which you can use to find all these snapshots.
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.
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.
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
Error "Get-PowerCLIVersion : The term 'Get-PowerCLIVersion' is not recognized as the name of a cmdlet, function, script file, or operable program." while starting VMware vSphere PowerCLI
Sometimes the following error appear while starting VMware vSphere PowerCLI:
Get-PowerCLIVersion : The term 'Get-PowerCLIVersion' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1:38 char:12 + $version = Get-PowerCLIVersion + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-PowerCLIVersion:String) , CommandNotFoundExce ption + FullyQualifiedErrorId : CommandNotFoundException
Sometime it's very difficult to find error in Powershell script, especially if script is running in some dedicated session, for example, under SYSTEM account. There will be errors but you'll never know about them.
That's why I started to search a way to log output from Powershell-console to file. Here is the solution.
If you ever need to unzip BIG archive files in Powershell DSC configurations (during deployment some software), you will possibly get stuck, because using Archive resource is not suitable for this task as it is very slow. xArchive also will not help.
One possible solution is to unzip it with 7zip or some other command line utility using WindowsProcess resource, but be warned that WindowsProcess will just start the process and then will go to the next instruction in your configuration. See the example:
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.
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.
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.
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.
Why do we need all this? Well, I've encountered a number of issues, problems and limitations while trying to use native Azure monitoring tool - OMS. Metrics could appear there with big delays, problems with writing queries, triggering problems - also is a problem.
So, we've decided to adopt Zabbix for monitoring of Azure...
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 powerfull: .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.