I am looking to Create a Powershell Script from within a Powershell Script.
The issue i am having is i need to build and run a script from a remote Powershell terminal to multiple machines. The Script must be on the local machine. Unfortunately, I don't think the Invoke-Command, or the Enter-PSSession are available as the version of Powershell installed on the various machines may not be compatible with them. Or this would have made life much easier :(
So coming from a UNIX/Linux background i was hoping to create a PowerShell script using plain text and then execute the Script locally. Unfortunaly as a newbee to the World of Powershell i was hoping for the powershell script to pass plain text and not to pass the executed output to the powershell script being created on the local machine.
To test the waters here is a small script i have written and the output. VS the Desired output.
Thanks in Advance!
Script:
$var = @"
ping 8.8.8.8
"$env:computername"
"@
$var > \Users\pc\Desktop\ping.ps1
C:\Users\pc\Desktop\ping.ps1
Remove-Item -Path C:\Users\pc\Desktop\ping.ps1 -Force
Output
ping 8.8.8.8
"DESKTOP-****"
Desired Output
ping 8.8.8.8
$env:computername