Can you use a powershell script to create a powershell script?Determine installed PowerShell versionTerminating a script in PowerShellHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?Distributing powershell script (.ps1) to computers, from java app on serverPowerShell to fetch installed programsCreate a startup script from Powershell on windowsPowershell script but not making the changes required in registryPowerShell Script/Refresh

How is linear momentum conserved in case of a freely falling body?

Shift lens vs move body?

Changing JPEG to RAW to use on Lightroom?

What are the IPSE’s, the ASPE’s, the FRIPSE’s and the GRIPSE’s?

How can I download a file from a host I can only SSH to through another host?

What is this fighter jet at Weymouth NAS?

How to say "I only speak one which is English." in French?

What's the point of fighting monsters in Zelda BoTW?

Does a Mace of Disruption's Frightened effect override undead immunity to the Frightened condition?

Under what circumstances does intermodulation become an issue in a filter after LNA setup?

How many petaflops does it take to land on the moon? What does Artemis need with an Aitken?

Can I get a PhD for developing an educational software?

How many birds in the bush?

To what extent should we fear giving offense?

74S vs 74LS ICs

When using a variable to set the path, I get "No such file or directory", but works fine otherwise

Half filled water bottle

Discussing work with supervisor in an invited dinner with his family

Expressing an implication as ILP where each implication term comprises a chain of boolean ORs

Count the number of paths to n

How to prevent a hosting company from accessing a VM's encryption keys?

can you help me identify this aircraft?

Router on a stick not connecting 2 different VLANs

Billiard balls collision



Can you use a powershell script to create a powershell script?


Determine installed PowerShell versionTerminating a script in PowerShellHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?Distributing powershell script (.ps1) to computers, from java app on serverPowerShell to fetch installed programsCreate a startup script from Powershell on windowsPowershell script but not making the changes required in registryPowerShell Script/Refresh






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















So this may be an odd request and maybe I'm going about this all wrong but I also have a unique situation. I have servers that are sometimes cloned and I need to run a script that I created on the clones servers. Due to the nature of the clones they cannot be connected to a network.



Currently I am manually putting the generic script on each server before cloning and then running the script on the clone server.



What I would like to do is have a script that runs and gathers all the information, say installed programs as an example, and generate a custom version of my current script on the servers before they are cloned.



I have both the powershell script that gets the server information and the generic one that makes the changes to the clone but I have not found a way to merge the two or any documentation so I don't know if i am hitting a limitation with this one.



Edit for more explanation and examples. I'm doing this from my phone atm so I dont have an example I can post.



Current I have a script that has a set number of applications to uninstall, registry keys to remove, services to stop ect. In another application I have a list of all the software that we have for each server and I can pull that data for each server. What I need to do is pull the data for each server, and have a script placed on each server that will uninstall just the programs for that server.



Currently the script has to run through every potential software and try to uninstall it and then check the other application to see if there are any additional programs that need to be uninstalled.



Hope this extra info helps.



Thanks.










