hello,
is it possible to change a user's password in azure ad true powershell?
i use the azure cloud shell and i want to know witch command's i must use if it is possible.
thanx
hello,
is it possible to change a user's password in azure ad true powershell?
i use the azure cloud shell and i want to know witch command's i must use if it is possible.
thanx
I wanting to delete all files and folders from the desktop under all window profiles.
I also want to keep a few .ppt that have specific names for under each profile. Below is what I have tried and using -exclude "AppV" as an example. Nothing works.
Remove-item -Path C:\$users\desktop\*.* -exclude "AppV" -force -erroraction 'silentlycontinue'
Remove-item c:\users\wcampbell\desktop\* -exclude "AppV" -force -erroraction 'silentlycontinue'
Remove-item C:\$users\desktop -exclude "AppV" -force -erroraction 'silentlycontinue'
hi,
I need to filter ad users on two criteria.
- The accounts must be enabled and employeeid field has to have a value.
Could someone assist with completion of the filter?
-Filter {Enabled -eq $true} -and
I tried to follow syntax suggested here, but could not get it to work.
Thanks
I'm working on a powershell script that exports specific VMs from a given text file. What I would like to do now when I run this script from a scheduled task is to have the script connect to a ISCSI conection before the export happens and disconnect the ISCSI connection after all the exports are done.
Any help will be greatly appreciated!
I am running this script to add all employee IDs into my active directory
>> Import-Module ActiveDirectoryThe last part of it is my attempt to pull out the results into a csv file but no luck, it exports the file but with no data. Any idea of what im doing wrong? ive also tried it with was and same results.....
>>Import-Module ActiveDirectoryMy situatio is:
I need to get via network how many profiles there is in a computer with following information (bellow) and save in a text file:
- Last time that the user logon;
- IP of the computer;
- Profile names (domain and local);
I've this script via powersheel that I found on internet, but this script only get information local computers and no of a remote computer.
$a = read-host "computername"Can someone please help me fix the error below.
You cannot call a method on a null-valued expression.
At C:\SHAREGATE\CreateFoldersInODFB.ps1:88 char:2
+ $newFolder = $spoFolder.Folders.Add($Folder1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Cannot find an overload for "Load" and the argument count: "1".
At C:\SHAREGATE\CreateFoldersInODFB.ps1:89 char:2
+ $web.Context.Load($newFolder)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
Here is the code
The full script can be found here
https://gallery.technet.microsoft.com/office/This-script-will-create-941c58af#content
Thanks in advanced.
Hi,
I would like to create a script (a continue loop) to check if my networks cards are always UP.
How can I do it please using :
$NIC1 = (Get-NetAdapter -Name "NIC1").StatusDo nothing
While {
(($NIC1 -eq "Up") -and ($NIC2 -eq "Up"))
}
Thank you
Hello !
I'm facing an issue with the custom script i'm writing, it basically create a scheduled action, then create a trigger, then create a registered clustered task as wrote in the documentation here https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/Register-ClusteredScheduledTask?view=win10-ps#parameters
I wrote 3 functions to automate action creation, trigger creation and register the task.
Here's my 3 functions code :
function CreateAction { Param ( [Parameter(Mandatory = $true, Position = 0)]$script, [Parameter(Mandatory = $false, Position = 1)]$exec_dir ) $action1 = "New-ScheduledTaskAction -Execute $script" if ($exec_dir) { $action1 = $action1 + " -WorkingDirectory " + $exec_dir } Invoke-Expression $action1 } function CreateTrigger { Param ( [Parameter(Mandatory = $true, Position = 0)]$freq, [Parameter(Mandatory = $true, Position = 1)]$starttime ) $trigger = 'New-ScheduledTaskTrigger ' + $freq + ' -At ' + $starttime Invoke-Expression $trigger } function CreateTask { Param ( [Parameter(Mandatory = $true, Position = 0)]$taskname, [Parameter(Mandatory = $true, Position = 1)]$action, [Parameter(Mandatory = $true, Position = 2)]$trigger, [Parameter(Mandatory = $true, Position = 3)]$resource_name ) $task = "Register-ClusteredScheduledTask -TaskName $taskname -TaskType ResourceSpecific -Action $action -Trigger $trigger -Resource $resource_name" Invoke-Expression $task | Out-Null }
Here's how i use them :
$ActionCopylog = CreateAction $task_script_copylog $task_dir_copylog $TriggerCopylog = CreateTrigger $trigger_freq $task_starttime_copylog $TaskCopylog = CreateTask $task_name_copy_log $ActionCopylog $TriggerCopylog $base_SID
2 of my 3 functions work well (CreateAction and CreateTrigger) BUT i always have the same error while the CreateTask function is used :
Register-ClusteredScheduledTask : Cannot bind argument to parameter 'Action', because PSTypeNames of the argument do not match the PSTypeName required by the parameter: Microsoft.Management.Infrastructure.CimInstance#MSFT_TaskAction. At line:1 char:95+ ... pyLog -TaskType ResourceSpecific -Action MSFT_TaskExecAction -Trigg ...+ ~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidArgument: (:) [Register-ClusteredScheduledTask], ParameterBindingArgumentTransformationException+ FullyQualifiedErrorId : MismatchedPSTypeName,Register-ClusteredScheduledTask
When i do a getType() of my 3 variables, i get the same type as the 3 in the Microsoft examples :
PS C:\Users\xxx\Desktop> $Action.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True CimInstance System.Object PS C:\Users\xxx\Desktop> $ActionCopyLog.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True CimInstance System.Object PS C:\Users\xxx\Desktop> $Trigger.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True CimInstance System.Object PS C:\Users\xxx\Desktop> $TriggerCopylog.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True CimInstance System.Object
Any idea what missing ?
Thanks !
I have the following code, which creates two arrays with different headers. I want to merge those two arrays into a single array called $array, with the data from all four headers and their data:
$array = @()My requirement is need to get adgrouopmember from domain A and need to search the users in domain B.
I'm trying with below command and it is working if the output file without double quotes.
Ex: if the output displayname is peter john then working
but unbale to get if it is "peter john". unable to export the list without double quotes
Get-ADGroupMember -identity "GROUPNAME" | Get-ADUser -Property DisplayName | Select DisplayName | Export-Csv C:\output.csv
$UserNamesList = get-content -path "C:\output.csv "
foreach ($name in $UserNamesList)
{Get-ADUser -filter { DisplayName -eq $name } -Properties * -Server diffdomainserver:3268 | Select-Object Name}
Instade of two output i'm trying to get the list directly from the group but im getting the below error.
$UserNamesList = Get-ADGroupMember -identity "GROUPNAME" | Select Nameforeach
($name in $UserNamesList)
{Get-ADUser -filter { DisplayName -eq $name } -Properties * -Server diffdomainserver:3268 | Select-Object Name}
Need your support with the script below.
What I try to do:
- Connect to Power BI Service to gather some data via Rest Api (https://docs.microsoft.com/en-us/rest/api/power-bi/groups/getgroupusers#code-try-0)
- Loop through the Api's Urls replacing part of them with the values from:
C:\WorkspaceId.csv
WorkspaceID c3ac3fd4-ad18-442d-acb6-0da3a63ce3b0 b0df3876-22d3-4df8-87fd-269c14c911c3 622e598c-a72e-475a-b779-c5c06dd8c9ec
- then I wanna save the output to:
"C:\output.csv"
Script:
Connect-PowerBIServiceAccount $WorkspaceFile = Import-CSV -Path "C:\WorkspaceId.csv" $ExportPath = "C:\output.csv" $Output = foreach ($Line in $WorkspaceFile) { $Item = $Line.WorkspaceID $url = "https://api.powerbi.com/v1.0/myorg/groups/"+$Item+"/users" Invoke-PowerBIRestMethod -Url $url -Method Get } $Output | Export-Csv $ExportPath Disconnect-PowerBIServiceAccount
As a result I want the output for each iteration to be saved in a the same csv.
There is a problem with looping or exporting to csv. It doesn't work.
I am Powershell beginner so please to have this in mind.
Thanks in advance
Hi,
Group scope is GLOBAL and Group type is SECURITY.
Permission "Write-ms-Mcs-AdmPwd" needs to be removed for many groups. Is there a way to remove it using powershell command. please help
Regards, Boopathi
Hi All,
Im trying to send two files with winscp to an sftp server. I tried so many things. Im lost.
It need to find the files created in the last 8 hours and then send them to the sftp. I only can do one file.
try { # Load WinSCP .NET assembly Add-Type -Path 'C:\Program Files (x86)\WinSCP\WinSCPnet.dll' # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "*************" UserName = "*************" Password = "*********" SshHostKeyFingerprint = "ssh-rsa 2048 ******" } $session = New-Object WinSCP.Session if (-not (get-psdrive K -ErrorAction SilentlyContinue)) { $pass="********"|ConvertTo-SecureString -AsPlainText -Force $Cred = New-Object System.Management.Automation.PsCredential('********\*******',$pass) New-PSDrive -name K -Root \\********\test -Credential $cred -PSProvider filesystem -Persist } try { # Connect $session.Open($sessionOptions) $localPath = "K:\" $remotePath = "/incoming/*********/" # Select the most recent file. # The !$_.PsIsContainer test excludes subdirectories. # With PowerShell 3.0, you can replace this with -File switch of Get-ChildItem. $latest = Get-ChildItem -Path $localPath | Where-Object {$_.CreationTime -gt $(get-date).addhours(-8)} | Sort-Object LastWriteTime -Descending | Select-Object -First 1 # Any file at all? if ($latest -eq $Null) { Write-Host "No file found" exit 1 } # Upload the selected file $sourcePath = Join-Path $localPath $latest.Name $session.PutFiles( [WinSCP.RemotePath]::EscapeFileMask($sourcePath), [WinSCP.RemotePath]::Combine($remotePath, "*")).Check() } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }
we are using the following command to try refreshing a report:
before refreshing, we test to see if the report API works good
Invoke-RestMethod -UseDefaultCredentials -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)" -verbose
that returns for us the something, so we know that part is working
VERBOSE: received 946-byte response of content type application/json; odata.metadata=minimal; odata.streaming=true @odata.context : https://pbi.dev.company.com/reports/api/v2.0/$metadata#CacheRefreshPlans/$entity Id : CC1A4569-B890-9633-7H33-908762F54436 Owner : user Description : CatalogItemPath : /Prototypes/Test/TestReport EventType : DataModelRefresh Schedule : @{ScheduleID=; Definition=} ScheduleDescription : LastRunTime : 2019-09-03T17:19:18.143-04:00 LastStatus : Data Refresh failed, contact the administrator, SessionId: 123456-874356-8738764 ModifiedBy : user ModifiedDate : 2019-08-29T16:55:29.173-04:00 ParameterValues : {}
now we found this command that supposedly would refresh a report, but we dont see any changes/updates made to a report (i.e. if we delete a record in the database it still keeps showing up on the report)
Invoke-RestMethod -UseDefaultCredentials -method POST -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)/Model.Execute" -verbose
this returns 0 bytes, and no response. so we're assuming that Model.Execute is not the right command or we are still missing something...
0-byte payload VERBOSE: received 0-byte response of content type
I have done the following steps on Windows server
winrmsetwinrm/config/Service@{AllowUnencrypted="true"}
on linux centos 7
in powershell I tryed
$creds = Get-Credential
Enter-PSSession -ComputerName target server ip -Authentication Negotiate -Credential $creds
get the following error
Enter-PSSession : Connecting to remote server target server ip failed with the following error message : acquiring creds with username only failed Unspecified GSS failure. Minor code may provide more information SPNEGO cannot find mechanisms to negotiate For more information, see the about_Remote_Troubleshooting Help topic.
Not sure what I am missing please assist
Hi,
I have a powershell script and I don't want to change the ExecutionPolicy on my machine. When I run PS command line and type the following command:
powershell -ExecutionPolicy ByPass -File test.ps1the script will run but I dont know how to add this command into my powershell script because I want to run it from context(linke in image) menu when I right click on this powershell script.
PowerShell code to delete all the unique permissions associated to a sub-site.
asnp *sh*
$webUrl="https://XXXXX/sites/opstest/Aditest/"
$web = Get-SPweb $webUrl
if($Web.HasUniqueRoleAssignments -ne $null)
{
#delete all unique permissions
}
Hello All,
I am working on a script from which all the source IPs must do a ping and traceroute to all provided destination IPs. And the output should be directed to CSV.
Below is the script. I don't know how to make the traceroute happen from the source.
I need the output as
Source Destination IP PingStatus
S1 D1 x.x.x.x Up
S1 D2 x.x.x.x Down
S2 D1 x.x.x.x Up
S2 D2 x.x.x.x Up
Once all these ping tests are completed, the Trace route details needs to be populated below these even if it is up and down.
I tried to populate in a formatted table, but the values are not getting out.
PS C:\Magesh> Test-NetConnection ServerNAME -TraceRoute
ComputerName : ServerNAME
RemoteAddress : 10.10.10.10
InterfaceAlias : Ethernet0
SourceAddress : SourceServer
PingSucceeded : True
PingReplyDetails (RTT) : 297 ms
TraceRoute : 10.10.10.1
10.10.10.2
10.10.10.3
...........
10.10.10.10
Kindly request to help me on this.
Script 1:
[CmdletBinding()] param ( [parameter(Mandatory=$true)] [string]$targetIP, [parameter(Mandatory=$true)] [string]$sourceIP ) $targets = get-content -path $targetIP | foreach{ $_.Trim() } $source = get-content -Path $sourceIP | foreach{ $_.Trim() } $time = Get-Date -Format d FOREACH ($target in $targets) { $result = Test-Connection -Source $source -ComputerName $target IF (-not ($result)) { Write-host "$target Failed to respond at $time. Starting Traceroute now...." | Out-File "C:\Tracey.csv" -Append Tracert $target | Out-File "C:\Tracey.csv" -Append } ELSE {Write-Host "$target responds to pings." Tracert $target | Out-File "C:\Tracey.csv" -Append} }
Script 2 :
[CmdletBinding()] param ( [parameter(Mandatory=$true)] [string]$targetIP, [parameter(Mandatory=$true)] [string]$sourceIP ) $targets = get-content -path $targetIP | foreach{ $_.Trim() } $source = get-content -Path $sourceIP | foreach{ $_.Trim() } #$ErrorActionPreference = 'SilentlyContinue' $headerObj = New-Object -Type PSObject Add-Member -InputObject $headerObj -MemberType NoteProperty -Name Source -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name Server -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name State -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name ComputerName -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name RemoteAddress -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name SourceAddress -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name PingSucceeded -value "" Add-Member -InputObject $headerObj -MemberType NoteProperty -Name TraceRoute -value "" $headerObj| export-csv -Force -path ServerStatus.csv foreach ($target in $targets) { $result = Test-Connection -Source $source -ComputerName $target -Count 1 if($result -eq "True") { $route = Test-NetConnection $target –TraceRoute | Select-Object -Property ComputerName,RemoteAddress,SourceAddress,PingSucceeded,TraceRoute foreach($dat in $route){ $OutputObj = New-Object -Type PSObject $OutputObj | Add-Member –MemberType NoteProperty –Name Source –Value $source $OutputObj | Add-Member –MemberType NoteProperty –Name Server –Value $target $OutputObj | Add-Member –MemberType NoteProperty –Name State –Value "Up" $OutputObj | Add-Member –MemberType NoteProperty –Name ComputerName –Value $($dat.ComputerName) $OutputObj | Add-Member –MemberType NoteProperty –Name RemoteAddress –Value $($dat.RemoteAddress) $OutputObj | Add-Member –MemberType NoteProperty –Name SourceAddress –Value $($dat.SourceAddress) $OutputObj | Add-Member –MemberType NoteProperty –Name PingSucceeded –Value $($dat.PingSucceeded) $OutputObj | Add-Member –MemberType NoteProperty –Name TraceRoute –Value $($dat.TraceRoute -join(',')) #$OutputObj $OutputObj | export-csv -append -path -Force ServerStatus.csv } } else { $OutputObj = New-Object -Type PSObject $OutputObj | Add-Member –MemberType NoteProperty –Name Source –Value $source $OutputObj | Add-Member –MemberType NoteProperty –Name Server –Value $target $OutputObj | Add-Member –MemberType NoteProperty –Name State –Value "Down" $OutputObj | Add-Member –MemberType NoteProperty –Name ComputerName –Value $($dat.ComputerName) $OutputObj | Add-Member –MemberType NoteProperty –Name RemoteAddress –Value $($dat.RemoteAddress) $OutputObj | Add-Member –MemberType NoteProperty –Name SourceAddress –Value $($dat.SourceAddress) $OutputObj | Add-Member –MemberType NoteProperty –Name PingSucceeded –Value $($dat.PingSucceeded) $OutputObj | Add-Member –MemberType NoteProperty –Name TraceRoute –Value $($dat.TraceRoute -join(',')) $OutputObj #$OutputObj | export-csv -append -Force "$outFile" } } $OutputObj | export-csv -append -path -Force ServerStatus.csv