The best case scenario in my opinion of using variables is to leverage objects. I know some of the users prefer text only, but objects carry much more information, that can be logged or leveraged. Here is an example:
Having computer’s name vs and object with multiple properties.
The 3 last lines are are magic…
Having the same data in the variable and then manipulating them to give you what you want so that the data is applicable and even passed to more commands.
So lets say there is another propery or point of interest that needs to be associated with the computer and user….
Can you do that with text and then create a fancy excel sheet? maybe if you want to have panic attacks about deadlines. It is all about the objects of desire lol.
Lets add a serial number:
Lets get Dynamic like a duo (no Microsoft pun) with dynamic Data
This object is now dynamic and can be used to extrapolate data inside of a remote script, report, or function.
Brain Check… share your real world applications of create dynamic and static objects.
If you cannot think of any then use the code to inventory your home PCs. Don’t forget to add the serial number:
Don’t Forget to select the properties you need or expand them to just get the inside of the object.
Want to learn what is selectable with any object? Indicate the object and pipe it to get-member.
After reading we will try to find the module using built im module package for powershell :
we can pipe this into an “install-module” command with a few parameters to ensure a smooth install.
this should install the module and you import Excel workbooks as easily as you can excel and text files.
Import-Excel, Export-Excel with a few extra parameters like -worksheet so you can target data sets and even write reports with details on different pages!
I use this to write share permission reports with different shares on different worksheets. So other things you can do is a security audit on servers and write a server to each worksheet and then write a pivot table for a summary report.
I how you download and support this module because it is nothing short of amazing, you dont have to have the excel application installed to import or export to Excel!
One of my favorite reasons I love PowerShell is because can tap into its programming roots for added power. I will demonstrate later in my post.
Here is why:
An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.
The base OLE Automation Date is midnight, 30 December 1899. The minimum OLE Automation date is midnight, 1 January 0100. The maximum OLE Automation Date is the same as DateTime.MaxValue, the last moment of 31 December 9999.
first there are not many reasons to convert excel to csv (who am I kidding it is tons). I ran across this issue helping a friend. I can’t believe how incredibly complicated it was to convert the time into a format that was more legible inside of the CSV file.
I think we can agree that sometimes things are harder than what they need to be and I will ensure that this can go easier specially if you take the time to make a function so that you can recall the fix in the future.
Planning is vital to any infrastructure environment and when scripting or using PowerShell is by no means any different. when you add a high level plan/structure and use it as a map of to-dos and things you want to add later and things you would like to change.
Failure to plan can mean data loss and errors that go uninvestigated. Either of which is not what you want to lay eye on or expose ears to. Error handling should go hand in hand with any PowerShell approached solution to cover your bases.
One way is to write a road map of comments in your script prior to coding. reference snippets as often as you can. enough detail so that you wont be lost of you reference that script or function 2 or 3 years from current date to create easily understood code and recycle.
Writing scripts and functions we sometimes just want something to do or be one way with one purpose.
I have mulled over things and re-coded tools to work with different things. The one thing I find to be the best in every situation is always script or code with objects in mind so that the rescuing of old code is easier.
Yeah it takes more time to do this and ensure that you aren’t reinventing the wheel.
The reality of even using PowerShell is to make your life easier. You want to ensure the process you use is refined enough to keep management at bay on your decisions and feeling confident about your solutions by reassuring them with facts and successes.
So instead of making a paper air plane that only flys in circles. Create a small engine that can fly a tiny drone and can be controlled with a strict protocol.
You may think to your self drones are cumbersome and you don’t always need to fly things but, hang on! That tiny engine can go in to a tiny car and use the same controller and so on.
I don’t want you to only be a pilot but an engineer that can reuse useful creations. Explore your horizons during down time, explore modules and other scripts to become inspired.
Take what you see and make it your foresight for newer projects. Have you taken the time to create something lately and really make it reusable?
I was looking into google cloud to explore some options for a client to leverage some automation elements and was very interested until I learned of the lack of PowerShell support.
For the life of me I cannot understand Google’s purpose to neglect populations of individual platforms and still want professionals to take their platform seriously as their competitors. Okay I’m done complaining.
It is something I sincerely hope Google notices and rectifies so that it supports PowerShell as it installs on all OS genres. To leave out automation potential is saying I’m just doing this cloud thing to be like everyone else.
So in my humble opinion there is simply no Power in google cloud shell.
How many others are fine learning python and writing shorthand and okay with not embracing a world where we take any OS as a catalyst that connects your tools to all the cloud providers.