Hello, my name is Adrien. Currently, I am in an internship and I manage mostly Linux servers. The company wants to migrate some servers to the Azure cloud and use Windows Server for user administration. I think it's time to learn PowerShell, but I am a beginner in Windows. I know the basics of AD and a few cmdlets, but nothing more. Do you have any tips on how to be efficient with this language for automation? I have coded in Java or Bash before and already did a lot of script in bash , for example
#Linux guy who want to learn powershell for azure and Windows Server need tips
22 messages · Page 1 of 1 (latest)
i think you have the bonus of already being familiar with cli/scripting. I have nothing specific for you unfortunately but someone else will. Check out #resources though!
Having the knowledge you have is a head start, I would always suggest just start with learning syntax and how the pipeline works, playing around with processes or services on a test system. Then learning how to get help on the fly: get-member, get-command, get-help or "help" etc..
Once ready, set a task for yourself to complete, for something advanced: try setup a test server and promote into a DC for a new AD forest & domain. Install server core if you feel you might cheat!
Then try populate it with characters out of the starwars api or something like that
If that is a little too far in the deep end, try just working with an api and changing the properties on objects, try exporting data into CSVs, try working with files, shares, registry etc.. I found doing some mundane hello world task is pointless unless scripting, shells and all the sorts is totally alien to you then yes, start there! But if not, start with something relevant to the reason you bothered starting in the first place
Then build out with whatever you wish to learn. Go nuts
For what it is worth, I'd recommend going with Oracle Cloud/Powershell combo over Azure/Windows combo. Oracle Cloud has a PowerShell module that allows one to manage the whole cloud infrastructure. https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/powershell.htm
I've been managing my VM instance in OCI for over 2 years now at zero hosting costs using just Linux/PowerShell combo.
Here is a blog on how to do a boot volume backup using the OCI module. https://cadayton.onrender.com/blog/PSOciBootBackup.html
This topic describes how to install, configure, and use the Oracle Cloud Infrastructure Modules for PowerShell
A PowerShell script for performing a Boot Volume Backup on an Oracle Cloud compute instance running BTCPay Server application to generate an application consistent backup.
thank you bro
Yeah currently i'm creating things with powershell server status , active directory massive user creation , disk management etc i tried server core but maybe too hardcore for me now maybe later when im more efficient with powershell but thanks for the idea files shares and registry im gonna work on that
Thanks you i dont have the power really but i'm gonna check that
Thats all there is too it!! work with these sort of things then you can build on that as you get better with practise. For files try making a scrip that generates and folder for <x> year that you can input then it makes that year with each month as sub folders?
Or, one i made recently in fact... Try making a scrip that can mount a file share as an "X" drive then backup a source folders data that has been changed/created within the last 2 days or something and delete anything older in the source.
For registry, you need the knowledge of windows really to do anything major but one i did recently was removing app data (non admin) software installs for all users on a PC without calling any installers. I enter a non ambiguous app name and boom... Gone! This was because Opera browser decided a --silent switch was not needed to uninstall as well as admin rights are not needed to install it.... yeah. Or you can play around with just simply changing windows settings via the registry in PowerShell, try changing the mundane OOB stuff you'd do for a new PC (all automated imaging/deployment tools aside here)
yes i understand a little bit more the power of this language i'm keep workinggg and wtf it's so underated i like bash of course but wtf powershell is so good
I would say learning how to write a cmdlet/function that supports pipeline input(process block), it helps to understand usages of cmdlets pipe. Item cmdlets are really good start point to practice pipeline, you can always manipulate items within pure pipeline, really fluent, try it out!CommonParameters for cmdlet are also interesting, it allows you to do value-based error handling which is a better practice in pwsh. With these knowledge you can write more decent statement with less variable declared.
Yeah the commonParameters i already try them with -ErrorAction something like this cause the red message scare me i prefer mine
we usually use -ErrorAction to suppress to error sinced terminating the process is the default.
For example we can check whether a command is available in pwsh like this. using Ignore makes sure it doesn't terminate the statement when not found
if (Get-Command cmd -ErrorAction Ignore) {
}
So for exemple i did that is it better to put like you did ?
$RootOU = Get-ADOrganizationalUnit -Identity $RootDN -ErrorAction SilentlyContinue
if (-not $RootOU) {
Write-Host "The OU '$Ou' does not exist under this Domain Controller" -ForegroundColor Yellow
return
}
or you can do something like
try {
$RootOU = Get-ADOrganizationalUnit -Identity $RootDN -ErrorAction Stop
}
catch {
Write-Warning "The OU '$Ou' does not exist under this Domain Controller"
}
just depends on your use case and preferences. just play around with different methods
there is plenty of pwsh in the Azure world. no need for oracle cloud.
i would start with converting one-liners or scripts you wrote in bash. Then I might try my hand at converting the Java to pwsh. I might try it first on `*nix host. This is about as practical and fast as I can think assuming you learn better with goals and clear beginning and end. loose goals are the death of learning and starting with a book can hurt that learning. advent of code is relevant now too.
they key is the object pipeline over text and reworking your mind around it.
dropping regex mentality or spliting on spaces using cut, awk. Many of the tools in *nix are mostly useless with objects.
another key is thinking in terms of APIs instead of text or files
it was my first mistake try to use powershell like bash but i did a little bit of java long time ago and OOP so the switch was not that hard just the time to understand how the language work i'm working with objects who have property and that's all
If you mean like strings instead of objects then yeah that will be challenging and you’d have to out string everywhere.
Sorry my english is bad just i mean now i understand it's object oriented it's way easier than last week just i have question on what is .NET object i dont really understand the term