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

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?