PowerShell Variables Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • In this video, we do an introduction to PowerShell variables explained. Nothing but the basics but just gives you a good foundation to build on.
    Video on using Write-Host
    • How to use Write-Host ...
    Video on String Manipulation
    • PowerShell String Mani...
    Video on using Foreach with PowerShell
    • How to use PowerShell ...
    Video on PowerShell arrays
    • PowerShell Arrays Intr...
    Video on working with Dates in PowerShell
    • Work with Date & Time ...
    For support, training, or more information about PowerShell check out www.boldzebras.com

ความคิดเห็น • 62

  • @user-cy1jj4gi8n
    @user-cy1jj4gi8n 8 หลายเดือนก่อน +1

    You put out great videos. Very informative and explanations are easy to follow!

    • @ShanesCows
      @ShanesCows  8 หลายเดือนก่อน

      I appreciate that!

  • @joenathan8262
    @joenathan8262 2 ปีที่แล้ว +1

    Man, I love your videos! I got my start with this series and it has become my go-to refresh for core concepts when I need a refresh after not working with it for a while. Thank you for what you do,!

    • @ShanesCows
      @ShanesCows  2 ปีที่แล้ว

      Glad to help! PowerShell is so fun.

  • @danielbanaru5296
    @danielbanaru5296 4 ปีที่แล้ว +1

    Man, You are a genius in online teaching. Please, teach everything you know because you were very very useful for my interview.

    • @ShanesCows
      @ShanesCows  4 ปีที่แล้ว +1

      Glad it is helping you.

  • @skovil
    @skovil 5 ปีที่แล้ว +2

    Finally someone who CAN explain. Thank you Shane! ...subscribed

  • @daye1997
    @daye1997 5 ปีที่แล้ว +1

    Thanks Shane. Great videos, easy to understand.

  • @beerzo
    @beerzo 5 ปีที่แล้ว +1

    Good stuff Shane. Trying to get my head around on how to build scripts. Cheers

    • @ShanesCows
      @ShanesCows  5 ปีที่แล้ว

      Worth the effort. They are awesome.

  • @darrylbaker5271
    @darrylbaker5271 3 ปีที่แล้ว +1

    Thanks, like your presentation style. Folksy.

  • @manojvamshikonka7603
    @manojvamshikonka7603 2 ปีที่แล้ว +1

    Good information regarding variable

  • @b3nisrael
    @b3nisrael 6 ปีที่แล้ว +1

    7:50 lolll I feel you shane... Thanks for your wonderful videos!!! Love 'em!

  • @louf7178
    @louf7178 ปีที่แล้ว

    If you're looking for a video idea, I'd like to hear about passing variables between sessions.
    To narrow the scenario of discussion, I want to pass a variable out to a "secondary" session (i.e. a main script main dot-sources a secondary script -- I want to send a variable from the main script into the secondary). Also, I swear the secondary script, that has been dot-sourced quietly (-windowstyle hidden) finished running and would not pass a variable to the "main" script. I believe Invoke-Command is the way.
    PowerShell release 5.
    "Secondary" scripts running on the same local computer (not a remote computer).
    Global variables might be good too.
    Thx.

  • @alanelston2330
    @alanelston2330 2 ปีที่แล้ว

    It was interesting and informative what you said about occasional variable Type problems and how the memory of variables is held in the PowerShell session:
    Whilst experimenting in the ISE as part of learning about variables I sometimes got some strange results.
    I found that these strange results came from a combination of the memory held of the variables and the variable type not being what I expected sometimes.
    ( I had been familiar with running coding in MS Office VBA and developing coding in the VB Editor. Things work a bit differently there, in that usually if you alter coding and re run, then variables are usually cleared / initialised, so you start again fresh.)

    • @alanelston2330
      @alanelston2330 2 ปีที่แล้ว

      I got over my problems in a couple of ways.
      _ I tend now to always put this towards the top of my script
      Remove-Variable * -ErrorAction SilentlyContinue
      _ I often declare my variables something like
      [Boolean]$Booh = 1
      ( Even if its not always needed, it looks pretty, Lol :) )
      Alan

  • @mbahr6322
    @mbahr6322 ปีที่แล้ว

    Hi,
    can you please tell me the answer for the below question
    Which variable cannot be modified by the administrator?
    A)user created
    B)automatic
    C) preference
    D)pre-defined

  • @rikrod11
    @rikrod11 ปีที่แล้ว

    Hi Shane. Awesome video! I have a question on how to take data from output and turn it into a variable. Example - I'm making a rest api call to get data back from a third party. I used the following syntax to write the output to the screen:
    Write-Output $response | Format-table -Wrap
    Let's say the results from the call are as follows:
    result
    ------
    {@{sensitive=no; description=game; id=123456; group=basic}}
    I would like to take the results and turn them into variables? Is this possible?

  • @johnsnow3780
    @johnsnow3780 5 ปีที่แล้ว +1

    Great video. Could we delve into into Azure AD variables?

    • @ShanesCows
      @ShanesCows  5 ปีที่แล้ว +1

      I will add it to my list.

  • @voideg3659
    @voideg3659 3 ปีที่แล้ว +1

    Is it possible to permanently set a variable even when closing the terminal?

    • @ShanesCows
      @ShanesCows  3 ปีที่แล้ว

      Not that I have ever done.

  • @PabloVillaronga
    @PabloVillaronga 4 ปีที่แล้ว +1

    Great Video share, i learn a lot , the easy way ! Wouldn;t be great if you post the link to the powershell you explained to Github or your site,like a blog ? Would be easy to execute and get out exercises !

    • @ShanesCows
      @ShanesCows  4 ปีที่แล้ว

      A lot of the videos have the content for download for free on my sellfy site. sellfy.com/shanescows

  • @ufo7614
    @ufo7614 3 ปีที่แล้ว +1

    Could you please make a Video for Global Variable in PS

    • @ShanesCows
      @ShanesCows  3 ปีที่แล้ว

      I haven’t done that before. 🤔

  • @DM-zm2zb
    @DM-zm2zb 5 ปีที่แล้ว +1

    Hello Shane! Thank you for your videos! They are super helpful, praticularly for me as I am just starting to use powershell.
    Have you done a video on exporting variables from a file (e.g. CSV) to a directory? If so, can you link it please? It would be super helpful!! Thanks!! :)
    Mars

    • @ShanesCows
      @ShanesCows  5 ปีที่แล้ว

      th-cam.com/video/PXBMdIkH24I/w-d-xo.html

    • @DM-zm2zb
      @DM-zm2zb 5 ปีที่แล้ว

      @@ShanesCows Hi Shane, thanks for your reply. It was actually really simple. I simply did it all in one line using pipes. Something like
      ADUSers= Import-csv "filepath"
      Get-ADUser -identity $user,sAMAccountname | Set-ADUser -Title $user.Jtitle
      This is for anyone that is interested specifically in what I asked. remember to add the parenthesis and fill the $User._ with you csv column name.
      Thank you again!!
      Bye bye

  • @davidsonmg
    @davidsonmg 6 ปีที่แล้ว

    Great explanation!

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว +1

      Thank you. I was nervous about this one. So many rabbit holes. 😀

  • @juliehill4501
    @juliehill4501 4 ปีที่แล้ว +1

    ok.. I am creating a script to run on computers to put the computer information into a CVS file so I can import into a database. I set a variable for some of the information I need. like this: $hostname = get-computerinfo |Select-Object CsDNSHostName but it returns the title CsDNSHostName as well as the actual hostname. I want just the hostname so I can put it in quotes for my CVS file. How do I do that? Is there a better way than using a variable?

    • @juliehill4501
      @juliehill4501 4 ปีที่แล้ว +1

      I figured it out: $hostname = $(get-computerinfo |Select-Object CsDNSHostName).CsDNSHostName

    • @ShanesCows
      @ShanesCows  4 ปีที่แล้ว

      Thanks for sharing 😀

  • @vantor1966
    @vantor1966 5 ปีที่แล้ว +1

    hi shane , i have a question about variables , i hope you will be able to help me undrstand -
    here is have a command mixed with variables - it is not make any sense to me the built of it - its like declared $vm at the beginning of the command but then uses it inside that very command - help !
    vm = Set-AzVMOperatingSystem `
    -VM $vm `
    -Windows `
    -ComputerName myVM `
    -Credential $cred `
    -ProvisionVMAgent -EnableAutoUpdate

    • @ShanesCows
      @ShanesCows  5 ปีที่แล้ว

      That does seem not right. 😑

  • @drza007
    @drza007 3 ปีที่แล้ว +1

    Is it possible to set the cdrom as a variable?

    • @ShanesCows
      @ShanesCows  3 ปีที่แล้ว

      I am not sure. I haven't tried that before 😐

    • @drza007
      @drza007 3 ปีที่แล้ว

      @@ShanesCows I don't think anyone has because I can't find it on the web. Not sure even where to look. Thanks anyway and great channel.

  • @ps-ri2qk
    @ps-ri2qk 6 ปีที่แล้ว +2

    Lower the Intro volume - Too loud when using headphones and the volume is way above voice levels.

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว

      Sorry about that. You are correct and I fixed it in later videos. Sorry again. - Shane

    • @ps-ri2qk
      @ps-ri2qk 6 ปีที่แล้ว +1

      Thanks Shane, my bad for not mentioning, great videos - please keep making them. From a recent powershell/pwsh fan perspective what do you think about numbering the videos for logical lessons moving forward? I realize you've been doing it 10+ years; but there's a lot to cover. Maybe logical categories of 1A, 1B, of related logic, etc. Just a thought...

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว

      That was my original plan and it just got skewed. :( If you have questions on where to go next after a video feel free to ask. :)
      I think the key though is just learning is hard. It is easier if you have a real task to accomplish and then you learn to do that task. So that means you learn in a different order than the next person. But seriously, I am happy to help. Just ask. :)

  • @brianthomas1489
    @brianthomas1489 6 ปีที่แล้ว +1

    Do you know what $(variablename) means? I see it occasionally and I curious on what it means.

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว

      Not off the top of my head. Can you send me a link to somewhere that is using it and I am happy to try to explain?

    • @danishdude6750
      @danishdude6750 6 ปีที่แล้ว

      Something like this:
      Get-ChildItem -Attributes Directory | ForEach-Object {Write-Output "This folder name is $($_.Name)"}

    • @MKcLTM
      @MKcLTM 5 ปีที่แล้ว

      its called subexpression.

  • @ryhtclgnd
    @ryhtclgnd 6 ปีที่แล้ว

    Hey Shane can you explain why my function New-Folder works but New-folder1 gives an error?
    Function New-Folder ( [string] $MyFolder)
    {New-Item C:\$MyFolder -type directory}
    Function New-Folder1 ( [string] $MyFolder)
    {New-Item -Name C:\$MyFolder -Itemtype "Directory"}
    The way I learned to create directories in powershell was using the syntax in New-Folder1 (without the variable) i.e New-Item -Name C:\FolderName -Itemtype "Directory". Took me ages to figure it out. Thanks

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว

      I will have to ponder on this a bit. I understand why it isn't working and I know how to work around it but what I lack is the nerdy, technical explanation of why you are probably looking for.

  • @sugato58
    @sugato58 5 ปีที่แล้ว +1

    Sir Question I get value or result from the command : Get-ADUser -Identity sd1016405 -Properties mailnickname how i add this value to a variable ? means the result i get from the command Get-ADUser -Identity sd1016405 -Properties mailnickname should get passed to some $USERMailNickName and when i just use $USERMailNIckName will show me the result

    • @ShanesCows
      @ShanesCows  5 ปีที่แล้ว

      Sorry I am not sure.

  • @abdulshaikh6807
    @abdulshaikh6807 6 ปีที่แล้ว

    Hello Shan I am from India and I want leran Powershell can you please confirm can you provide a traning.if yes so share me a details

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว

      Hi Abdul? Have you checked out my playlist of all things PowerShell? It is a great first step. th-cam.com/play/PLCGGtLsUjhm2k22nFHHdupAK0hSNZVfXi.html

  • @alaaalhafez842
    @alaaalhafez842 5 ปีที่แล้ว

    Thanks sir

  • @MKcLTM
    @MKcLTM 5 ปีที่แล้ว +1

    no info about pipeline variables (introduced in psv4) .. sad

    • @ShanesCows
      @ShanesCows  5 ปีที่แล้ว +1

      What do you mean by pipeline variables? I teach about the pipeline itself in a different video. I don't consider using the pipeline a variable.

  • @sanyalraj
    @sanyalraj 6 ปีที่แล้ว

    Hi Shane,
    Thanks for your wonderful videos, i need a help from you, i connected a microntroller at COM port 3 in my PC,
    i send value from microcontroller(example '2' and '3' by println command)to COM3 , i need to trigger/open a text.cmd file in desktop if the received information is '2' ,
    so i open powershell
    # initialize the port
    $port=new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
    #start continuous loop to check the port and open once it 2
    while($true){ $x =$port.readline() if { ( $x -eq "2") { .\text.cmd }}
    and this is not working, Kindly support to fix it ,

    • @ShanesCows
      @ShanesCows  6 ปีที่แล้ว

      Hi Sanyal - I haven't done anything like this before so I am not going to be much help. Sorry.