Page 2 of 3 FirstFirst 123 LastLast
  1.    3 Weeks Ago #10
    Join Date : Nov 2013
    Chicagoland
    Posts : 33,722
    Dual boot Windows 10 FCU Pro x 64 & Insider 10 Pro

    Great tutorial, Kari.

    Running 10 Pro FCU and Insider 17017. Using PS ISE Admin.

    First things first > Before I get started with learning scripting basics, I was going through the interface to get familiar with it. I see it doesn't have "About" in the help menu. When I click on Help/F1 it takes me to:

    Windows PowerShell Integrated Scripting Environment ISE | Microsoft Docs

    It shows version 5.1 at the left. There's a v6 shown in that drop down menu. In my Windows/System32/WindowsPowerShell/v1.0 the .exe shows as version 1 in properties. Is there a way to get v6?

    I have a PS ISE tile on my Start screen. Is there a way to start the program with Admin rights without going through the UAC prompt? I have to right click the tile and go through its context menu to start in that mode. First-world problem I know.
      My ComputersSystem Spec
  2.    3 Weeks Ago #11
    Join Date : Dec 2015
    Posts : 5,865
    Windows10

    Quote Originally Posted by Kari View Post
    PowerShell has no issues with logical operators. In screenshot beginning of a sample script reading 3 numbers and outputting them in ascending order, comparison in IF statement uses one AND operator (-and in PS) and in ELSEIF statement two AND operators:
    Attachment 159748

    You can use AND (-and), OR (-or), XOR (-xor) and NOT (-not).




    Yes it is.

    Code:
    if (this condition is met)
         {
         Do this
         Then do this
         Finally do this, too
         }

    An IF statement can also include other IF statements:

    Code:
    if (this condition is met)
         {
         if (this condition is met, too)
              {
              Do this
              Then do this
              Finally do this, too
              }
         Do this
         Do that
         }

    Kari
    Thanks very much. I shall have to experiment now :-).
      My ComputerSystem Spec
  3.    3 Weeks Ago #12
    Join Date : Dec 2015
    Posts : 5,865
    Windows10

    Quote Originally Posted by slicendice View Post
    @cereberus

    I am sorry, I must have used only half my brain this morning and read your question only partially. I did not answer your question at all. Instead I got stuck at your comment about the funny looking operators.

    The correct answer to your question is exactly what @Kari said.
    No problem - we all have brain fart days.
      My ComputerSystem Spec
  4.    3 Weeks Ago #13
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,949
    Windows 10 Pro
    Thread Starter

    Quote Originally Posted by HippsieGypsie View Post
    Is there a way to get v6?
    PowerShell Core, still in beta, is a relatively new version of PowerShell, difference to original native Windows PowerShell being it's open source and can be installed and used in Windows, Linux and Mac. PowerShell Core is currently in version 6.0.0-beta.8: Releases PowerShell/PowerShell GitHub

    Although (almost fully) compatible with Windows native PS, I recommend staying in native PS until the time comes that both versions merge to one. Current version of native Windows PS is 5.1:
    Name:  image.png
