ProblemYou want to create a compress files in python.IntroductionZIP files can hold the compressed contents of many other files. Compressing a file reduces its size on disk, which is useful when transferring it over the internet or between the systems using Control-m AFT or Connect direct or even scp.Python programs creates ZIP files using functions in the zipfile module.How to do it...1. We will be using zipfile and io packages. Install them with pip if any of the packages are missing on your system. If you are unsure, use pip freeze command to validate the packages.2. We will write a ... Read More
How to append new rows to DataFrame using a Template In Python Pandas.IntroductionBeing a data engineering specialist, i often end up creating more derived columns than rows as the role of creating and sending the data to me for analysis should be taken care of other database specialists. However, it is not true during all time.We have to create sample rows rather than waiting for data specialists team to send us the data. In this topic i will be showing the neat tricks for creating rows.How to do it..In this recipe, we will begin by appending rows to a small ... Read More
ProblemYou need to extract the HTML tables from a web page.IntroductionThe internet, and the World Wide Web (WWW), is the most prominent source of information today. There is so much information out there, it is just very hard to choose the content from so many options. Most of that information is retrievable through HTTP.But we can also perform these operations programmatically to retrieve and process information automatically.Python allows us to do this using its standard library an HTTP client, but the requests module helps in obtaining web pages information very easy.In this post, we will see how to parse through ... Read More
To format string in PowerShell, you can use -F operator. When you use -F format, you need to provide the argument number in the curly brackets.ExamplePS C:\> $Str = "Hello PowerShell" PS C:\> "{0}" -f $str Hello PowerShellFor the multiple values, PS C:\> $Str = "Hello PowerShell" PS C:\> $str1 = "Rockstart" PS C:\> "{0} says {1}" -f $Str, $str1 Hello PowerShell says RockstartFrom the above example, we understood if we need to get the output for multiple variables using the -F operator then we can increment the number in curly brackets.To use the above output with the Write-Output command, ... Read More
There are several ways to find the MAC address (Physical Address) of the system using PowerShell.Using the Get-NetAdapter commandUsing this command, we can retrieve the MAC address of the network adapter.Using GetMac commandIpconfig commandWe need to use Ipconfig /all to retrieve the mac address of all the adapters.ExampleIpconfig /all | Select-String -Pattern "Description","Physical"Output
To resolve the DNS address using PowerShell, we need to use the Resolve-DNS address command. This command works similarly to Nslookup command.To resolve the A record (Name -> IP), you can directly provide the hostname and by default, it will retrieve all the records for the particular address.ExampleResolve-DnsName -Name Test1-win2k12OutputName Type TTL Section IPAddress ---- ---- --- ------- --------- Test1-Win2k12.labdomain.local A 1200 Answer 192.168.0.107-Name parameter doesn’t accept the multiple-input. Only the single ... Read More
To install the active directory module using PowerShell, you need Remote Server Administrator Tools (RSAT) on the server. It should be available in the Roles and Features section of the windows server operating system as shown below and you can enable it from the GUI as well.If you can’t find the RSAT then you can download it from the below location, appropriate to your OS version.https://www.microsoft.com/en-us/download/details.aspx?id=45520Once you have the RSAT tool available in your system, you can use the PowerShell command to enable this feature. To get the Active Directory tools features available in the system, use the below command.ExampleGet-WindowsFeature ... Read More
We know that PowerShell executes commands sequentially until we specify some parallel Jobs but sometimes the next command executes before the First command because the first command might be taking a long time to retrieve the data. In that case, if you want the previous command to finish first and then the next command to get executed, you can use PowerShell Job functionality.For example, we need to write a script to ask for the user input to terminate process ID but the program should retrieve the process IDs first.Example$job = Start-Job {Get-Process} Wait-Job $job | Out-Null Receive-Job $job $id = ... Read More
To get the timezone of the System, you can use the Get-TimeZone command.ExamplePS C:\> Get-TimeZone Id : Mountain Standard Time DisplayName : (UTC-07:00) Mountain Time (US & Canada) StandardName : Mountain Standard Time DaylightName : Mountain Daylight Time BaseUtcOffset : -07:00:00 SupportsDaylightSavingTime : TrueTo Set the TimeZone of the System, you can you the ID or the Name of the ... Read More
Like the Parameter alias, we can also set the function alias name to refer to the function as a different name.Examplefunction Test-NewConnection{ [CmdletBinding()] [Alias("TC")] param( [Parameter(Mandatory=$true)] [String]$Server ) Write-Output "Testing $server connection" }Now, instead of the Test-NewConnection function name, you can directly use the function alias “TC” as shown below.PS C:\> Tc -Server "Test1-win2k16" Testing Test1-win2k16 connection