我制定了以下非常基本的政策,旨在对新资源组强制执行命名约定。
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/resourceGroups"
},
{
"field": "name",
"notLike": "rg-*"
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
Run Code Online (Sandbox Code Playgroud)
该策略是在订阅级别分配的,并且policy enforcement = enabled。没有排除情况,正如您从策略中看到的,效果设置为deny。
然而,这个政策根本就没有任何效果。我可以noncompliant随意创建名称为 , ... 的新资源组。另外,我等了30多分钟政策才生效(实际上我等了24小时多)。
有趣的是,以下策略生效(几乎在分配后立即生效),唯一的区别是资源类型的比较。
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks"
},
{
"field": "name",
"notLike": "vnet-*"
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
} …Run Code Online (Sandbox Code Playgroud) 我试图捕获System.UnauthorizedAccessException.如果用户没有对特定文件的读访问权,则会发生此异常.
$fwlog = $env:SystemRoot + "\system32\logfiles\firewall\pfirewall.log"
if(Test-Path $fwlog)
{
try
{
Get-Content -ReadCount 10 -Path $fwlog
}
catch [System.UnauthorizedAccessException]
{
Write-Host "caught"
}
}
else
{
write-host "File does not exist"
}
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误消息:
Get-Content : Access to the path 'C:\Windows\system32\logfiles\firewall\pfirewall.log' is denied.
At D:\SourceCode\PowerShell\FwLogParser.ps1:7 char:9
+ Get-Content -ReadCount 10 -Path $fwlog
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\syst...l\pfirewall.log:String) [Get-Content], UnauthorizedAccessException
+ FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
谢谢回答.我仍然不明白为什么这个运行进入[Exception]而不是更具体的[System.UnauthorizedAccessException].
$fwlog = $env:SystemRoot + "\system32\logfiles\firewall\pfirewall.log"
$ErrorActionPreference = "stop"
if(Test-Path $fwlog)
{
try
{
Get-Content …Run Code Online (Sandbox Code Playgroud) 我的脚本一直困扰着我,但出现以下异常
copy-item : Cannot find drive. A drive with the name 'F' does not exist.
At C:\Program Files (x86)\CA\ARCserve Backup\Templates\RB_Pre_Process.ps1:58 char:1
+ copy-item -Path $drive -Destination $DST_DRIVE -Recurse -ErrorAction Stop
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (F:String) [Copy-Item], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
Run Code Online (Sandbox Code Playgroud)
这就是我的脚本的样子。我正在驱动器 F: 上安装 ISO 映像,并且我添加了一个“start-slepp -s 5”命令,以便我可以验证映像是否已安装,确实如此!
$BACKUP_PATH = "E:\00_BACKUP_DATA"
$DR_PATH = "E:\01_DR_DATA"
$ISO_IMAGE = "C:\Program Files (x86)\CA\ARCserve Backup\Templates\Winpe_x64.iso"
$DST_DRIVE = "E:\"
try {
New-EventLog -LogName Application -Source "RB_Pre_Process.ps1" -ErrorAction Stop
} catch [System.InvalidOperationException] {
Write-host $_ …Run Code Online (Sandbox Code Playgroud) $DebugPreference如果进行了相应设置,显示变量内容的最佳方式是什么?我的印象是必须有一个更好/更短/更有效的方法来完成这个......有什么想法吗?
我知道有$MyInvocation.BoundParameters,但我不知道如何在这种情况下正确使用它。它返回一个哈希表,Write-Debug 不会显示该哈希表。
Clear-Host
$VerbosePreference = "Continue"
$DebugPreference = "Continue"
$WhatIfPreference = $true
$Global:Config = @{
SearchBase = "OU=SomeOU,DC=ad,DC=contoso,DC=com"
LogFolder = "C:\Temp"
LogFile = $($MyInvocation.MyCommand.Name -replace ".ps1", ".txt")
LogPath = "$($Global:Config.LogFolder)\$($Global:Config.LogFile)"
}
Write-Debug "$($MyInvocation.MyCommand.Name): SearchBase = $($Global:Config.SearchBase)"
Write-Debug "$($MyInvocation.MyCommand.Name): LogFolder = $($Global:Config.LogFolder)"
Write-Debug "$($MyInvocation.MyCommand.Name): LogFile = $($Global:Config.LogFile)"
Write-Debug "$($MyInvocation.MyCommand.Name): LogPath = $($Global:Config.LogPath)"
Function Move-MyADObjects
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,HelpMessage="define sitecode e.g. xxxxx")]
[string]$Sitz
)
$TargetPathUsers = "OU=$sitz,OU=Users,$($Global:Config.SearchBase)"
$TargetPathGroups = "OU=$sitz,OU=Groups,$($Global:Config.SearchBase)"
$TargetPathServers = "OU=$sitz,OU=Servers,$($Global:Config.SearchBase)"
$TargetPathClients = "OU=$sitz,OU=Clients,$($Global:Config.SearchBase)"
Write-Debug "$($MyInvocation.MyCommand.Name): …Run Code Online (Sandbox Code Playgroud) 我想使用提供的方法评估电话号码。电话号码的长度应始终为10。但是,以下方法似乎总是返回false。这是为什么?谢谢。
public static boolean valPhoneNumber(String phonenumber){
boolean result= true;
if (phonenumber.length() > 10 || phonenumber.length() < 10){
result= false;
}else
phonenumber.length();
char a=phonenumber.charAt(0);
char b=phonenumber.charAt(1);
char d=phonenumber.charAt(3);
char e=phonenumber.charAt(4);
char f=phonenumber.charAt(5);
if (a<2 || a>9){
result = false;
}else if( b<0 || b>8){
result = false;
}else if (d<2 || d>9){
result = false;
}else if (e==1 && f==1){
result = false;
}
return result;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 masm32 在 Windows 7 上编译和链接,它与下面的代码一起工作得很好。然而,调用 stdOut 并不是简单地在我的命令提示符上打印任何内容。我究竟做错了什么?
.386
.model flat, stdcall
option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\masm32.inc
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\masm32.lib
.data
MsgBoxCaption db "Message Box Caption", 0
MsgBoxText db "Win32 Assembly is great!", 0
.data?
; declare an uninitialized byte, referred to as location sum
sum dd ?
.code
start:
mov eax, 1d
mov ebx, 1d
; result will be stored in the first argument
add eax, ebx
; push eax onto …Run Code Online (Sandbox Code Playgroud) 我一直将其内容NLog.config移至我的网站App.config,并打算删除原始的nlog配置文件。
但是Visual Studio 2017 Enterprise (15.8.4),由于以下错误消息,我无法这样做:
无法修改源自导入文件的评估对象。C:...... csproj.nuget.g.props
打开上述文件时,我发现以下部分:
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<None Include="$(NuGetPackageRoot)nlog.config\4.5.10\contentFiles\any\any\NLog.config" Condition="Exists('$(NuGetPackageRoot)nlog.config\4.5.10\contentFiles\any\any\NLog.config')">
<NuGetPackageId>NLog.Config</NuGetPackageId>
<NuGetPackageVersion>4.5.10</NuGetPackageVersion>
<NuGetItemType>None</NuGetItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>NLog.config</TargetPath>
<Private>True</Private>
<Link>NLog.config</Link>
</None>
Run Code Online (Sandbox Code Playgroud)
删除后段<ItemGroup>的NLog.config走了,但自动生成默认的内容又上来了。
长话短说:NLog.config将所有配置内容移至项目后,如何删除项目根目录下的文件App.config
目前,我正在尝试弄清楚 Spring Boot 多模块项目是如何工作的。该项目设置为包含:
mvn package我可以通过从根模块调用来构建所有模块。然而,当我尝试从 Spring Boot 模块中调用相同的目标时,我得到了
[错误] 无法在项目 spring-boot-app-2 上执行目标:无法解析项目 io.azureblue 的依赖项:spring-boot-app-2:jar:0.0.1-SNAPSHOT:找不到工件 io.azureblue :shared-library:jar:1.0-SNAPSHOT -> [帮助 1]
我不明白为什么。这只是一个演示项目,所以将所有内容编译在一起没什么大不了的。但在现实生活中,这可能需要相当长的时间,我想单独编译模块。
当我查看我的存储库文件夹 ( .m2/repository/) 时,我可以看到共享库在那里 ( io/azureblue/shared-library/...)。下面是我的 POM 文件。您可以在我的存储库中找到整个项目。
我在这里做错了什么?
父POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.azureblue</groupId>
<artifactId>spring-boot-multi-module-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-multi-module-demo</name>
<description>spring-boot-multi-module-demo</description>
<properties>
<java.version>11</java.version>
</properties>
<packaging>pom</packaging>
<modules>
<module>spring-boot-module-1</module>
<module>spring-boot-module-2</module>
<module>shared-library</module>
</modules>
</project>
Run Code Online (Sandbox Code Playgroud)
共享库 …
为什么以下while语句永远循环?我想在用户输入"是"或"否"后突破.其他一切都应该让他留在输入循环中.
while ($input -ne "yes" -or $input -ne "no") {
$input = Read-Host "Ready to process? [yes|no]"
switch ($input) {
yes {
write-host "yes"
}
no {
write-host "no"
}
default {
write-host "input not understood"
}
}
}
Run Code Online (Sandbox Code Playgroud) powershell ×4
java ×2
assembly ×1
azure ×1
azure-policy ×1
c# ×1
copy-item ×1
debugging ×1
exception ×1
masm32 ×1
maven ×1
nlog ×1
spring ×1
spring-boot ×1
while-loop ×1
x86 ×1