Windows 10: PowerShell Scripting - The Basics

Discus and support PowerShell Scripting - The Basics in Windows 10 Tutorials to solve the problem; Thanks very much. I shall have to experiment now :-). Just remember to use parentheses and curly brackets correctly. IF (this) {DO that} IF ((this)... Discussion in 'Windows 10 Tutorials' started by slicendice, Oct 22, 2017.

  1. Kari Win User

    PowerShell Scripting - The Basics


    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 }[/quote]
    Using five OR operators to check if any of six conditions is met is not very elegant but it does the job *Smile
     
  2. Kari Win User
  3. The proper way to do any If statements is by using Try/Catch/Finally blocks.
     
    DrEmpiricism, Oct 26, 2017
    #18
  4. PowerShell Scripting - The Basics

    Hahahah! Are you serious?
     
    slicendice, Oct 26, 2017
    #19
  5. cereberus Win User
    Using five OR operators to check if any of six conditions is met is not very elegant but it does the job *Smile

    Kari[/quote] Actually, I think it is very elegant and clear.
     
    cereberus, Oct 26, 2017
    #20
  6. Kari Win User
    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.


    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
     
  7. cereberus Win User
    I once started to read a book "A Beginners Guide to Chaos Theory". The first sentence read "Consider an n-dimensional object in Hilbert Space". I never got as far as the second sentence - LOL.
     
    cereberus, Oct 26, 2017
    #22
  8. PowerShell Scripting - The Basics

    That sentence in the book was a definite beginners killer, assumes familiarity with the subject or was a poor attemp to get the readers attention. Makes absolutely no sense to start a book for beginners with those words. *Roflmao2
     
    slicendice, Apr 4, 2018
    #23
Thema:

PowerShell Scripting - The Basics

Loading...
  1. PowerShell Scripting - The Basics - Similar Threads - PowerShell Scripting Basics

  2. PowerShell script help

    in Windows 10 Software and Apps
    PowerShell script help: Hello,I am trying to use PowerShell to edit similar file names examples below. no_25!2-2_FORSE_COMP.prnno_25!2-4_FORSE_COMP.prnno_25!2-9_FORSE_COMP.prnno_30!10-5_FORSE_COMP.prngb_10!01-_5_FORSE_COMP.prnno_30!11-3_FORSE_COMP.prnI need all the writing in upper case, the '!'...
  3. PowerShell script help

    in Windows 10 Network and Sharing
    PowerShell script help: Hello,I am trying to use PowerShell to edit similar file names examples below. no_25!2-2_FORSE_COMP.prnno_25!2-4_FORSE_COMP.prnno_25!2-9_FORSE_COMP.prnno_30!10-5_FORSE_COMP.prngb_10!01-_5_FORSE_COMP.prnno_30!11-3_FORSE_COMP.prnI need all the writing in upper case, the '!'...
  4. Issue in Powershell script

    in Windows 10 Gaming
    Issue in Powershell script: HI Team,We have a power shell script. It will check if the user is available in the ACL list of ADL. To get the ACL list, we are connecting to the Azure Datalake storage using Connect-AzAccount and authenticating with SPN. To get the group member details, we authenticate the...
  5. Issue in Powershell script

    in Windows 10 Software and Apps
    Issue in Powershell script: HI Team,We have a power shell script. It will check if the user is available in the ACL list of ADL. To get the ACL list, we are connecting to the Azure Datalake storage using Connect-AzAccount and authenticating with SPN. To get the group member details, we authenticate the...
  6. PowerShell script

    in Windows 10 Support
    PowerShell script: The code below tests a series of IPs in a txt file.The result is as follows and is written in a txt file. 19.191.12.161 - online 19.191.12.162 - offline 19.191.12.163 - offline 19.191.12.164 - offline 19.191.12.165 - offline also see the scrennshot Code: $Output= @()$GetIP =...
  7. powershell scripts

    in AntiVirus, Firewalls and System Security
    powershell scripts: Hi, I have azure. Someone is somehow installing powershell scripts onto my computer that allows them to host my PC through P2P and UDP connections, well I think so anyway. I have only just found powershell script entry changes in my registry by accident. These criminals...
  8. powershell script

    in Windows 10 Customization
    powershell script: looking for a script to monitor for a folder, if there is a file in that folder send it as an email, once the email is sent out, confirm and then move the files to an archive folder. monitor c:\test\*.pdf No files, do not send email. Yes Files, send an email to someone at...
  9. Powershell Script on Shutdown

    in Windows 10 Performance & Maintenance
    Powershell Script on Shutdown: Hi all, I try to run a Powershell Script (*.ps1) when i shut down my PC. I created the script and it is working fine when i run it. However if i want to run it on a regular Shutdown it seems like it does not start or is not finished, before Windows is killing every running...
  10. A Powershell Script for HandBrake

    in Windows 10 Software and Apps
    A Powershell Script for HandBrake: Here's the thing. My system is an age-old i3-530 overclocked to 3.5GHz coupled with GTX 1050 2GB. I have around 1.5TB of tutorial videos that I have to encode due to dearth in HDD space. I want to encode the videos while keeping the folder and subfolder structure intact....