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,!
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.
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.)
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
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?
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 !
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
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?
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 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
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
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
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.
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...
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. :)
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
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 ,
Man, You are a genius in online teaching. Please, teach everything you know because you were very very useful for my interview.
Glad it is helping you.
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,!
Glad to help! PowerShell is so fun.
You put out great videos. Very informative and explanations are easy to follow!
I appreciate that!
Finally someone who CAN explain. Thank you Shane! ...subscribed
Awesome! 😌
Good stuff Shane. Trying to get my head around on how to build scripts. Cheers
Worth the effort. They are awesome.
Thanks, like your presentation style. Folksy.
Thanks 😊
Good information regarding variable
So nice of you
Thanks Shane. Great videos, easy to understand.
Happy to help
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.
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.)
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
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?
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 !
A lot of the videos have the content for download for free on my sellfy site. sellfy.com/shanescows
7:50 lolll I feel you shane... Thanks for your wonderful videos!!! Love 'em!
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
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?
I figured it out: $hostname = $(get-computerinfo |Select-Object CsDNSHostName).CsDNSHostName
Thanks for sharing 😀
Is it possible to permanently set a variable even when closing the terminal?
Not that I have ever done.
Great video. Could we delve into into Azure AD variables?
I will add it to my list.
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
ruclips.net/video/PXBMdIkH24I/видео.html
@@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
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
That does seem not right. 😑
Could you please make a Video for Global Variable in PS
I haven’t done that before. 🤔
Is it possible to set the cdrom as a variable?
I am not sure. I haven't tried that before 😐
@@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.
Great explanation!
Thank you. I was nervous about this one. So many rabbit holes. 😀
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
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.
Lower the Intro volume - Too loud when using headphones and the volume is way above voice levels.
Sorry about that. You are correct and I fixed it in later videos. Sorry again. - Shane
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...
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. :)
Do you know what $(variablename) means? I see it occasionally and I curious on what it means.
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?
Something like this:
Get-ChildItem -Attributes Directory | ForEach-Object {Write-Output "This folder name is $($_.Name)"}
its called subexpression.
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
Hi Abdul? Have you checked out my playlist of all things PowerShell? It is a great first step. ruclips.net/p/PLCGGtLsUjhm2k22nFHHdupAK0hSNZVfXi
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
Sorry I am not sure.
no info about pipeline variables (introduced in psv4) .. sad
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.
Thanks sir
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 ,
Hi Sanyal - I haven't done anything like this before so I am not going to be much help. Sorry.