Posts

Create multiple Azure files shares using Powershell

If you have to create multiple shares for an Azure files instance as part of a migration or new deployment it can be very time consuming. With this script you put the name of the shares in a txt file called "shares.txt" and it will loop through and create them all and assign them to the hot tier. <# .SYNOPSIS Created by James Lambert www.roonics.com .DESCRIPTION This script creates shares from a txt file in Azure and set's their access tier .EXAMPLE .OUTPUTS .NOTES #> # CONFIG START $file = Get-Content -Path "shares.txt" $accessTier = "Hot" $tenant = "<tenant id>" $subscription = "<subscription id>" $resourceGroupName = "<resource group>" $storageAccountName = "<storage account name>" # CONFIG END # CONNECT TO AZURE Connect-AzAccount -Tenant $tenant -SubscriptionId $subscription # GET STORAGE KEY $storageKey = (Get-AzStorageAccountKey ` -ResourceGroupName $resour...

Apply tags to azure resource groups from csv file

This script is used to apply tags as per a csv file. Tags will be applied in uppercase. If a resource group is present in the csv but not in Azure it will be skipped. A log file will be generated in the log folder. A backup of the resource groups previous tags and values will be created in the backup folder. CSV should be formatted as the Example file and saved as tags.csv in c:\temp\tags unless you specify differently under the config section An example csv file can be downloaded here <# .SYNOPSIS Created by James Lambert www.roonics.com .DESCRIPTION This script is used to apply tags as per a csv file. Tags will be applied in uppercase. If a resource group is present in the csv but not in Azure it will be skipped. A log file will be generated in the log folder. A backup of the resource groups previous tags and values will be created in the backup folder. .EXAMPLE CSV should be formatted as below or see the example file and saved as tags.csv in c:\temp\tags unless you specify d...

List object contributors in all Azure subscriptions with Powershell

Image
The below script will loop through all Azure subscriptions excluding Visual Studio subscriptions, it will then look at every object and list/export everyone who has a role that has the word "Contributor" in it. Example below: <### .Synopsis Created by James Lambert www.roonics.com .DESCRIPTION This script will connect to Azure and cycle through all subscriptions listing all the objects and who has a role which has "Contributor" in the name .EXAMPLE Run the script and sign in to Azure .OUTPUTS A file csv file will be created for each subscription named "contribuators_subscription.csv" in c:\temp A total number of contributors will be added to the bottom of the csv .NOTES Keep in mind this will only be able to look at subscriptions you have permissions to. This will also skip the Visual studio subscription using a if the name like 'visual' statement ###> ### Config and clear screen cls $Path = "C:\Temp\" $f...

List printers and IP addresses on a windows server using Powershell

Image
  <### .SYNOPSIS Created by James Lambert www.roonics.com .DESCRIPTION Collect port names and host addresses into hash table .EXAMPLE .OUTPUTS .NOTES ###> $hostAddresses = @{} Get-WmiObject Win32_TCPIPPrinterPort | ForEach-Object { $hostAddresses.Add($_.Name, $_.HostAddress) } Get-WmiObject Win32_Printer | ForEach-Object { New-Object PSObject -Property @{ "Name" = $_.Name "DriverName" = $_.DriverName "Status" = $_.Status "HostAddress" = $hostAddresses[$_.PortName] } }

Stop and disable a Windows service using powershell

Populate "computers.txt" with all the server names you wish this to run on then adjust the script to fit the service you require. <### .SYNOPSIS Created by James Lambert www.roonics.com .DESCRIPTION Stop and disable a Windows service using powershell Populate "computers.txt" with all the server names you wish this to run on then adjust the script to fit the service you require. .EXAMPLE .OUTPUTS .NOTES ###> $SrvNames = Get-Content -Path 'C:\data\scripts\computers.txt' foreach ($Server in $SrvNames) { Get-Service -Name "Rubrik Backup Service" -ComputerName $Server | Stop-Service -PassThru | Set-Service -StartupType disabled }

Split file every xxx lines with Powershell

Image
I recently ran in to an issue whilst using CommVault to restore some archive files from it's HSM. You have to run the gxhsmutility to scan the files to check if any stub files remain, if there is it outputs what is called a map file, you then run the restore again pointing to said map file. The problem with this was that if the map file was over 100,000 lines the recovery would just crash, so I wrote this to split the map file out in to multiple map files I could then use to recover the data. <### .SYNOPSIS Created by James Lambert www.roonics.com .DESCRIPTION This script will get a list of all files in the "Files_to_split folder" then loop through each file and split every XXX numbers of lines (set in the config) .EXAMPLE .OUTPUTS .NOTES ###> ### Config $FilesToSplitDir = "Files_to_split\" $SplitFilesDir = "Split_files\" $SplitFileLines = 100000 $padding = " " cls ### Check if source folder is present if (!(Test-Path ...

Add random number prefix to filename with Powershell

This allows you to add a randomly generated number to the prefix of a bunch of files. In the below example we are adding a random prefix to every *.jpg file. <# .SYNOPSIS Created by James Lambert www.roonics.com .DESCRIPTION This allows you to add a randomly generated number to the prefix of a bunch of files. In the below example we are adding a random prefix to every *.jpg file. .EXAMPLE .OUTPUTS .NOTES #> $files = Get-ChildItem "C:\temp\files" -Filter *.jpg foreach ($file in $files) { $prefix = Get-Random $newFileName = "${prefix}_${file}" Rename-Item $file $newFileName }