标签: powershell

如何修复错误 - nodemon.ps1 无法加载,因为在此系统上禁用了运行脚本,(没有安全风险)?

终端错误:无法加载 nodemon.ps1,因为在此系统上禁用了运行脚本。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkID=135170 上的 about_Execution_Policies。

我有一个通过这种方式解决问题的解决方案

  1. 以管理员身份打开 Windows PowerShell
  2. 运行此命令:Set-ExecutionPolicy Unrestricted

这解决了问题,但这样系统会显示安全风险警告。我的问题:有没有其他方法可以在没有安全风险的情况下解决这个问题?目标是使用 nodemon。

powershell web-development-server node.js nodemon visual-studio-code

46
推荐指数
9
解决办法
6万
查看次数

Powershell:为Get-Content管道设置编码

我有一个文件保存为UCS-2 Little Endian我想更改编码,所以我运行以下代码:

cat tmp.log -encoding UTF8 > new.log
Run Code Online (Sandbox Code Playgroud)

生成的文件仍在UCS-2 Little Endian中.这是因为管道始终采用这种格式吗?有没有一种简单的方法可以将其作为UTF8传输到新文件?

powershell encoding

45
推荐指数
3
解决办法
7万
查看次数

如何在Powershell中进行经过身份验证的Web请求?

在C#中,我可能会这样做:

System.Net.WebClient w = new System.Net.WebClient();
w.Credentials = new System.Net.NetworkCredential(username, auth, domain);
string webpage = w.DownloadString(url);
Run Code Online (Sandbox Code Playgroud)

是否有Powershell版本,或者我应该打电话给CLR?

powershell

45
推荐指数
2
解决办法
10万
查看次数

我可以用C#和Powershell做什么?

我对C#有一个很好的理解,对powershell有一个非常基本的了解.我正在使用Windows PowerShell CTP 3,这非常有趣.但我想超越编写脚本/函数.C#有什么很酷的东西吗?

c# powershell powershell-2.0

45
推荐指数
4
解决办法
5万
查看次数

在PowerShell中为git命令创建别名?

我理解如何在PowerShell中为cmdlet创建别名,但是我想在PowerShell中创建一个别名,比如"git status"就像"gs"和"git pull origin master"那样"gpm"可以让任何人指出我在右边方向?

git powershell

45
推荐指数
4
解决办法
1万
查看次数

如何在PowerShell中全屏显示

有没有办法让powershell出现在全屏?不仅可以在屏幕上最大化,还可以隐藏顶栏?

此外,由于这可能很难做到,如何根据当前分辨率最大化它?

powershell fullscreen powershell-2.0

45
推荐指数
5
解决办法
3万
查看次数

获取当前目录中子文件夹中文件的相对路径

有没有直接的方法(通过使用cmdlet或.NET类)来获取给定路径中子文件夹中文件的相对路径?

例如,当前文件夹是C:\MyScript并没有所谓的子文件夹Data与文件Test.txt,所以我想看到Data\Test.txt的,而不是C:\MyScript\Data\Test.txt

powershell powershell-ise powershell-2.0

45
推荐指数
2
解决办法
4万
查看次数

无论260 char限制,都删除目录

我写了一个简单的脚本,在一定天后删除USMT迁移文件夹:

## Server List ##
$servers = "Delorean","Adelaide","Brisbane","Melbourne","Newcastle","Perth"

## Number of days (-3 is over three days ago) ##
$days = -3

$timelimit = (Get-Date).AddDays($days)

foreach ($server in $servers)
{
    $deletedusers = @()
    $folders = Get-ChildItem \\$server\USMT$ | where {$_.psiscontainer}
    write-host "Checking server : " $server
    foreach ($folder in $folders) 
    {
        If ($folder.LastWriteTime -lt $timelimit -And $folder -ne $null)
        {
            $deletedusers += $folder
            Remove-Item -recurse -force $folder.fullname
        }
    }
        write-host "Users deleted : " $deletedusers
        write-host
}
Run Code Online (Sandbox Code Playgroud)

但是我一直在畏惧 Remove-Item : …

powershell limit

45
推荐指数
8
解决办法
6万
查看次数

如何在PowerShell中为XML添加子元素

我正在尝试为此xml创建一个子XML元素:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我使用这个PowerShell脚本:

[xml] $doc = Get-Content($filePath)
$child = $doc.CreateElement("newElement")
$doc.configuration.AppendChild($child)
Run Code Online (Sandbox Code Playgroud)

我有一个错误: 方法调用失败,因为[System.String]不包含名为'AppendChild'的方法.

xml powershell

45
推荐指数
1
解决办法
7万
查看次数

如何在计算机启动时运行PowerShell脚本?

我有一个监控图像文件夹的PowerShell脚本.我需要找到一种在计算机启动后自动运行此脚本的方法.

我已经尝试了以下方法,但我无法使其正常工作.

  1. 使用msconfig并将PowerShell脚本添加到启动,但我找不到该列表上的PowerShell脚本.

  2. 创建快捷方式并将其拖放到启动文件夹.没运气.

    %SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -File "C:\Doc\Files\FileMonitor.ps1"
    
    Run Code Online (Sandbox Code Playgroud)

    或%SystemRoot%\ system32\WindowsPowerShell\v1.0\powershell.exe -File"C:\ Doc\Files\FileMonitor.ps1"

    这是我的PowerShell脚本:

    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Doc\Files\FileMonitor.ps1"
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我还尝试使用taskschd.msc添加基本任务.它仍然无法正常工作.

    这是我发现的,也许这将有助于调试它.

    如果我打开PowerShell窗口并在那里运行脚本,它就可以工作了.但如果我在CMD提示中运行它,

    $folder = "C:\\Doc\\Files"
    $dest = "C:\\Doc\\Files\\images"
    $filter = "*.jpg"
    
    $fsw = new-object System.IO.FileSystemWatcher $folder, $filter -Property @{
        IncludeSubDirectories=$false
        NotifyFilter = [System.IO.NotifyFilters]'FileName, LastWrite'
    }
    
    $onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
    
        Start-Sleep -s 10
        Move-Item -Path C:\Doc\Files\*.jpg C:\Doc\Files\images
    }
    
    Run Code Online (Sandbox Code Playgroud)

    不起作用.我不确定这是许可问题还是其他问题.

    顺便说一下,我安装了PowerShell 3.0,如果输入$ host.version,它会在那里显示3.但我的powershell.exe似乎仍然是v1.0.

    powershell.exe -File "C:\Doc\Files\FileMonitor.ps1"
    
    Run Code Online (Sandbox Code Playgroud)

powershell

45
推荐指数
6
解决办法
12万
查看次数