Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Error: Set-FsrmQuotaTemplate : 0x80070057, The parameter is incorrect.

$
0
0

When I try to create new or modify settings for FSRM Quota Template, for example:

-------------------------------

#Create action
$Action= New-FsrmAction -Type Command -Command "C:\Windows\System32\cmd.exe"

#Create thresholds
$Threshold = New-FsrmQuotaThreshold -Percentage 80 -action $Action
$Threshold2 = New-FsrmQuotaThreshold -Percentage 95 -action $Action

#Create quota
Set-FsrmQuotaTemplate -name "Test" -size 1073741824 -Threshold $Threshold,$Threshold2
-------------------------------

Receive next errors:

------------------------------
Set-FsrmQuotaTemplate : 0x80070057, The parameter is incorrect.
At line:1 char:9
+         Set-FsrmQuotaTemplate -name "Test" -size 1073741824 -Threshold $Threshol ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_FSRMQuotaTemplate (Name = "Test"):Root/Microsoft/...RMQuotaTempla
   te) [Set-FsrmQuotaTemplate], CimException
    + FullyQualifiedErrorId : MI RESULT 4,Set-FsrmQuotaTemplate
------------------------------

Maybe anyone can help me to resolve this errors.




install downlevel "FailoverClusters" module on Server 2016

$
0
0

quick version - I wrote a bunch of monitoring scripts that run on our VMM server, all start with "Import-Module FailoverClusters" on the first line.

The server was in-place upgraded to Server 2016, and now all the scripts fail with:

  • get-vm : The Hyper-V module used in this Windows PowerShell session cannot be used for remote management of the server 'HVSQLTCUCS04'. Load a compatible version of the Hyper-V module

Some internet articles suggest I should be able to do this:

  • Import-Module FailoverClusters -RequiredVersion 1.1

But the response is not ideal:

  • Import-Module : The specified module 'FailoverClusters' with version '1.1' was not loaded because no valid module file was found in any module directory.

