PowerShell in Intune - How to Copy file(s) (1/3)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign we will look at three ways to use Powershell in InTune the first one we're gonna copy a file called CM Trace but it could be any file or files and CM Trace is a good log viewer and the one who comment on one of my videos we're asking how do you install that and we could copy that we will use that by using a Powershell script baked into a win32 app and I've done a lot of videos about win32 app in the second video we will create a scheduled task with Powershell and the schedule task will run every Wednesday morning and run system file Checker with the scan now to verify that the system is fine and in the last video we will use one of my favorite remedition script it's Powershell who will look for certain State and we will be using this to look if the Firefox is too old for example older than version 103 and then uninstall it and if it's not we'll let it so in this first video of Power social usage we're gonna copy a file in Powershell you could copy multiple files we will copy CM trays so let's download that first and it's not a free software you need to have configuration manager but you can download it for free so if we download CM Trace here and I'm not going to give any Link in the description but you can easily find that by Googling so here there is a download of CM Trace it's very small so I like to clean up stuff so I'm gonna cut this one and we're going to need to have um a base folder you have all of my videos know how I like to have it clean so under underscore gbn In Tune packages I add all my um installation folders so I'm gonna create a new folder here as well new folder and we know it's Microsoft that is the manufacturer CM Trace CM Trace I'm not sure if it's a 64-bit and which version so we're gonna change that I'm pasting that one in here Ctrl V because I copied earlier let's verify which version here we see it's 5.0 8239 1000 okay I'm gonna add that to the name here so I press f2 so it was 5.0. what was it I forgot 82.39 it was not but something like that so it was not 82.39 it was 8239 okay it was that was lucky how do we know if this is a 32-bit or 64-bit well I usually double click on it so it started then I go to task manager Ctrl shift Escape and if it's a 32-bit app it's gonna say that here and CM Trace oh it's even say AMD 64-bit okay so it's a 64-bit um version good I like that so then I'm going to rename the folder again we're going to create a Powershell script that copied and the file and we're going to package it as a win32 app so that's what I'm preparing here so we need a source folder and an output folder let's start with an output so in here it's going to be the InTune win32 file oh InTune win file the one we will upload to In Tune and we need a source folder so let's create folder here source and that one will contain two files our Powershell script and our Sim Trace so let's write the Powershell script the Powershell script I like to run that in power create that in Powershell ISE run it as admin not needed for writing the script but we want to test it after that it's working and then it's a good thing so I click here on the script let's zoom in a bit I zoom in um let's see zoom in three times so I like to put the comment what the script is doing who have done it and date so let's do three rows for that and if you put one hash sign here then it's a comment so what will it do it will copy Sim Trace file into and I want it under C program files CM Trace up lost the backslash here so we can copy it into that folder it doesn't exist we can have our script create that uh author that's gonna be myself date today is 18 October 2022 this will most likely work when you're even if you look this in the future and let's see so we can start a bit backwards so first we would actually copy the item that's going to be the last line what should we copy well we're going to copy our files and that's the CM Trace I do an F2 Ctrl a control C just to be sure so we want to copy this file where do we want to copy it so it's destination well I said I wanted it here and we need a double quotation y because there is a space in program if we didn't have the double quotation it's going to try to copy to C program so that looks good the problem is how can it find CM trays I mean should we put C column backslash well it's not going to be on the root of the C can we do backslash the server in the cloud or something well no we're gonna have to have a dynamic one it's a variable that always find this files so how can we do that well we do know that when we save this file which will have another name if we save that file in the same folder as CM Trace if we can find out where the script is we know that the CM trays have the same path so let's create some variables we start with I'll call here variables we're going to call create this called Script wrote and I'm going to name the variable starts with the dollar dbn script oh well let's call it script root and then we put that to be the same path where the script runs and then in order to find CM Trace we can just copy the script route put that in front paste here do a backslash so then we have the path to CM Trace now we have to do this also so we can do a split path and then we do a path and then we use a variable built in my I thought it would help me oh it did I tapped usually it comes up Dot then it is my command dot path so this part here it's going to be the the path where this file is so that's going to work we could save this file but we have another problem the destination if the destination doesn't exist it might fail so let's make sure that this destination exists before we run the script so we can do that here we can look if and then we want to look if it doesn't exist so that means the explanation mark if test path that's testing does the path exist and then I paste it because I have it here if it doesn't exist because we have the exclamation mark then it's going to run whatever is in between this curly bracket so if it doesn't exist let's create it so we can do a new item what uh what item type is it well it's the directory well you would argue and say it's a folder and I would agree with you but they called it directory and then uh I think it's going to be path for the directory and it's this one here so I think we have a pretty good one just for better um Powershell coding or coding in general when you type the same thing multiple times I think else three times then it's usually better to use a variable why because if we want to have it in another destination in the future we don't want to change it in three places so let's create another variable and call that GBM CM Trace deer for directory and then we set that equal to this path so then we can use this variable instead and if we in the future want to change place we just need to change it in one place so I'm going to put that here paste there and paste there and in the last one and I forgot to say if we would run this now this won't work the script route you really have to save it and run it as a file so let's do that so hit save and it's in the source why don't we see our cmtrace.exe well we're not looking for all files so it's here so we want to save it in the same space so we can call it the copy Dash uh CM Trace let's put the version number 82 39 39.000 x 64 and it has to be PS1 so now we save this let's see if this works so let's look on my machine here if I go to um uh C program CM Trace I should not have that folder so if I just type put that here it should say hey it doesn't exist yeah but hopefully after running our script it should so let's go to our script I have mine under dbn unders oops I thought I had selected it cdgbn uh InTune packages oh I didn't select it that's why and we have to go into our source folder so if I do an LS or deer here here we have our Powershell script let's run that copy and hopefully if we if we get error we'll fix it no problem it looks like it went just fine so now if we go back here and try to go to this folder that didn't work it should be there with the file okay so we know our script is working and that's always good to check before you create the InTune win file so that's our next step if I go back yep source so now we have our source files that we want to create an output file that we can upload to InTune in the InTune win format and for that we need another tool so let's download the win32 prep tool so we can open a new tab just type win32 oh InTune prep tool that's the one uh it's a GitHub page you get there if you click here also I'll put the link in the description and it's the InTune Win app util file we want so let's download that one I got it and I said I wanted to keep this one clean let me delete this one and I'm gonna cut our InTune Win app utility and go to our package have I closed all my windows again C dbn engine packages CM Trace so paste it here we are more or less good I it's not technically needed but I like to have an icon for it especially since we're going to put it in the company portal that's nice there is no real good icon for CM trade so I'm just gonna do a log icon transparent and see if I find one it's a log reader uh can I get a better one if not I take that it's not that important log well one of these any any do is it a PNG saving images as long as it's the pnd it is I'll I'll take it um but I'm gonna rename it to logo Dash cmtrace again optional you don't have to have it so now finally we have everything that we need now we will create our InTune win file and we use the InTune Win app utility so we double click on that it's going to ask for four questions where are our source files well in our source folder shift right shift right click copy as path Ctrl V we paste it here setup file doesn't really matter you can take any files in the source we have only two I will take CM Trace well actually I'm going to take this one because you get the name by default it doesn't matter if you have an MSI file I always recommend to take that but here you just want to see one file output folder well we have one just for that um shift well right click in Windows 11 is enough don't need shift Ctrl V and always know on the catalog folder it's only for Windows s version which doesn't exist in Windows 11 I believe so this file should be a bit smaller than these two combined because it's compressed xfile normally isn't compressed so much so it might not be so much smaller oh still pretty good compression usually it's less so this is our packet file engine win file in this one it's encrypted it's compressed and this is what we're gonna upload to intro so let's go there into in endpoint.microsoft.com say I don't have to log in it remember me let's go to apps I like to go to Windows then you get less option when you click on ADD let's click on ADD select our type and we want to win app win32 I have a full course where I go through all the options very carefully so I go fairly quick now select an app package select the file we go to our output folder and here is our InTune win file that's what it's looking for and this one is small so even with my slow connection it's going to go faster upload but it does that in the end so here the name let's call it Microsoft cem Trace and that here description is important for company portal exactly what I'm going to use it for so let's say uh excellent logo reader require config M gear light license I think I mentioned that million million of time let's do log reader bold with the two asterisks so down here you see what it looks like and Publisher's name it's Microsoft app version we have here Ctrl C paste category I never know any good one let's call it productivity you can add your own I'm not gonna highlight it notes I like to put who have done it and date a October 2022 and here comes the image that we downloaded so let's select go up one and take the logo CM Trace yeah on white on white it doesn't look so good maybe you I'm sure you can find a better logo than what I have uh why I don't see it at all though that's strange oh there it is yeah looks really bad um then install command so we're gonna need to run the script our Powershell script so we can do powershell.exe I put execution policy it's not needed because um intern by highest anyways it doesn't really need it but I like it just for my own learning file what should we run dot backslash and then we take the name of our file so let's say it's not in our output it's in our source so it's this one here I do a F2 Ctrl a control C and of course you must show file extension if not you can't do this copy method so we just want to run this one we don't need to run anything for uninstall important to run a system because you remember our script is copying to see program files if you are not admin it won't work if I put user here it will only work for the few users or local admin and Source always system here definitely no restart needed no return code operating say must be 64-bit since the software is 64-bit operating system I mean technically you could work on the older one I'll I have Windows 11 in this fake organization it's not more than one megabyte but it's not needed you only need the two first one let's do that because we want it to go a bit fast detection rule very important so and very easy for this package so we do manual manual configuration detection rule add and it's not an MSI it's not ready Siri must do file we just look if our file is there if it's there then it's a success and CM Trace cm it's not case sensitive but still so we are just looking is this file here is there if not we could look uh for a version of the file if we did an update but we just do an easy here and it's not the 32-bit so detection rule super important because before it run it's gonna look is this true if it's true it's not going to run it's a why should I run it's already there if it's not there it's going to run the scripting program and then come back here and say successfully it's the file here if it's there it's going to say success regardless what happens dependency have no dependency of Adobe Air or NET Framework or anything super Seasons no assignment I'm gonna add it to all users I like show note the toast notification in company portal and we are good let's create this one so it's created but remember it also needs to be uploaded so it's not totally ready yet but it's so small it should go faster and wow this um really bad okay there it is you can see overview and properties we're gonna see a blue edit no it's not done yet there is Daddy okay now I waited a while and one of my clients do have this app showing up in the company portal so if we go company portal and I saw the icon isn't as bad as it looked in the console with the white background because it puts something gray behind some signing into company portal well it does does that let's check this machine if we go see program files and then sort here there's only one with z and that's common file we don't have any CM trays so here it is and here the icon looks pretty okay here looks horrible in the in the console but here sort of okay so the detection method says well it's not installed normal so let's hit install it's gonna download our InTune win file it's gonna decrypt it decompress it extract it run it and with the help of our script route our script gonna find the CM trace and copy it in so it's downloading still downloading okay we can follow it live here so far it's only common files there we have the CM Trace and if we go in we have the cmtrace.exe have it on the stand it's still looking here and the detection might say yes it was installed successful so we did it great job um let's do a very quick recap pretty long video so we did create our script that copy the CM Trace file we were using a script wrote In order to always find it we put the CM trace and the script together into an InTune winfide we uploaded it as a win32 app and from there we could deploy it so if you follow along so far very good thank you very much see you in next video
Info
Channel: Intune & Vita Doctrina
Views: 6,558
Rating: undefined out of 5
Keywords: Intune, PowerShell, Win32, CMTrace, Copy files
Id: f2GnNYlhxSM
Channel Id: undefined
Length: 21min 53sec (1313 seconds)
Published: Sun Oct 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.