小编Fra*_*ani的帖子

为什么我的 PowerShell 脚本不遵守步骤顺序?

我试图自己找到解决方案,但现在我没有主意了。我编写了一个脚本,我想用它来检查机器上是否安装了 Erlang:

# Check if a Software ins installed
function Check_Program_Installed($programName) {
$x86_check = ((Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall") |
Get-ItemProperty |
        Where-Object {$_.DisplayName -like "*$programName*" } |
            Select-Object -Property DisplayName, UninstallString)

if(Test-Path 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')  
{
$x64_check = ((Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") |
Get-ItemProperty |
        Where-Object {$_.DisplayName -like "*$programName*" } |
            Select-Object -Property DisplayName, UninstallString)
}
if ($x86_check -and $x64_check -eq $null){ 
    write-host "$programName is not installed on this computer" -ForegroundColor Green 
    #continue
    }
elseif ($x86_check -or $x64_check -ne $null){
    write-host "On this computer is installed …
Run Code Online (Sandbox Code Playgroud)

powershell scripting automation

5
推荐指数
1
解决办法
3284
查看次数

无法在 Docker 上使用 SSMS 连接到 SQL Server

我遵循了 Microsoft 官方文档,并安装了 SQL Server Docker 映像

结果,我在 IP 地址 172.17.0.2 的 Docker 上运行了一个 SQL Server 映像

在此处输入图片说明

我还可以使用带有我的虚拟密码的 sqlcmd 轻松连接到它

在此处输入图片说明

问题是我无法通过 SSMS 连接到它:

Login failed for user 'sa'. (Microsoft SQL Server, Error: 18456)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

当然,在发布此问题之前,我阅读了其他 StackOverflow帖子,并且尝试了多次登录:

  • 本地主机,1433
  • 本地主机:1433
  • 172.17.0.2,1433
  • 等等...

如果 localhost 无法正常工作以及 docker 映像的 IP 地址,我该如何连接?

sql-server containers ssms sqlcmd docker

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

如何在独立显卡 AMD GPU 上运行 Python 脚本?

我想做的事:

我有一个脚本,用于分解给定范围内的素数:

# Python program to display all the prime numbers within an interval

lower = 900
upper = 1000

print("Prime numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)
Run Code Online (Sandbox Code Playgroud)

我想使用 GPU 而不是 CPU 来运行这样的脚本,这样会更快

问题:

我的英特尔 NUC NUC8i7HVK上没有 NVIDIA GPU,而是“独立 GPU”

在此输入图像描述

如果我运行此代码来检查我的 GPU 是什么:

import pyopencl as …
Run Code Online (Sandbox Code Playgroud)

python pyopengl pyopencl tensorflow pytorch

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

如何升级PowerShell版本

最近,启动 PowerShell,我注意到有这样一句话:

安装最新的 PowerShell 以获得新功能和改进! https://aka.ms/PSWindows

那么为什么不按照实际的 Microsoft 文档进行尝试呢:

  1. 我运行$PSVersionTable安装的版本是5.1
  2. 我运行winget search Microsoft.PowerShell它,它说该版本7.2以及7.3 preview版本可用
  3. 我运行并安装了winget install --id Microsoft.Powershell --source winget版本7.2
  4. $PSVersionTable再次奔跑,但我仍继续前行5.1

在此输入图像描述

让我们尝试通过dotnet安装它:

  1. 我运行dotnet tool install --global PowerShell,终端显示Tool 'powershell' (version '7.2.6') was successfully installed.
  2. 我奔跑$PSVersionTable,但我仍继续前行5.1

在此输入图像描述

我正在遵循当前的 Microsoft 文档,我哪里错了?

windows powershell powershell-5.0 powershell-7.0

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

Google Places API:如何在 Python 中按类型和位置进行搜索

我正在遵循我在GitHub主页上找到的示例googlemaps,我正在编写自己的代码,以便从特定区域检索所有电影院。

代码是这样的:

import googlemaps

gmaps = googlemaps.Client(key='MyGoogleKey')

search_loction = gmaps.location('40.714224, -73.961452').type('movie_theater')
print (search_loction)
Run Code Online (Sandbox Code Playgroud)

它返回给我错误:

Traceback (most recent call last):
  File "GoogleMap.py", line 5, in <module>
    search_loction = gmaps.location('40.714224, -73.961452')
AttributeError: 'Client' object has no attribute 'location'
Run Code Online (Sandbox Code Playgroud)

如果我按照指南,是的,该属性[location]是允许的 在此处输入图片说明

那么我做错了什么?

python google-maps google-places-api

3
推荐指数
1
解决办法
3971
查看次数

PowerShell Sort-Object by Name升序

PowerShell似乎不按名称升序对对象进行排序:

dir | Sort-Object Name
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当然,我的目标是按以下顺序对元素进行排序:

1.sql
2.sql
3.sql
4.sql
5.sql
6.sql
...
...
...
Run Code Online (Sandbox Code Playgroud)

你觉得有什么出路吗?

sorting powershell

3
推荐指数
1
解决办法
1154
查看次数

仅过滤文件中的大写单词

我有一个output.txt文件,有大约1000个单词,如下所示:

SESSIONDAYOFWEEK
FILMTITLELONGALT
tblTrans_Ticket.
ADMITDETAILSALT2
MESSAGESTUB2ALT3
StartDayOfWeek
Description
MESSAGESTUB2ALT2
FILMTITLESHORTALT
Applications
TICKETTYPELONGALT

我需要过滤该文件,只选择只有大写字符的单词,并删除那些具有小写字符的单词.

我在PowerShell中运行此命令:

Get-Content .\out.txt | ForEach-Object if ($_.IsUpper) {Write-Host $_}
Run Code Online (Sandbox Code Playgroud)

并且shell逐个解析所有单词,每个单词打印我:

ForEach-Object : Input name "if" cannot be resolved to a method.
At line:1 char:25
+ ... et-Content .\out.txt | ForEach-Object if ($_.IsUpper) {Write-Host $_}
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (TAIL:PSObject) [ForEach-Object], PSArgumentException
    + FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand

我不明白我哪里错了?

regex powershell foreach

3
推荐指数
1
解决办法
315
查看次数

SSMS 和 sp_OAMethod:是否存在大于 VARCHAR(8000) 的数据类型?

通过 SSMS 调用 REST 服务确实不是一个好主意。

顺便说一句,自从微软创建了存储过程 sp_OAMethod,甚至 Red Gate 的 Phil Factor向我们展示了如何使用它,我想试一试。

我想将 OpenStreetMap 中的一些数据直接导入 MSSQL,所以我从这里复制了一个很好的查询并根据我的意愿进行了调整。

在这个例子中,我将返回纳尔逊的所有电影院:

DECLARE @obj AS INT
DECLARE @Uri AS NVARCHAR(4000)
DECLARE @Response AS VARCHAR(8000)

SET @Uri = 'http://overpass-api.de/api/interpreter?data=area[name="Nelson"]->.a;(node(area.a)[amenity=cinema];way(area.a)[amenity=cinema];rel(area.a)[amenity=cinema];);out;'
EXEC sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @obj OUT
EXEC sp_OAMethod @obj, 'open', NULL, 'GET', @Uri, false
EXEC sp_OAMethod @obj, 'send'
EXEC sp_OAGetProperty @obj, 'ResponseText', @Response OUTPUT

SELECT @Response [response] 
EXEC sp_OADestroy @obj
Run Code Online (Sandbox Code Playgroud)

很好很简单,我可以在 Postman 和 SSMS 中看到 REST 调用响应:

在此处输入图片说明

当我尝试从 …

api rest ssms sqldatatypes varcharmax

2
推荐指数
1
解决办法
1554
查看次数

Python:Windows 10 上的“pip install gmpy”返回“cl.exe' failed with exit status 2”

我已经在 Windows10 上安装了 Pyhton 3.7,当我运行pip install gmpy控制台时,返回这个错误:

Collecting gmpy
  Using cached https://files.pythonhosted.org/packages/26/37/2184c13cee81e1dbeaebbb13570195247e73ab2138a3db0c9d2c5347e372/gmpy-1.17.zip
Building wheels for collected packages: gmpy
  Building wheel for gmpy (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\franc\\AppData\\Local\\Temp\\pip-install-du1j9u7s\\gmpy\\setup.py'"'"'; __file__='"'"'C:\\Users\\franc\\AppData\\Local\\Temp\\pip-install-du1j9u7s\\gmpy\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\franc\AppData\Local\Temp\pip-wheel-nz4_kuat' --python-tag cp37
       cwd: C:\Users\franc\AppData\Local\Temp\pip-install-du1j9u7s\gmpy\
  Complete output (12 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'gmpy' extension
  creating build
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\src …
Run Code Online (Sandbox Code Playgroud)

python pip cl.exe gmpy cl

2
推荐指数
1
解决办法
3007
查看次数

T-SQL :: 生成随机瑞士国民身份证号 (AHV/AVS)

我想生成随机的瑞士国民身份证号码 (AHV/AVS)。

我找到了一个可以做到这一点的网站,如果我查看同一页面的源代码,我还可以看到JavaScript 可以生成它的代码

这些数字是按照以下模式生成的:

在此输入图像描述

  1. 756: 是前缀号码,永远不会改变
  2. 1234: 是一个随机数
  3. 5678: 是一个随机数
  4. 9: 是一个随机数
  5. 7: 是通过此计算生成的 控制号:
    • 从第一个数字开始,取所有其他数字并将它们相加:7 + 6 + 2 + 4 + 6 + 8=33
    • 从 drcond 数字开始,取所有其他数字并对它们求和:5 + 1 + 3 + 5 + 7 + 9=30
    • 然后将第二个数相乘x 3并与第一个数相加:33 + (30 x 3)=123
    • 现在减去该数字的10模:10-(123%10)==10-37

===> 这就是我们最终获得7最后一个数字的方式<===

我创建了一个 SQL 命令,可以生成我需要的随机数:

SELECT …
Run Code Online (Sandbox Code Playgroud)

javascript sql t-sql sql-server random

2
推荐指数
1
解决办法
967
查看次数

SELECT sp_WhoIsActive 到表中

我正在尝试将sp_WhoIsActive编写到表中。目标是每 10 秒向表提供一次代理作业。

我遵循了这个指南,并尝试以这种方式为桌子提供食物:

--Log activity into table.  
DECLARE @destination_table VARCHAR(4000) = 
  '[Monitoring].[dbo].[WhoIsActive] ' 
  
EXEC sp_WhoIsActive
  @get_plans = 1, 
  @get_transaction_info = 1, 
  @destination_table = @destination_table;
Run Code Online (Sandbox Code Playgroud)

但结果我收到错误:

Warning: The join order has been enforced because a local join hint is used.
Msg 50000, Level 16, State 1, Procedure sp_WhoIsActive, Line 1111 [Batch Start Line 0]
Destination table not properly formatted.
Run Code Online (Sandbox Code Playgroud)

在 Google 上,我发现许多指南都在讨论一种解决方案,该解决方案可以帮助我在临时表中执行存储过程,然后我可以从那里创建一个表:

sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1 …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server stored-procedures whois sql-agent-job

1
推荐指数
1
解决办法
3360
查看次数

PowerShell :: SQL SELECT 只返回第一行

我有一种奇怪的感觉,我在这里做错了什么。

这是我的 PowerShell 脚本,当然是从这里窃取和改编的:

param(
    $instance = "localhost"
)

if (!(Get-Module -ListAvailable -Name "SQLPS")) {
    Write-Host -BackgroundColor Red -ForegroundColor White "Module Invoke-Sqlcmd is not loaded"
    exit
}

#Function to execute queries (depending on if the user will be using specific credentials or not)
function Execute-Query([string]$query,[string]$database,[string]$instance,[int]$trusted,[string]$username,[string]$password){
    if($trusted -eq 1){
        try{ 
            Invoke-Sqlcmd -Query $query -Database $database -ServerInstance $instance -ErrorAction Stop -ConnectionTimeout 5 -QueryTimeout 0      
        }
        catch{
            Write-Host -BackgroundColor Red -ForegroundColor White $_
            exit
        }
    }
    else{
        try{
            Invoke-Sqlcmd -Query $query …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server powershell scripting automation

0
推荐指数
1
解决办法
56
查看次数

如何修复可以恢复已删除数据的存储过程

我最近偶然发现了一篇博客文章,其中讨论了一个名为的存储过程Recover_Deleted_Data_Proc.sql,它显然可以从文件中恢复已删除的数据.log

太阳底下并无新鲜事,我们要用fn_dblog

重现步骤

我们首先要创建表:

--Create Table
CREATE TABLE [Test_Table]
(
    [Col_image] image,
    [Col_text] text,
    [Col_uniqueidentifier] uniqueidentifier,
    [Col_tinyint] tinyint,
    [Col_smallint] smallint,
    [Col_int] int,
    [Col_smalldatetime] smalldatetime,
    [Col_real] real,
    [Col_money] money,
    [Col_datetime] datetime,
    [Col_float] float,
    [Col_Int_sql_variant] sql_variant,
    [Col_numeric_sql_variant] sql_variant,
    [Col_varchar_sql_variant] sql_variant,
    [Col_uniqueidentifier_sql_variant] sql_variant,
    [Col_Date_sql_variant] sql_variant,
    [Col_varbinary_sql_variant] sql_variant,
    [Col_ntext] ntext,
    [Col_bit] bit,
    [Col_decimal] decimal(18,4),
    [Col_numeric] numeric(18,4),
    [Col_smallmoney] smallmoney,
    [Col_bigint] bigint,
    [Col_varbinary] varbinary(Max),
    [Col_varchar] varchar(Max),
    [Col_binary] binary(8),
    [Col_char] char,
    [Col_timestamp] timestamp,
    [Col_nvarchar] nvarchar(Max),
    [Col_nchar] nchar,
    [Col_xml] …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server scripting stored-procedures data-conversion

-1
推荐指数
1
解决办法
740
查看次数