also this:

  •  Get-Module -Name FailoverClusters -listavailable
        Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   2.0.0.0    FailoverClusters                    {Add-ClusterCheckpoint, Add-ClusterDisk, Add-ClusterFileSe...

I tried "Find-Module" and things like it, they all get an internet error:

  • WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
    WARNING: Unable to download the list of available providers. Check your internet connection.
    PackageManagement\Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please
    check if the specified package has the tags.

So, How can I get a 2012 r2 compatible version or the module "FailoverClusters" loaded on my 2016 server, preferably manually copy and not automatic internet download (which may be blocked by policy or firewall)

Thanks in advance!

Content library deployment tool vCenter

$
0
0

Afternoon all

I'm building a Powershell script that will enable me to deploy VM's from my vCenter content library after filling in a brief form. This form pulls through some information from the vCenter to aid in completing it.

I've 2 current issues:

1. If a Combobox only receives only a single result to populate with, I get the below error:

exception settings "datasource": "Complex DataBinding accepts as a data source either an IList or an IListSource

2. When pulling back all the VM folder names, it doesn't list them in a nice tree view like vCenter does (for example, we have several folders identically named "compute") so in order to make these readable, I put in a command that gives the parent folder, followed by the 2nd level folder and finally the ID of that folder. Is there any way to get just the "ID" bit out of the Combobox to pass through to a variable for the rest of my script to use?

# Drawing the box


Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$CDWVMDeploy                     = New-Object system.Windows.Forms.Form
$CDWVMDeploy.ClientSize          = '500,689'
$CDWVMDeploy.text                = "CDWVMDeploy"
$CDWVMDeploy.TopMost             = $false

$Title                           = New-Object system.Windows.Forms.Label
$Title.text                      = "CDW ServiceWorks VM Deployment Tool"
$Title.AutoSize                  = $true
$Title.width                     = 25
$Title.height                    = 10
$Title.location                  = New-Object System.Drawing.Point(23,25)
$Title.Font                      = 'Microsoft Sans Serif,10,style=Bold'
$Title.ForeColor                 = "#ff0000"

$vCenterLabel                    = New-Object system.Windows.Forms.Label
$vCenterLabel.text               = "Which vCenter?"
$vCenterLabel.AutoSize           = $true
$vCenterLabel.width              = 25
$vCenterLabel.height             = 10
$vCenterLabel.location           = New-Object System.Drawing.Point(21,57)
$vCenterLabel.Font               = 'Microsoft Sans Serif,10'

$vCenterChoice                   = New-Object system.Windows.Forms.ComboBox
$vCenterChoice.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$vCenterChoice.width             = 141
$vCenterChoice.height            = 20
@('1','2') | ForEach-Object {[void] $vCenterChoice.Items.Add($_)}
$vCenterChoice.location          = New-Object System.Drawing.Point(19,84)
$vCenterChoice.Font              = 'Microsoft Sans Serif,10'

$OSChoice                        = New-Object system.Windows.Forms.ComboBox
$OSChoice.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$OSChoice.width                  = 200
$OSChoice.height                 = 20
@('cl_template-CentOS7','cl_template-RHL6.4','cl_template-fgvm-FGVM-5.6.4','cl_template-w2008R2-std','cl_template-w2012-std','cl_template-w2012R2-std','cl_template-w2016-std','cl_template-w2019-std') | ForEach-Object {[void] $OSChoice.Items.Add($_)}
$OSChoice.location               = New-Object System.Drawing.Point(19,148)
$OSChoice.Font                   = 'Microsoft Sans Serif,10'

$OSLabel                         = New-Object system.Windows.Forms.Label
$OSLabel.text                    = "OS Choice?"
$OSLabel.AutoSize                = $true
$OSLabel.width                   = 25
$OSLabel.height                  = 10
$OSLabel.location                = New-Object System.Drawing.Point(21,118)
$OSLabel.Font                    = 'Microsoft Sans Serif,10'

$VMNameChoice                    = New-Object system.Windows.Forms.TextBox
$VMNameChoice.multiline          = $false
$VMNameChoice.width              = 244
$VMNameChoice.height             = 40
$VMNameChoice.location           = New-Object System.Drawing.Point(20,347)
$VMNameChoice.Font               = 'Microsoft Sans Serif,10'

$CPUChoice                       = New-Object system.Windows.Forms.ComboBox
$CPUChoice.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$CPUChoice.width                 = 100
$CPUChoice.height                = 20
@('1','2') | ForEach-Object {[void] $CPUChoice.Items.Add($_)}
$CPUChoice.location              = New-Object System.Drawing.Point(19,214)
$CPUChoice.Font                  = 'Microsoft Sans Serif,10'

$CPUSocketLabel                  = New-Object system.Windows.Forms.Label
$CPUSocketLabel.text             = "vSocket"
$CPUSocketLabel.AutoSize         = $true
$CPUSocketLabel.width            = 25
$CPUSocketLabel.height           = 10
$CPUSocketLabel.location         = New-Object System.Drawing.Point(21,185)
$CPUSocketLabel.Font             = 'Microsoft Sans Serif,10'

$RAMLabel                        = New-Object system.Windows.Forms.Label
$RAMLabel.text                   = "RAM (GB)"
$RAMLabel.AutoSize               = $true
$RAMLabel.width                  = 25
$RAMLabel.height                 = 10
$RAMLabel.location               = New-Object System.Drawing.Point(140,185)
$RAMLabel.Font                   = 'Microsoft Sans Serif,10'

$RAMChoice                       = New-Object system.Windows.Forms.ComboBox
$RAMChoice.width                 = 100
$RAMChoice.height                = 20
@('2','4','6','8','10','12','16','20','24','32','48','64','128') | ForEach-Object {[void] $RAMChoice.Items.Add($_)}
$RAMChoice.location              = New-Object System.Drawing.Point(140,213)
$RAMChoice.Font                  = 'Microsoft Sans Serif,10'

$VMNameLabel                     = New-Object system.Windows.Forms.Label
$VMNameLabel.text                = "VM Name?"
$VMNameLabel.AutoSize            = $true
$VMNameLabel.width               = 25
$VMNameLabel.height              = 10
$VMNameLabel.location            = New-Object System.Drawing.Point(21,319)
$VMNameLabel.Font                = 'Microsoft Sans Serif,10'

$DeployButton                    = New-Object system.Windows.Forms.Button
$DeployButton.text               = "DEPLOY"
$DeployButton.width              = 174
$DeployButton.height             = 49
$DeployButton.location           = New-Object System.Drawing.Point(75,617)
$DeployButton.Font               = 'Microsoft Sans Serif,25,style=Bold'
$DeployButton.ForeColor          = "#7ed321"

$vCoreLabel                      = New-Object system.Windows.Forms.Label
$vCoreLabel.text                 = "vCore (Socket x Core = Total vCPU)"
$vCoreLabel.AutoSize             = $true
$vCoreLabel.width                = 25
$vCoreLabel.height               = 10
$vCoreLabel.location             = New-Object System.Drawing.Point(21,253)
$vCoreLabel.Font                 = 'Microsoft Sans Serif,10'

$CoreBox                         = New-Object system.Windows.Forms.ComboBox
$CoreBox.width                   = 100
$CoreBox.height                  = 20
@('1','2','3','4','6','8','10','12','16') | ForEach-Object {[void] $CoreBox.Items.Add($_)}
$CoreBox.location                = New-Object System.Drawing.Point(19,282)
$CoreBox.Font                    = 'Microsoft Sans Serif,10'

$ConnectButton                   = New-Object system.Windows.Forms.Button
$ConnectButton.text              = "Connect"
$ConnectButton.width             = 99
$ConnectButton.height            = 26
$ConnectButton.location          = New-Object System.Drawing.Point(185,81)
$ConnectButton.Font              = 'Microsoft Sans Serif,10,style=Bold'
$ConnectButton.ForeColor         = "#7ed321"

$DatastoreChoice                 = New-Object system.Windows.Forms.ComboBox
$DatastoreChoice.width           = 244
$DatastoreChoice.height          = 20
$DatastoreChoice.location        = New-Object System.Drawing.Point(20,411)
$DatastoreChoice.Font            = 'Microsoft Sans Serif,10'

$DatastoreLabel                  = New-Object system.Windows.Forms.Label
$DatastoreLabel.text             = "Datastore?"
$DatastoreLabel.AutoSize         = $true
$DatastoreLabel.width            = 25
$DatastoreLabel.height           = 10
$DatastoreLabel.location         = New-Object System.Drawing.Point(21,381)
$DatastoreLabel.Font             = 'Microsoft Sans Serif,10'

$NetworkLabel                    = New-Object system.Windows.Forms.Label
$NetworkLabel.text               = "Network?"
$NetworkLabel.AutoSize           = $true
$NetworkLabel.width              = 25
$NetworkLabel.height             = 10
$NetworkLabel.location           = New-Object System.Drawing.Point(21,439)
$NetworkLabel.Font               = 'Microsoft Sans Serif,10'

$NetworkChoice                   = New-Object system.Windows.Forms.ComboBox
$NetworkChoice.width             = 245
$NetworkChoice.height            = 20
$NetworkChoice.location          = New-Object System.Drawing.Point(19,460)
$NetworkChoice.Font              = 'Microsoft Sans Serif,10'

$ClusterLabel                    = New-Object system.Windows.Forms.Label
$ClusterLabel.text               = "Cluster?"
$ClusterLabel.AutoSize           = $true
$ClusterLabel.width              = 25
$ClusterLabel.height             = 10
$ClusterLabel.location           = New-Object System.Drawing.Point(23,490)
$ClusterLabel.Font               = 'Microsoft Sans Serif,10'

$ClusterChoice                   = New-Object system.Windows.Forms.ComboBox
$ClusterChoice.width             = 245
$ClusterChoice.height            = 20
$ClusterChoice.location          = New-Object System.Drawing.Point(21,511)
$ClusterChoice.Font              = 'Microsoft Sans Serif,10'

$FolderLabel                     = New-Object system.Windows.Forms.Label
$FolderLabel.text                = "VM Folder?"
$FolderLabel.AutoSize            = $true
$FolderLabel.width               = 25
$FolderLabel.height              = 10
$FolderLabel.location            = New-Object System.Drawing.Point(25,548)
$FolderLabel.Font                = 'Microsoft Sans Serif,10'

$FolderChoice                    = New-Object system.Windows.Forms.ComboBox
$FolderChoice.width              = 450
$FolderChoice.height             = 20
$FolderChoice.location           = New-Object System.Drawing.Point(21,575)
$FolderChoice.Font               = 'Microsoft Sans Serif,10'

$CDWVMDeploy.controls.AddRange(@($Title,$vCenterLabel,$vCenterChoice,$OSChoice,$OSLabel,$VMNameChoice,$CPUChoice,$CPUSocketLabel,$RAMLabel,$RAMChoice,$VMNameLabel,$DeployButton,$vCoreLabel,$CoreBox,$ConnectButton,$DatastoreChoice,$DatastoreLabel,$NetworkLabel,$NetworkChoice,$ClusterLabel,$ClusterChoice,$FolderLabel,$FolderChoice))




#End GUI Region



#Disable certificate checking
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

#What happens when clicking "connect" button
$ConnectButton.Add_Click({ConnecttoVC})
function ConnecttoVC
{
#Disconnect any existing sessions
disconnect-viserver -Confirm:$false

#connect to vCenter
connect-viserver $vCenterChoice.selecteditem


#Get Folder into FolderChoice box
$Folders = get-folder | where{$_.Type -eq "vm"} | select parent,name,id |Sort-Object parent
$FolderChoice.DataSource = $Folders
$FolderChoice.SelectedItem

#Get Cluster choice 
$Clusters = Get-Cluster
$ClusterChoice.Datasource = $Clusters
$ClusterChoice.SelectedItem

#Get Datastore choice

$Datastores = Get-Datastore | Sort-Object
$DatastoreChoice.DataSource = $Datastores
$DatastoreChoice.SelectedItem

#Get networks choice

$Network = Get-VDPortGroup | Sort-Object
$NetworkChoice.DataSource = $Network
$NetworkChoice.SelectedItem
}

#What happens when clicking "deploy" button
$DeployButton.Add_Click({DeployVM})
function DeployVM 
{ 

#Need to get these variables from the combo/free text boxes from form into the below

#region Starter Vars ()
$cluster = Get-Cluster $ClusterChoice.Text
$datacenter = $cluster | Get-Datacenter
$datastore = Get-Datastore $DatastoreChoice.Text
$folder = Get-Folder $FolderChoice.Text
$vmSubnet = Get-VDPortgroup -Name $NetworkChoice.Text
$NewVM = $VMNameChoice.Text
#endregion


#Spin up the vm from a content library template.
Get-ContentLibraryItem -Name $OSChoice.Text | New-VM -Name $NewVM -resourcePool $cluster -location $folder -datastore $datastore -DiskStorageFormat "Thin" -confirm:$false

#assumes a single nic, which as a template should be your standard
$NewVM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $vmSubnet -StartConnected $true -confirm:$false

#Set CPU's
get-VM -name $NewVM | set-VM -NumCpu $CPUChoice.text
$TotalvCPU=$CPUChoice.text*$CoreBox.text
$spec=New-Object –Type VMware.Vim.VirtualMAchineConfigSpec –Property @{“NumCoresPerSocket” = $CoreBox.text}
($NewVM).ExtensionData.ReconfigVM_Task($spec)
$NewVM | set-vm -numcpu $TotalvCPU -confirm:$false

#Set Memory

set-vm $vm -MemoryGB $RAMChoice.text -confirm:$false

#Need to complete the below only if Windows OS selected (need to put an if statement in?)
set-vm $vm -OSCustomizationSpec "+ServiceWorks Windows Templates" -confirm:$false
Get-VM $NewVM
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.Firmware = [VMware.Vim.GuestOsDescriptorFirmwareType]::efi
$vm.ExtensionData.ReconfigVM($spec)

} 


[void]$CDWVMDeploy.ShowDialog()

Thanks!

PSRemote over One Way External Trust not working

$
0
0

Hi,

The infrastructure I have is two forests, one with a root and child domain and the other only has one domain so the names could be DomainA, SubDomainA and DomainB

I created an external trust from Domain B to SubDomainA.  I added my admin account from SubDomainA to specific servers in DomainB and I can successfully connect to the servers via UNC, RDP, etc

All ports are open between the servers (tested with telnet) and psremoting enabled on the server in DomainB (on which I can UNC, RDP, etc to)

My problem comes in when I try to Enter-Pssession from a server in SubDomainA to the server in DomainB. I get the following error message when trying to connect using the FQDN of the server:


As always any help is greatly appreciated.

Kind regards

How to pass parameters to a PowerShell ISE script?

$
0
0

Hello,

   I am trying to figure out on how to pass parameters to a PowerShell ISE script.

I took a snap shot of my simple script and tried to find out how to pass parameter to it. I could not do it from the Run button on top since there was no place for placing the parameters. I would like to seek your expertise if you happen to know a way on how to do it.

Many Thanks!!


Student at Georgia Tech

Get a copy of a value from a file

$
0
0

Hi All , 

I'm trying to use select string to get a copy of a line from ini file.....my problem is every time i get an output it start with the word "Line" and then it list the value i need

I need to only get the value "Path=xxxx" in the output without Line and without the path

I use this command

select-string -path C:\temp\Test.ini -Pattern "Path=" | Select Line


Thoughts?

Script works with static values, but misbehaves when parameterized.

$
0
0

In a previous question, I sought help with a cleanup script. I want to match a filename, keep the 5 newest of that filename, and delete the rest. 

The solution provided by BOfH-666 was:

$Zpath = 'D:\sample'
$Zfile = 'eggs*'
Get-ChildItem -Path $Zpath -File -Filter $Zfile |
    Sort-Object -Descending -Property CreationTime |
        Select-Object -Skip 5 |
            Remove-Item #-WhatIf

This works very well, and I marked it so.  The filematching is important as our customers store other files in these directories and I can't be deleting them.  My issue is I have 29 file matches to cleanup daily, and I don't want 29 scripts.  So, I sought to parameterize the script.

$Zpath = $args[0]
write-host $Zpath

$Zfile = $args[1]
write-host $Zfile


##$Zpath = 'D:\sample'
##$Zfile = 'bacon*'
##$Zfile = 'eggs*'
Get-ChildItem -Path $Zpath -File -Filter $Zfile |
    Sort-Object -Descending -Property LastWriteTime |
        Select-Object -Skip 5 |
            Remove-Item -WhatIf			

If I call the script, using eggs, it works:  .\breakfast.ps1 'D:\sample', 'eggs*'

However, if I call the script, using bacon, it wants to delete old bacon files and all eggs files.
It seems to be the apha part of the match, as the parameter alphabetically later works.  Any thoughts?


-Al H

Remove rows from a csv file based on the values from the text file

$
0
0

Hi All,

I have a .csv file called input.csv with the following columns.

Columns:

#TYPE Selected.Microsoft.PowerShell.Commands.MatchInfo"Path","Filename","Pattern","LineNumber","Line","APPID","LastWriteTime"

with the sample values below separated by comma and with in double quotes

Sample Values:

"\\XXXXXX\d$\Apps\Archive\XXX-2015-08-14_16-08-34\Service\log4net.xml","log4net.xml","password=|pass=|passwd=|passphrase=|pwd=|psw=|\<password\>","60","              <connectionString value=""data source=SQLSVR;initial catalog=test_log4net;integrated security=false;persist security info=True;User ID=sa;Password=sa""/>","765","7/8/2015 6:03:44 PM""\\XXXXXX\d$\Support\__PACKAGE\Support\Software\PowerShell\Carbon\Service\Install-Service.ps1","Install-Service.ps1","password=|pass=|passwd=|passphrase=|pwd=|psw=|\<password\>","187","            $passwordArgName = 'password='","1310","1/28/2014 4:59:06 PM"

I have a file called exclude.txt  with the value like below which matches the column Line in input.csv

Sample Value in the exclude.txt

"            $passwordArgName = 'password='"

I have written the code below to exclude the line which contains the value in the exclude.txt and put the remaining in an output file.  But it is not working and simple returning all the values in input.csv.  Please review and me know what I a doing wrong here.

$import = @{}


$import = Get-Content C:\PC\Libaudit\input.csv
 select -Skip 1

$database = Get-Content C:\PC\Libaudit\exclude.txt
 
$import |
 where {$_ -notcontains $database} |
 Add-Content C:\PC\LibAudit\ToUpload.csv

Thanks for your help

SS


export text file to html format using powershell for the services running and your system process status

$
0
0

Hi Team,

Need script to fulfil requirement as mentioned in title.

Thanks,

Pranav (aaru0504)

Powershell function-get multple values - SOLVED

$
0
0

I have file 1.csv

number, name # column name
1,john
2,mike
3,test
4,test2
...

I created function for returning all values from this csv (number,name)

Function Get-CSV {

 [CmdletBinding()]

    param (
    # CSV File path
    [Parameter(Mandatory=$true)][string]$path
    )

    #Create an hashtable variable
    [hashtable]$return = @{}

    Import-Csv $path |  
         ForEach-Object { 

         $number = $_.number 
         $name = $_.name
         $return.name = $name
         $return.number = $number
         return $return 

     }

      # return $return un-commenting this line don't change output 

}

# calling function

$a = Get-CSV "C:\Users\1.csv"

$a.number
$a.name

I get only one (last row from CSV) - a.name = test2 and a.number = 4

How to get all rows from CSV in diffrent variables (a.name, a.number) ?


How to get EACH EVENT(Get-EventLog -LogName Application) latest triggering time along with message in powershell.

$
0
0

Hello Team,

How to get EACH EVENT(Get-EventLog -LogName Application)latest triggering time along with message in powershell.

Thanks

M. Ramesh


Ramesh. M

Get MAC address of VM running in cluster

$
0
0

Hi,

I have FOC and which have several Hyperv hosts. I want to get the MAC address of a VM located in the FOC.

Now to do that i run the following command from the Management Server (which is of course not part of FOC)

$HyperVHost = Read-host -prompt 'Input HyperV host name'

$VMName = Read-host -prompt 'Input VM Name'

Get-networkAdapter -ComputerName $HyperVHost -VMname $VMName | Select -Property MacAddress

That requires me to find where the VM is located and then enter the HyperV host name. Is there anyway to find the mac address for a VM located in a cluster? or maybe find what host the vm is hosted in a FOC?

Can i run powershell get-clustergroup remotly?

How run Stop-VM without confirmation and without -Force

$
0
0
When I run
Stop-VM -Name "VMNAME" -confirm:$false
I receive prompt for confirmation:
    Confirm
    Hyper-V cannot shut down virtual machine VMNAME because the Shutdown integration service is 
    unavailable. To avoid potential data loss, you can pause or save the state of the virtual machine. 
    The
    other option is to turn off the virtual machine, but data loss might occur.
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): N

    
But when I run the script (for example, cron), I do not want any interactive and pause on this team.
I would want that the command returned an error or does not return anything (and later deal with the result of the command), but does not stop the execution of waiting for a input in the console.
And I want an answer "No" to such a request (-Force I understand it gives the answer is always Yes).