share|improve this question
































    0















    So this may be an odd request and maybe I'm going about this all wrong but I also have a unique situation. I have servers that are sometimes cloned and I need to run a script that I created on the clones servers. Due to the nature of the clones they cannot be connected to a network.



    Currently I am manually putting the generic script on each server before cloning and then running the script on the clone server.



    What I would like to do is have a script that runs and gathers all the information, say installed programs as an example, and generate a custom version of my current script on the servers before they are cloned.



    I have both the powershell script that gets the server information and the generic one that makes the changes to the clone but I have not found a way to merge the two or any documentation so I don't know if i am hitting a limitation with this one.



    Edit for more explanation and examples. I'm doing this from my phone atm so I dont have an example I can post.



    Current I have a script that has a set number of applications to uninstall, registry keys to remove, services to stop ect. In another application I have a list of all the software that we have for each server and I can pull that data for each server. What I need to do is pull the data for each server, and have a script placed on each server that will uninstall just the programs for that server.



    Currently the script has to run through every potential software and try to uninstall it and then check the other application to see if there are any additional programs that need to be uninstalled.



    Hope this extra info helps.



    Thanks.










    share|improve this question




























      0












      0








      0








      So this may be an odd request and maybe I'm going about this all wrong but I also have a unique situation. I have servers that are sometimes cloned and I need to run a script that I created on the clones servers. Due to the nature of the clones they cannot be connected to a network.



      Currently I am manually putting the generic script on each server before cloning and then running the script on the clone server.



      What I would like to do is have a script that runs and gathers all the information, say installed programs as an example, and generate a custom version of my current script on the servers before they are cloned.



      I have both the powershell script that gets the server information and the generic one that makes the changes to the clone but I have not found a way to merge the two or any documentation so I don't know if i am hitting a limitation with this one.



      Edit for more explanation and examples. I'm doing this from my phone atm so I dont have an example I can post.



      Current I have a script that has a set number of applications to uninstall, registry keys to remove, services to stop ect. In another application I have a list of all the software that we have for each server and I can pull that data for each server. What I need to do is pull the data for each server, and have a script placed on each server that will uninstall just the programs for that server.



      Currently the script has to run through every potential software and try to uninstall it and then check the other application to see if there are any additional programs that need to be uninstalled.



      Hope this extra info helps.



      Thanks.










      share|improve this question
















      So this may be an odd request and maybe I'm going about this all wrong but I also have a unique situation. I have servers that are sometimes cloned and I need to run a script that I created on the clones servers. Due to the nature of the clones they cannot be connected to a network.



      Currently I am manually putting the generic script on each server before cloning and then running the script on the clone server.



      What I would like to do is have a script that runs and gathers all the information, say installed programs as an example, and generate a custom version of my current script on the servers before they are cloned.



      I have both the powershell script that gets the server information and the generic one that makes the changes to the clone but I have not found a way to merge the two or any documentation so I don't know if i am hitting a limitation with this one.



      Edit for more explanation and examples. I'm doing this from my phone atm so I dont have an example I can post.



      Current I have a script that has a set number of applications to uninstall, registry keys to remove, services to stop ect. In another application I have a list of all the software that we have for each server and I can pull that data for each server. What I need to do is pull the data for each server, and have a script placed on each server that will uninstall just the programs for that server.



      Currently the script has to run through every potential software and try to uninstall it and then check the other application to see if there are any additional programs that need to be uninstalled.



      Hope this extra info helps.



      Thanks.







      powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 21:03







      Andrew Tschoepe

















      asked Mar 27 at 19:57









      Andrew TschoepeAndrew Tschoepe

      11 bronze badge




      11 bronze badge

























          1 Answer
          1






          active

          oldest

          votes


















          1















          Stop thinking of it as code.



          Use script 1 to export blocks of text into a new file. for example, you might have a configuration that says all Dell servers must have this line of code run:



          Set-DELL -attribute1 unmanaged


          where on HP, the script would have been



          Set-HP -attribute1 unmanaged


          on web servers, you want:



          set-web -active yes


          where if not a web server, you want nothing.. so, your parent script code would look like:



          $Dell = "Set-DELL -attribute1 unmanaged"
          $HP = "Set-HP -attribute1 unmanaged"
          $web = "set-web -active yes"

          if (Get-servermake -eq "Dell")
          out-file Child.ps1 -append


          if (Get-servermake -eq "HP")

          $HP

          if (Get-webserver -eq $true)
          out-file Child.ps1 -append



          The result is a customized script for the specific server, child.ps1.



          Now, you can take this and run with it. You could say add functionality to the child script like "Is it an AD controller", etc.



          However, you might be better off having all of this in a single script, and just block off sections that don't apply in an if statement for example.



          I'm still not totally sure I understand what your asking. If I've missed the mark, tell me how, and I'll tell you how to tweak this better. (And hopefully obvious is that the Get-whatever is sample code. I don't expect that to be what your using to determine a computer make/model/etc)






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385496%2fcan-you-use-a-powershell-script-to-create-a-powershell-script%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1















            Stop thinking of it as code.



            Use script 1 to export blocks of text into a new file. for example, you might have a configuration that says all Dell servers must have this line of code run:



            Set-DELL -attribute1 unmanaged


            where on HP, the script would have been



            Set-HP -attribute1 unmanaged


            on web servers, you want:



            set-web -active yes


            where if not a web server, you want nothing.. so, your parent script code would look like:



            $Dell = "Set-DELL -attribute1 unmanaged"
            $HP = "Set-HP -attribute1 unmanaged"
            $web = "set-web -active yes"

            if (Get-servermake -eq "Dell")
            out-file Child.ps1 -append


            if (Get-servermake -eq "HP")

            $HP

            if (Get-webserver -eq $true)
            out-file Child.ps1 -append



            The result is a customized script for the specific server, child.ps1.



            Now, you can take this and run with it. You could say add functionality to the child script like "Is it an AD controller", etc.



            However, you might be better off having all of this in a single script, and just block off sections that don't apply in an if statement for example.



            I'm still not totally sure I understand what your asking. If I've missed the mark, tell me how, and I'll tell you how to tweak this better. (And hopefully obvious is that the Get-whatever is sample code. I don't expect that to be what your using to determine a computer make/model/etc)






            share|improve this answer





























              1















              Stop thinking of it as code.



              Use script 1 to export blocks of text into a new file. for example, you might have a configuration that says all Dell servers must have this line of code run:



              Set-DELL -attribute1 unmanaged


              where on HP, the script would have been



              Set-HP -attribute1 unmanaged


              on web servers, you want:



              set-web -active yes


              where if not a web server, you want nothing.. so, your parent script code would look like:



              $Dell = "Set-DELL -attribute1 unmanaged"
              $HP = "Set-HP -attribute1 unmanaged"
              $web = "set-web -active yes"

              if (Get-servermake -eq "Dell")
              out-file Child.ps1 -append


              if (Get-servermake -eq "HP")

              $HP

              if (Get-webserver -eq $true)
              out-file Child.ps1 -append



              The result is a customized script for the specific server, child.ps1.



              Now, you can take this and run with it. You could say add functionality to the child script like "Is it an AD controller", etc.



              However, you might be better off having all of this in a single script, and just block off sections that don't apply in an if statement for example.



              I'm still not totally sure I understand what your asking. If I've missed the mark, tell me how, and I'll tell you how to tweak this better. (And hopefully obvious is that the Get-whatever is sample code. I don't expect that to be what your using to determine a computer make/model/etc)






              share|improve this answer



























                1














                1










                1









                Stop thinking of it as code.



                Use script 1 to export blocks of text into a new file. for example, you might have a configuration that says all Dell servers must have this line of code run:



                Set-DELL -attribute1 unmanaged


                where on HP, the script would have been



                Set-HP -attribute1 unmanaged


                on web servers, you want:



                set-web -active yes


                where if not a web server, you want nothing.. so, your parent script code would look like:



                $Dell = "Set-DELL -attribute1 unmanaged"
                $HP = "Set-HP -attribute1 unmanaged"
                $web = "set-web -active yes"

                if (Get-servermake -eq "Dell")
                out-file Child.ps1 -append


                if (Get-servermake -eq "HP")

                $HP

                if (Get-webserver -eq $true)
                out-file Child.ps1 -append



                The result is a customized script for the specific server, child.ps1.



                Now, you can take this and run with it. You could say add functionality to the child script like "Is it an AD controller", etc.



                However, you might be better off having all of this in a single script, and just block off sections that don't apply in an if statement for example.



                I'm still not totally sure I understand what your asking. If I've missed the mark, tell me how, and I'll tell you how to tweak this better. (And hopefully obvious is that the Get-whatever is sample code. I don't expect that to be what your using to determine a computer make/model/etc)






                share|improve this answer













                Stop thinking of it as code.



                Use script 1 to export blocks of text into a new file. for example, you might have a configuration that says all Dell servers must have this line of code run:



                Set-DELL -attribute1 unmanaged


                where on HP, the script would have been



                Set-HP -attribute1 unmanaged


                on web servers, you want:



                set-web -active yes


                where if not a web server, you want nothing.. so, your parent script code would look like:



                $Dell = "Set-DELL -attribute1 unmanaged"
                $HP = "Set-HP -attribute1 unmanaged"
                $web = "set-web -active yes"

                if (Get-servermake -eq "Dell")
                out-file Child.ps1 -append


                if (Get-servermake -eq "HP")

                $HP

                if (Get-webserver -eq $true)
                out-file Child.ps1 -append



                The result is a customized script for the specific server, child.ps1.



                Now, you can take this and run with it. You could say add functionality to the child script like "Is it an AD controller", etc.



                However, you might be better off having all of this in a single script, and just block off sections that don't apply in an if statement for example.



                I'm still not totally sure I understand what your asking. If I've missed the mark, tell me how, and I'll tell you how to tweak this better. (And hopefully obvious is that the Get-whatever is sample code. I don't expect that to be what your using to determine a computer make/model/etc)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 20:26







                user2883951




























                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385496%2fcan-you-use-a-powershell-script-to-create-a-powershell-script%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript