Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Powershell: basic commands

Hello experts,
I am new in powershell and I would like to know which command are related to:
1-Parse current dir as variable (example in cmd %cd%)
2-Echo specific variable (example in cmd echo %variable%)
3-Log ouput of script (example in cmd > test.log 2>&1)
Thank you in advance for your help.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Thank you oBdA, unable to test it right now. I will keep you informed.
oBdA, I tested the commands and they work. Just some comments:
#1
To get currentdir I prefer the option:
# Determine script location for PowerShell
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path 
Write-Host "Current script directory is: " $ScriptDir

Open in new window

#3
I review log file but I get not necessary information such as:
 Start time: 
Username: 
RunAs User: 
Configuration Name: 
Machine: 
Host Application: C: 
Process ID: 
PSVersion: 
PSEdition: 
PSCompatibleVersions: 
BuildVersion: 
CLRVersion: 
WSManStackVersion: 
PSRemotingProtocolVersion: 
SerializationVersion: 

Open in new window

Is there a way to get ride of it?
Thank you in advance for your help.
Avatar of oBdA
oBdA

Not with the transcript; don't know why they didn't add a switch to turn that off.
But as I said, you can still redirect a script's output like you did before, only PS has a few more output streams than stdout and stderr; to catch them all, you can just use a * like this:
& C:\temp\SomeScript.ps1 *>"C:\Temp\foo.log"

Open in new window

Noted, thank you very much for your help!