Views: 69
Size:  283.0 KB


    Quote Originally Posted by HippsieGypsie View Post
    I have a PS ISE tile on my Start screen. Is there a way to start the program with Admin rights without going through the UAC prompt? I have to right click the tile and go through its context menu to start in that mode. First-world problem I know.
    Create an elevated shortcut for it: Create Elevated Shortcut without UAC prompt in Windows 10 Customization Tutorials

    Kari
      My ComputerSystem Spec
  5.    3 Weeks Ago #14
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,949
    Windows 10 Pro
    Thread Starter

    Quote Originally Posted by cereberus View Post
    Thanks very much. I shall have to experiment now :-).
    Just remember to use parentheses and curly brackets correctly.
    IF (this) {DO that}
    IF ((this) -or (this)) {DO that}
    IF ((this) -and (this)) {DO that}

    A "real life" example of using OR (-or), from second tut in PS scripting (will be published in couple of hours) about using a PS script to create bootable USB Windows 10 install media, I'll use a conditional statement as shown below in CODE box to check if the folder / mounted ISO given by user contains Windows setup files by checking if install.wim or install.esd exists either in \Sources folder (single bit architecture ISO) or at least in one of either \x86\Sources and x64\Sources folders (dual architecture ISO).

    Script has read user input just before storing it, either drive letter for a mounted W10 ISO or path to a folder containing files copied from ISO, in variable $ISOFolder. Using cmdlet Test-Path to check if a file exists, if true the condition is met:

    Code:
    $WimCount = 0
    if ((Test-Path $ISOFolder\Sources\install.wim) -or 
        (Test-Path $ISOFolder\x86\Sources\install.wim) -or
        (Test-Path $ISOFolder\x64\Sources\install.wim) -or
        (Test-Path $ISOFolder\Sources\install.esd) -or 
        (Test-Path $ISOFolder\x86\Sources\install.esd) -or
        (Test-Path $ISOFolder\x64\Sources\install.esd))
            {$WimCount = 1}        
        else 
            {
            cls
            Write-Host
            Write-Host ' No Windows 10 installation files found.'
            Write-Host ' Please check mounted ISO letter or path'
            Write-Host ' to folder containing installation files'
            Write-Host ' and run script again.'
            Write-Host
            Pause
            Exit
            }

    Using five OR operators to check if any of six conditions is met is not very elegant but it does the job

    Kari
      My ComputerSystem Spec
  6.    3 Weeks Ago #15
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,949
    Windows 10 Pro
    Thread Starter

    When the scripting basics is clear, see the next part in PS scripting tutorials: PowerShell Scripting - Create USB Install Media for Windows 10 Installation Upgrade Tutorials
      My ComputerSystem Spec
  7.    3 Weeks Ago #16

    The proper way to do any If statements is by using Try/Catch/Finally blocks.
      My ComputerSystem Spec
  8.    3 Weeks Ago #17
    Join Date : Jan 2017
    Turku
    Posts : 1,774
    Windows 10 Pro IP Build 16299.19 (Branch: RS3 Release)

    Quote Originally Posted by DrEmpiricism View Post
    The proper way to do any If statements is by using Try/Catch/Finally blocks.
    Hahahah! Are you serious?
      My ComputersSystem Spec
  9.    3 Weeks Ago #18
    Join Date : Dec 2015
    Posts : 5,865
    Windows10

    Quote Originally Posted by Kari View Post
    Just remember to use parentheses and curly brackets correctly.
    IF (this) {DO that}
    IF ((this) -or (this)) {DO that}
    IF ((this) -and (this)) {DO that}

    A "real life" example of using OR (-or), from second tut in PS scripting (will be published in couple of hours) about using a PS script to create bootable USB Windows 10 install media, I'll use a conditional statement as shown below in CODE box to check if the folder / mounted ISO given by user contains Windows setup files by checking if install.wim or install.esd exists either in \Sources folder (single bit architecture ISO) or at least in one of either \x86\Sources and x64\Sources folders (dual architecture ISO).

    Script has read user input just before storing it, either drive letter for a mounted W10 ISO or path to a folder containing files copied from ISO, in variable $ISOFolder. Using cmdlet Test-Path to check if a file exists, if true the condition is met:

    Code:
    $WimCount = 0
    if ((Test-Path $ISOFolder\Sources\install.wim) -or 
        (Test-Path $ISOFolder\x86\Sources\install.wim) -or
        (Test-Path $ISOFolder\x64\Sources\install.wim) -or
        (Test-Path $ISOFolder\Sources\install.esd) -or 
        (Test-Path $ISOFolder\x86\Sources\install.esd) -or
        (Test-Path $ISOFolder\x64\Sources\install.esd))
            {$WimCount = 1}        
        else 
            {
            cls
            Write-Host
            Write-Host ' No Windows 10 installation files found.'
            Write-Host ' Please check mounted ISO letter or path'
            Write-Host ' to folder containing installation files'
            Write-Host ' and run script again.'
            Write-Host
            Pause
            Exit
            }

    Using five OR operators to check if any of six conditions is met is not very elegant but it does the job

    Kari
    Actually, I think it is very elegant and clear.
      My ComputerSystem Spec
  10.    3 Weeks Ago #19
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,949
    Windows 10 Pro
    Thread Starter

    Quote Originally Posted by DrEmpiricism View Post
    The proper way to do any If statements is by using Try/Catch/Finally blocks.
    This is the first part of series of PowerShell scripting tutorials I intend to write in coming months, emphasis in words first part. The idea of this tutorial is to introduce concept of PS scripting to those not familiar with it. Error handling, "catch" in coding principle try - catch - finally you refer to does most certainly not belong to it.

    In similar way this tutorial tells nothing about do while loops or functions or calling VBS from PS script or many other features and finesses of PS scripting. Your comment is like asking why math textbook for grade 5 does not mention Riemannian geometry.


    Quote Originally Posted by cereberus View Post
    Actually, I think it is very elegant and clear.
    That conditional statement is now "live" in the next part of PS scripting tuts: PowerShell Scripting - Create USB Install Media for Windows 10 Installation Upgrade Tutorials

    Kari
      My ComputerSystem Spec

 
Page 2 of 3 FirstFirst 123 LastLast


Similar Threads
Tutorial Category
Installation & Upgrade PowerShell Scripting - Create USB Install Media for Windows 10
The way Windows operating system is delivered and installed has changed quite a lot from days when Windows 3.0 was delivered on 6 floppy disks. To install, you booted PC from floppy 1, which in its turn asked you to eject it and insert floppy 2 to...
Tutorials
Scripting Errors
I had this problem a few months ago and it went away by itself. I tried This morning some restarts and also the tools. internet ops, advanced with boxes checked. It seems to appear more when I go to a newspaper site, Wall Street Journal, New...
Performance & Maintenance
One or more applications are using the iTunes scripting interface.
Back when I got Windows 10 I started having this problem with iTunes that I didn't have before with 7. When I go to close iTunes it freezes and then this message pops up, "One or more applications are using the iTunes scripting interface. Are you...
Software and Apps
Solved Scripting hulu plus
Good morning. I was trying to create a script to run hulu plus from the microsoft store. So I made a simple .bat file with Start hulu plus:. This command will run non stop it just keeps repeating itself in a loop. I used the command for Netflix and...
General Support
Using Chakra for Scripting Applications across Windows 10
Source: http://blogs.windows.com/msedgedev/2015/05/18/using-chakra-for-scripting-applications-across-windows-10/
Windows 10 News
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 20:26.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums