AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-322802

Confusias's questions

Martin Hope
Confusias
Asked: 2017-10-03 10:42:17 +0800 CST

Invoke-Sqlcmd -InputFile "\\UNC\Path" 访问被拒绝?

  • 2

我正在开发一个概念验证 Powershell 脚本,该脚本将安排在源主机上,并在远程 SQL 服务器&SOURCEHOST01上调用命令。计划的操作顺序如下:SQLSERV01SQLSERV02

  1. 从存储在源主机上的文本文件中获取 SQL Server 主机名列表 \\SOURCEHOST01\PATH\SQLSERVERHOSTNAME.LIST

  2. 对于每个 SQL 服务器,调用命令以将 SQL 脚本复制 \\SOURCEHOST01\PATH\simple_sp_who.sql到%TEMP%每个 SQL 服务器上。

  3. Invoke-Sqlcmd在每个 SQL 服务器上使用指定的 SQL 脚本。

这是我到目前为止的代码:

Get-Content \\SOURCEHOST01\PATH\SQLSERVERHOSTNAME.LIST | Foreach-Object {
    Invoke-Command -ComputerName $_ -ScriptBlock {
        $FileSource = "\\SOURCEHOST01\PATH\"
        $FileDest = "$Env:TEMP\SQL\"
        $Database = "Master"
        $InputFile = "$FileDest\simple_sp_who.sql"
        Copy-Item $FileSource -Destination $FileDest -Recurse
        Invoke-Sqlcmd -ServerInstance $_ -Database $Database -InputFile $InputFile 
    }
}

结果错误:

Access is denied
+ CategoryInfo          : PermissionDenied: (\\SOURCEHOST01\PATH\:String) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName        : SQLSERV01

由于文件权限问题,该脚本似乎在 Copy-Item 失败。我正在运行的测试环境以域管理员身份运行所有内容。我确定这是一个我忽略的简单问题,但我已经开始重复步骤,所以我需要一双新的眼睛。

编辑:

这就是我最终得到的结果:

    Get-Content \\SOURCEHOST01\PATH\SQLSERVERHOSTNAME.LIST | Foreach-Object {
            $SQLSource = Test-Path "\\$($_)\C$\Windows\Temp\SQL\"
            $FileSource = "\\SOURCEHOST01\PATH\"
            $FileDest = "\\$($_)\C$\Windows\Temp\SQL\"
    IF ($SQLSource -eq $True) {
        Remove-Item -Recurse -Force $FileDest
        Copy-Item -Recurse $FileSource $FileDest
    } ELSE {
        Copy-Item -Recurse $FileSource $FileDest
    }
            $date = Get-Date -UFormat "%Y%m%d-%H%M"
            $ScriptBlockContent = {
                $Database = "Master"
                $InputFile = "C:\Windows\Temp\SQL\simple_sp_who.sql"
            Invoke-Sqlcmd -ServerInstance $_ -Database $Database -InputFile $InputFile
            }
        Invoke-Command -ComputerName $_ -ScriptBlock $ScriptBlockContent | Out-File -filePath "\\SOURCEHOST01\PATH\Logs\$date-$_.rpt" -NoClobber
     }

似乎产生了预期的结果。

sql-server
  • 1 个回答
  • 1907 Views
Martin Hope
Confusias
Asked: 2016-07-16 13:05:39 +0800 CST

调整内存大小时,用于在 2012 R2 中创建 VM 的 PowerShell 脚本失败

  • 0

我创建了一个基本脚本以在 Hyper-V 中快速添加一个 VM,并且一切正常,直到它到达Set-VMMemory命令。此时变量似乎失败并产生错误。

脚本代码:

$Name = Read-Host -Prompt 'New VM Name'
$ProcessorCount = Read-Host -Prompt 'Processor Count'
$MinimumBytes = Read-Host -Prompt 'Dynamic Memory Minimum'
$MemoryStartupBytes = Read-Host -Prompt 'Memory Startup Bytes'
$MaximumBytes = Read-Host -Prompt 'Dynamic Memory Maximum'
$Priority = Read-Host -Prompt 'Dynamic Memory Priority'
$Buffer = Read-Host -Prompt 'Dynamic Memory Buffer'
$VlanId = Read-Host -Prompt 'VLAN ID'

