powershell

Powershell script to check if Python is installed

社会主义新天地 提交于 2021-02-08 08:44:15
问题 I'm trying to check if Python is installed on a machine via a Powershell script. My idea so far is to run the following: $p = iex 'python -V' If the command executes correctly (check the Exitcode on $p property), read the output and extract the version number. However, I'm struggling to capture the output when executing the script in Powershell ISE. It's returning the following: python : Python 2.7.11 At line:1 char:1 + python -V + ~~~~~~~~~ + CategoryInfo : NotSpecified: (Python 2.7.11

Why does FtpWebRequest download files from the root directory? Can this cause a 553 error?

夙愿已清 提交于 2021-02-08 08:35:28
问题 I have built a PowerShell script for downloading files from a FTP server. This script is working with all the servers I have tested with expect one. For this one server the script is able to connect, get the directory listing, but each time it attempts to download a file a "553 File Unavailable" error is returned. Below is the code I am using to download files. function Get-FtpFile { Param ([string]$fileUrl, $credentials, [string]$destination) try { $FTPRequest = [System.Net.FtpWebRequest]:

“SFC” output redirection formatting issue - Powershell / Batch

大憨熊 提交于 2021-02-08 08:35:23
问题 I'm working on a powershell script in which several commands output are shown in the window and appended to a file or a variable. It worked correctly until I used the sfc command. When piped or redirected, the output is "broken": > sfc /? Vérificateur de ressources Microsoft (R) Windows (R) version 6.0[...] > sfc /? | Tee-Object -Variable content V Ú r i f i c a t e u r d e r e s s o u r c e s M i c r o s o f t ( R ) W i n d o w s ( R ) v e r s i o á 6 . 0[...] Are there other commands like

Supplying an input file via '@' gives an error: The splatting operator '@' cannot be used to reference variables in an expression

放肆的年华 提交于 2021-02-08 08:33:26
问题 Following this example here https://docs.microsoft.com/en-us/cli/azure/vm/run-command?view=azure-cli-latest I'm getting an error when running my command az vm run-command invoke --command-id RunPowerShellScript --name win-vm -g my-resource-group --scripts @script.ps1 Error: The splatting operator '@' cannot be used to reference variables in an expression. '@script' can be used only as an argument to a command. To reference variables in an expression use '$script'. Putting it in quotes only

Automate PowerShell Response to prompt

╄→гoц情女王★ 提交于 2021-02-08 08:29:41
问题 Creating a PowerShell script that calls an apps cmdlet. When then cmdlet runs it prompts for a response and the scripts hangs. The cmdlet doesn't have any parameters for this. Is there any way to respond programmatically? I tried ECHO but that doesn't work. script hanging 回答1: The only way to get PowerShell scripts that solicit input via the host - typically, via Read-Host - to read input from the pipeline instead of from the keyboard is to use to run the script as an external PowerShell

You must provide a value expression on the right-hand side of the '-' operator

折月煮酒 提交于 2021-02-08 08:25:24
问题 Morning. I have a script that blocks IP's at a specific time if over a threshold of 10 failed logins per day. It works on every server, but one. (there's always one!) This server in particular is Server 2008 (Works fine on other 08's) it throws the following error: You must provide a value expression on the right-hand side of the '-' operator. At C:\Users\admin\Desktop\Block.ps1:11 char:34 + $arRemote = $ar.RemoteAddresses -s <<<< plit(',') This is the original code. $DT = [DateTime]::Now

Enabling execution policy for PowerShell from C#

Deadly 提交于 2021-02-08 08:24:42
问题 I have an ASP.NET MVC 4 page that calls a piece of PowerShell. However, I am running into a problem as a module I am using is not signed, so I have to enable the Unrestricted policy. How can I force the PowerShell child to use Unrestricted policy? I have enabled this in my script, but it is ignored. Also when I try to set the policy in code, an exception is thrown. using (Runspace myRunSpace = RunspaceFactory.CreateRunspace()) { myRunSpace.Open(); using (PowerShell powerShell = PowerShell

Native App Registration with AZ Powershell Module

為{幸葍}努か 提交于 2021-02-08 08:24:40
问题 I need to register a native app on Azure Active Directory using the AZ Powershell 6 Module. A native app can be registered with the command New-AzureADApplication in the AzureAD module setting the value of the field "PublicClient" to true, but the module AzureAD is not supported for powershell 6. In powershell 6 it seems that the corresponding command is New-AzADApplication, which allows to register a Web app / API but not a native app. So how is it possible to register a native app with the

Run a script via FTP connection from PowerShell

♀尐吖头ヾ 提交于 2021-02-08 08:23:33
问题 I have made a script that does a really basic task, it connects to a remote FTP site, retrieves XML files and deletes them afterward. The only problem is that in the past we lost files because they were added when the delete statement was run. open ftp.site.com username password cd Out lcd "E:\FTP\Site" mget *.XML mdel *.XML bye To prevent this from happening, we want to put a script on the FTP server ( rename-files.ps1 ). The script will rename the *.xml files to *.xml.copy . The only thing

Run a script via FTP connection from PowerShell

房东的猫 提交于 2021-02-08 08:23:10
问题 I have made a script that does a really basic task, it connects to a remote FTP site, retrieves XML files and deletes them afterward. The only problem is that in the past we lost files because they were added when the delete statement was run. open ftp.site.com username password cd Out lcd "E:\FTP\Site" mget *.XML mdel *.XML bye To prevent this from happening, we want to put a script on the FTP server ( rename-files.ps1 ). The script will rename the *.xml files to *.xml.copy . The only thing