In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Some time ago, I wrote a PowerShell script to my colleagues, but in exchange for the eyes of my colleagues, it means that this is all linux. If you write a script of powershell for me, where will I go? I really want to look back. It has been 0202 years since I thought that powershell can only run on windows. PowerShell is open source. It has been a long time since PowerShell Core was born, but there are still people who naively think that PowerShell is only suitable for the Windows platform. In fact, starting from PowerShell Core. PowerShell script can be directly run on the major Linux platforms! And the experience is basically a seamless transplantation! Many scripts do not need to change a single letter!
Take the Azure script, for example, let's take a look at how to play PowerShell on Linux
First of all, we need to install the PowerShell, and first get the repo information ready.
Curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee / etc/yum.repos.d/microsoft.repo
After the direct yum install installation, the installation under linux is indeed convenient and fast.
Sudo yum install-y powershell
Enter Pwsh directly into PowerShell
Next, you can install module for Azure. Note that we want to install the latest az module under linux, or we can try other commands. The syntax is basically the same as powershell under windows.
Next, let's take a look at how to log in to Azure. Like windows, you can log in directly with login-azaccount, but the difference is that because there is no graphical interface, you need to log in with code, which is similar to CLI.
Enter the corresponding code in the browser
You can see the information that has been able to get to the account!
There is another problem to say. If you want to run some regular scripts, PowerShell core does not support login directly with user name and password, so here we either use the code method we just saw to achieve interactive login, or use service principal to log in.
The introduction of service principal has been discussed before. I will not repeat it here. The method of creating service principal is also relatively simple. You can create it with PowerShell. If you want to add a password to service principal, you can find Service Principal on Portal and click add secret.
Secret can set the expiration time
Save the value. If you don't save it, you won't find it later, so be sure to save it.
Then you can log in with this secret!
$ApplicationID= "a67aa2ff-f009-4ec9-93fa-c773aa1442ec" $Password= "*" $TenantID= "b7283bff-0d3d-4728-9189-8513ee70744a" $Password=ConvertTo-SecureString $Password-AsPlainText-Force$Credential=New-Object System.Management.Automation.PSCredential ($ApplicationID,$Password) Add-AzAccount-Credential $Credential-ServicePrincipal-TenantId $TenantID-EnvironmentName azurechinacloud
Login successful! You can run the script happily.
I have to say, it's really convenient. Microsoft has to like this operation.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.