Invalid Grant Type Powershell Invoke-WebRequest

$
0
0

I am writing a powershell script to request a access token. When I run it I am getting the error below for Invalid Grant type. I am not sure why (I am fairly new to powershell programming).

Error:

Invoke-WebRequest : Invalid grant type
At C:\pwscripts\testps.ps1:34 char:1
+ Invoke-WebRequest -uri 'https://urlsite' -M ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

The code I am using:

$BodyArray = @(
    @{
        grant_type= 'refresh_token'
        refreshToken= 'refres token here'
 }
)

$BodyArray_Json = ConvertTo-Json -InputObject $BodyArray

(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

Invoke-WebRequest -uri 'https://urlsite' -Method POST -body $BodyArray_Json -Headers @{'Accept' = 'application/json';'Content-Type' = 'application/json';}

AD Powershell command for deleted users

$
0
0
Hi, can anyone please help with an AD Powershell command to extract deleted AD user accounts showing their start date and end date.

Output from powershell not ordered as expected

$
0
0

Hi there,

I have a powershell which will list all the SQL clusters in a domain with their corresponding nodes etc but it doesn’t output that info in the structured way I was expecting of cluster name followed by that clusters’ nodes sequentially. Any ideas how to straighten that out?

$cluster = Get-Cluster -domain xxxx.com 

$cluster | foreach-object {
        write-host "$_"
        Get-ClusterNode -Cluster $_.Name
        } 

This gives me the correct information but sequenced like:-

Cluster1
Cluster2

cluster1 node1
cluster1 node2
cluster 2 node1
cluster2 node2

Instead of the below:-

Cluster1
cluster1node1 cluster1node2

Cluster2
Cluster2node1
Cluster2node2

Many thanks for looking.

Cheers,

rob

Unable to find and delete registry keys using powershell -Error - Remove-Item : A device attached to the system is not functioning.

$
0
0

Hi,

I am not able to make this script run. Please help me.

$systems = get-content "C:\cb\systems.txt"
Write-Host $systems
foreach ($system in $systems)
{

Invoke-Command -ComputerName $system{ Pushd

sl HKLM:SOFTWARE\

$path = Test-Path cbd
write-host $path

Remove-Item cbd

popd
}}

Powershell "-match" Bug or Feature? O_o

$
0
0
"h\abc" -match "h\a"
False

"h\abc" -match "h\b"
True


"h\abc" -match "h\c"

parsing "h\c" - Missing control character.
At C:\Work\Scripts\App03.ps1:14 char:1
+ "h\abc" -match "h\c"
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException

"h\k" -match "h\k"
parsing "h\k" - Malformed \k<...> named back reference.
At C:\Work\Scripts\App03.ps1:16 char:1
+ "h\k" -match "h\k"
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException

"h\k" -match "h\a"
False



"a\a" -match "a\a"
False

"a\a" -match "a\k"
parsing "a\k" - Malformed \k<...> named back reference.

"a\a" -match "a\b"
True



$PSVersionTable.PSVersion

False

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      17763  771

IDE VisualStudia Code Version: 1.40.1 (user setup)
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:49:35.976Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.17763

Не будите, да не будимы будите!

How to stop getting prompted to "Confirm"

$
0
0

Hello,

I have some Windows Server 2008 systems that I'm trying to run a powershell script on to delete some temp files, but I keep getting prompted with "Confirm... Y [Yes] [A] Yes to All...... ect"  Is there a way to bypass the Confirm?

Thanks,

Tom


Tom Martin Email: tmartin@caa.com

SharePoint PowerShell - need to adapt a script so that it runs on every web in every site for a specified web application

$
0
0

Please help - this script runs on a single site collection and checks that the default groups are present and creates them if not - but we have hundreds in sites in our extranet web app - How can I adapt it so that it goes - for this web app - for every Site collection - for every web in every site collection - do the stuff

asnp *sharepoint*

#Get a site collection:
$s1 = Get-SPSite http://sp16/sites/eWiki

#To list all webs and their associated groups run:
foreach ($w1 in $s1.AllWebs)
{
    $w1.Url #Just for sake of knowing where we are
    $w1.AssociatedMemberGroup | select Name
    $w1.AssociatedVisitorGroup | select Name
    $w1.AssociatedOwnerGroup | select Name
}

#To list all webs with at least one associated group empty reference run:
foreach ($w1 in $s1.AllWebs)
{
if ($w1.AssociatedMemberGroup -eq $null -or $w1.AssociatedVisitorGroup -eq $null -or $w1.AssociatedOwnerGroup -eq $null)
    {
    $w1.Url #Just for sake of knowing where we are
    $w1.AssociatedMemberGroup
    $w1.AssociatedVisitorGroup
    $w1.AssociatedOwnerGroup
    }
}

#To add association groups to webs missing them run:
foreach ($w1 in $s1.AllWebs)
{
if ($w1.AssociatedMemberGroup -eq $null -or $w1.AssociatedVisitorGroup -eq $null -or $w1.AssociatedOwnerGroup -eq $null)
    {
    $w1.Url #Just for sake of knowing where we are
    
    $w1.AssociatedMemberGroup
    $w1.AssociatedVisitorGroup
    $w1.AssociatedOwnerGroup
    [string]$User1 = "spdev\Administrator" #Group Owner, mandatory
    [string]$User2 = "" #Group Contact
    [string]$Name = "" #Group Name if not default

    $w1.CreateDefaultAssociatedGroups($User1,$User1,$Name) #This creates 3 new groups under the form of “[Site title] Members”, “[Site title] Visitors”, “[Site title] Owners” and associates them as default groups
    
    #Alternatively assign existing groups manually, choose from $w1.AssociatedGroups

    }  
}


Thanks!

Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>