New-VM -Name "$Name" -Path H:\VM –NewVHDPath H:\VHD\$Name\$Name.VHDX -NewVHDSizeBytes 64GB -SwitchName "INFRASTRUCTURE"
Set-VM -Name "$Name" -ProcessorCount "$ProcessorCount"
Set-VMMemory "$Name" -DynamicMemoryEnabled $true -MinimumBytes $MinimumBytes -StartupBytes $MemoryStartupBytes -MaximumBytes $MaximumBytes -Priority $Priority -Buffer $Buffer
Set-VMNetworkAdapterVlan –VMName "$Name" –Access –VlanId "$VlanId"

错误代码:

Set-VMMemory : 'test' failed to modify device 'Memory'. (Virtual machine ID 17109661-11E1-4213-97DA-19C5847C8F87)
Invalid startup memory amount assigned for 'test'. The minimum amount of memory you can assign to this virtual machine is '32' MB. (Virtual machine ID 17109661-11E1-4213-97DA-19C5847C8F87)
A parameter that is not valid was passed to the operation.
At line:12 char:1
+ Set-VMMemory "$Name" -DynamicMemoryEnabled $true -MinimumBytes $MinimumBytes -St ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Microsoft.HyperV.PowerShell.VMTask:VMTask) [Set-VMMemory], VirtualizationOperationFailedException
+ FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.SetVMMemoryCommand

我尝试更改语法,但最终得到相同或相似的结果。任何关于车轮在哪里脱落的见解都可以提供,我们将不胜感激。

添加了一些默认值选项的更正脚本: 再次感谢@Peter Hahndorf 为我指明了正确的方向。

$Name = Read-Host -Prompt 'New VM Name'
$ProcessorCount = Read-Host "Processor Count (Press [Enter] to choose 2): "
    if ($ProcessorCount -eq ""){$ProcessorCount="2"} ; if ($ProcessorCount -eq $NULL){$ProcessorCount="2"}
[long]$MinimumBytes = Invoke-Expression (Read-Host -Prompt 'Dynamic Memory Minimum')
[long]$MemoryStartupBytes =  Invoke-Expression (Read-Host -Prompt 'Memory Startup Bytes')
[long]$MaximumBytes =  Invoke-Expression (Read-Host -Prompt 'Dynamic Memory Maximum')
[long]$VHDiskSize =  Invoke-Expression (Read-Host -Prompt 'VHDX Size')
$Priority = Read-Host "Dynamic Memory Priority (Press [Enter] to choose 50): "
    if ($Priority -eq ""){$Priority="50"} ; if ($Priority -eq $NULL){$Priority="50"}
$Buffer = Read-Host "Dynamic Memory Buffer (Press [Enter] to choose 20): "
    if ($Buffer -eq ""){$Buffer="20"} ; if ($Buffer -eq $NULL){$Buffer="20"}
$VlanId = Read-Host "Select Vlan ID (Press [Enter] to choose 2): "
    if ($VlanId -eq ""){$VlanId="2"} ; if ($VlanId -eq $NULL){$VlanId="2"}
New-VM -Name "$Name" -Path H:\VM –NewVHDPath H:\VHD\$Name\$Name.VHDX -NewVHDSizeBytes $VHDiskSize -SwitchName "INFRASTRUCTURE"
Set-VM -Name "$Name" -ProcessorCount "$ProcessorCount"
Set-VMMemory "$Name" -DynamicMemoryEnabled $true -MinimumBytes "$MinimumBytes" -StartupBytes "$MemoryStartupBytes" -MaximumBytes "$MaximumBytes" -Priority "$Priority" -Buffer "$Buffer"
Set-VMNetworkAdapterVlan –VMName "$Name" –Access –VlanId "$VlanId"
powershell hyper-v-server-2012-r2
  • 1 个回答
  • 1747 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve