Deploy IE shotcut from server to multiple PCs - deployment

I'm new to sccm, psexec, and vb scripting. I need help copying a Internet Explorer shortcut from a server to multiple computers.
Lets say my link is named Shortcut.lnk and is located on \troyserver\shortcut.lnk and I need to push it to troypc1, troypc2, troypc3. How could I do this?
Can someone help me out with this? i've tried using xcopy and psexec and I cannot come up with something simple that works.
I need everything spelled out in detail because im a rookie.

Seems this question was asked without searching. Duplicate of this question How to create a shortcut using Powershell where the answer is listed out with example code.
You can use Powershell to create a shortcut on a remote computer. (edit) Also note you can use Powershell's foreach to loop through a list of computers. There are numerous examples of this available on StackOverFlow.
Example:
PS C:\> $shell = New-Object -comObject WScript.Shell
PS C:\> $shell
SpecialFolders CurrentDirectory
-------------- ----------------
System.__ComObject C:\
PS C:\> $shortcut = $shell.CreateShortcut('\\SERVER\c$\mine.lnk')
PS C:\> $shortcut.TargetPath = c:\Windows\Notepad.exe
PS C:\> $shortcut.TargetPath = "c:\Windows\Notepad.exe"
PS C:\> $shortcut.save()
PS C:\> ls '\\itdrenmvp787\c$\mine.lnk'
Directory: \\itdrenmvp787\c$\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12/23/2014 3:18 PM 673 mine.lnk

Related

Is it possible to use PowerShell to automate interactions with installed programs in windows 10?

Is it possible, from a PowerShell script, to for example automate text box population, automate striking of the enter key inside of an installed program in Windows 10? Could anyone point me in the direction of relevant documentation?
Would a different alternative to PowerShell be more appropriate?
Thanks!
I know how to execute the program from PowerShell (PS C:> 'filepath\program.exe'). I also know how to kill the program from PowerShell (PS C:> stop-process -Name "program_name").
In trying to figure out how events are identified, I tried:
PS C:> $Events = Get-Event
PS C:> $Events[0] | Format-List -Property *
But it returns an error message: "Cannot index into a null array"

PowerShell asks "How do you want to open this file" when executing command

After upgrading from to Windows 11 the Select-String cmdlet stopped working and everytime I use it, it tries to "open an unknown file" as in image bellow:
I found it out when I tried to run one of my ps scripts from batch file - in Win 10 it worked well, but in Win 11 it doesn't. When I run the code in VSCode, it works correctly, I have no clue why.
I tried to copy texts from VSCode (in case of different encoding) to a new file and directly to PowerShell terminal, but none of these worked.
I tried also the new Windows 11 terminal and updating PowerShell to the latest version (7.2.2 x64), but nothing worked.
Dis/Enabling the system function of Windows PowerShell 2.0 has no effect in this case as well.
EDIT:
I found out that if I run the command Update-Script (without any parameters) at the beginning of the script, Select-String works as expected (before that the cmdlet seems to not exist at all - Get-Help Select-String didn't find anything, but after using Update-Script it finds appropriate help). Some other commands does the same (eg. Trace-Command). See the output:
PS C:\> Get-Command Select-String
CommandType Name Version Source
----------- ---- ------- ------
Application Select-String 0.0.0.0 C:\WINDOWS\system32\Select-String
PS C:\> Update-Script
PS C:\> Get-Command Select-String
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Select-String 3.1.0.0 Microsoft.PowerShell.Utility
The Trace-Command "makes" the Select-String works properly as the Update-Script does and gives this output:
DEBUG: CommandDiscovery Information: 0 : Looking up command: Select-String
DEBUG: CommandDiscovery Information: 0 : Cmdlet found: Select-String Microsoft.PowerShell.Commands.SelectStringCommand
hello everybody!
Why do I have to do that (call the Update-Script), when Select-String should work without it?
Well, there are a lot of discussions (not really solved) about powershell "how do you want to open this file", but finally, this was the problem of mine:
https://serverfault.com/questions/1038546/powershell-start-job-returns-a-how-do-you-want-to-open-this-file-with-some-cm
Solution:
Delete file c:\Windows\System32\Select-string (0 bytes, no file extension). I have no idea how it got there...

Powershell execution policy remotesigned contradiction?

please look at the following URL: URL
Now it says the following about downloaded scripts:
"Runs scripts that are downloaded from the Internet and not signed, if the scripts are unblocked, such as by using the Unblock-File cmdlet."
I just downloaded a script from the technet gallery (PS2EXE) and I could run the test script that was included just fine without using the Unblock_file cmdlet. What is going on? Am i misunderstanding what Microsoft is telling me or is this a glitch?
help unblock-file:
Internally, the Unblock-File cmdlet removes the Zone.Identifier alternate data stream, which has a value of "3" to indicate that it was downloaded from the Internet.
The idea of a file being "remote" or "coming from the internet" is data on your local computer filesystem which has to be put there by the tool that downloads the file, it's not included in the file during the download.
If you downloaded a file through Internet Explorer, maybe FireFox, Invoke-WebRequest, these will add it. If you download with something else, the tool might not add this alternate stream.
See how it behaves:
# Show folder is empty
PS C:\temp\> Get-ChildItem
# Make a test script which prints Hello World, and run it
PS C:\temp\> "'Hello World'" | Set-Content -Path .\test.ps1
PS C:\temp\> .\test.ps1
Hello World
# Show the file exists
PS C:\temp\> Get-ChildItem
Directory: C:\temp\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 01/08/2018 22:07 15 test.ps1
# Add the Zone Identifier alternate data stream
PS C:\temp\> "[ZoneTransfer]`nZoneId=3" | Set-Content -Path 'test.ps1' -Stream 'Zone.Identifier'
# Show that it doesn't appear in a normal directory listing:
PS C:\temp\> Get-ChildItem
Directory: C:\temp\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 01/08/2018 22:08 15 test.ps1
# Show how it blocks the file from running
PS C:\temp\> .\test.ps1
.\test.ps1 : File C:\temp\test.ps1 cannot be loaded. The file C:\temp\test.ps1 is not digitally signed. You cannot
run this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
# Show file content
PS C:\temp\> Get-Content -Path .\test.ps1
'Hello World'
# Show alternate data stream content
PS C:\temp\> Get-Content -Path .\test.ps1 -Stream 'Zone.Identifier'
[ZoneTransfer]
ZoneId=3
# Unblock-File removes this alternate stream
PS C:\temp\> Unblock-File .\test.ps1
# Script runs again
PS C:\temp\> .\test.ps1
Hello World
So the main question is, if you run Get-Content file.ps1:Zone.Identifier and see the ZoneId is 3 and can still run the script, and Get-ExecutionPolicy is RemoteSigned, then you have something odd going on.
But my guess is the download tool did not add this data, so the file looks just like a locally created one.
NB. RemoteSigned is not intended to be a security feature, it's intended to be a "help guard against accidentally running scripts before reading them and deliberately choosing to run them" check, like an "are you sure?" box, not like a password prompt.

Where to put PowerShell profile scripts if standard locations are forbidden?

In our corporate environment, I am having difficulty with creating a PowerShell profile scripts.
To prevent users from writing documents on the local disk, the "Documents" directory is forced to be on a network drive. Commonly the "H:" (home) drive.
Likewise, users are forbidden from writing under C:\Windows\System32.
Where can I put the ISE profile script if these two are not available?
PSVersion 5.0.10586.117
PS C:\Windows\System32\WindowsPowerShell\v1.0> $HOME, $PSHOME
C:\Users\pwatson
C:\Windows\System32\WindowsPowerShell\v1.0
See also: Help-About about_Profiles
When I am not connected to the network, these are the $profile settings. I still cannot write under C:\Windows\System32 and the CurrentUser values are invalid.
PS C:\Windows\System32\WindowsPowerShell\v1.0> $profile | Get-Member -Type NoteProperty | ForEach-Object {$_.ToString
()}
string AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
string AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
string CurrentUserAllHosts=WindowsPowerShell\profile.ps1
string CurrentUserCurrentHost=WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS C:\Windows\System32\WindowsPowerShell\v1.0>
One option is to create a shortcut with a target like this:
%systemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -file C:\somewhere\myprofile.ps1
and then always use this shortcut to start PowerShell.
This is not actually using the built-in PowerShell profile concept but it is dot-sourcing a ps1 file that behaves pretty much like a profile file.
If you like to start PowerShell from cmd.exe, create a batch-file with the same content as above and put it somewhere in your path (if you have permissions to do so)

Where can I find a list of exit codes and their meanings for the PowerShell ServerManager cmdlet?

I'm using the PowerShell ServerManager cmdlet and haven't been able to find a comprehensive list of exit codes for the installation commands.
$feature = Add-WindowsFeature NET-Framework-Core
exit $feature.ExitCode
What values can I expect ExitCode to contain?
I have never used this cmdlet, but based on #vmrob's initial answer, it appears that ExitCode is in instance of the Microsoft.Windows.ServerManager.Commands.FeatureOperationExitCode enum type.
You should be able to get a list of possible values like this:
[enum]::GetNames( [Microsoft.Windows.ServerManager.Commands.FeatureOperationExitCode] )
It's possible that the current version of the PowerShell cmdlets act as a wrapper around the deprecated servermanagercmd.exe. If this is the case, then the exit codes listed here should be applicable:
http://technet.microsoft.com/en-us/library/cc733119.aspx
The exit codes that I've encountered so far match:
With a feature that is already installed
PS C:\> $feature = Add-WindowsFeature NET-Framework-Core
PS C:\> $feature.ExitCode
NoChangeNeeded
PS C:\> $feature.ExitCode.value__
1003
When a feature fails to install due to a needed restart
This can happen after Windows Update runs but before the computer is restarted.
PS C:\> $feature = Add-WindowsFeature NET-Framework-Core
PS C:\> $feature.ExitCode
FailedRestartRequired
PS C:\> $feature.ExitCode.value__
1001
On success
PS C:\> $feature = Add-WindowsFeature NET-Framework-Core
PS C:\> $feature.ExitCode
Success
PS C:\> $feature.ExitCode.value__
0